Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Asking Advice for Scripting Updates across Devices

1 view
Skip to first unread message

freemont

unread,
Jan 27, 2019, 4:14:17 PM1/27/19
to
Greetings to all - I hope this froup isn't totally dead. I badly miss
usenet.

Anyway. I have a little experience with the shell and with scripting,
but I am no programmer/developer in earnest. The longest thing I can
remember creating from scratch is a perl script from many years ago,
created for one of my sites, which was maybe a hundred lines, tops.

At work I've been handed responsibility for maintenance of several
Raspberry Pi units that sit behind or near wall displays. These displays
stream information, weather, time for customers. They're spread over a
geographic area covering several counties.

I want to do a couple of things for now:

1) Script the updating of all these machines so that they handle any
problems with aptitude without human input when possible; if the update
fails, the machine emails me.

2) Script the pushing-out of updates to said script to all these machines.

Number 1 works, but isn't it wordy? Is there some way to use c-style
switch or case stuff and use aptitude's exit codes, for instance?

Number 2, the push-out script, needs help. Actually I need the help. So
I can help the script.

Here is what I have for the single-host update:

################################################################################
#!/bin/bash

mailalert() {
date=$(date +%Y%m%d-%H%M)
host=$(hostname)
errorfile=$(touch ./Failed-Update-"$host"-"$date".txt)
aptitude full-upgrade -s > $errorfile
mpack -s "Failed Update $host" -o "$errorfile"
free...@freemontsoffice.com
}

if ping -c 5 ubuntu.com
then
echo "************ Looks like I'm online, so starting update.
************"
else
echo "************ Looks like it's NOT online, so exiting.
************"
exit
fi

if sudo aptitude update
then
echo "************** Updating repos succeeded, trying upgrade.
************"
else
echo "************** Updating repos failed for some reason,
exiting. ************"
exit
fi

if sudo aptitude upgrade -y
#if [[ $? != 0 ]]
then
echo "************* Upgrade succeeded, all patched up.
************"
echo "************ Now time to autoclean. ************"
else
echo "************* upgrade failed, trying full-upgrade.
************"
if sudo aptitude full-upgrade -y
then
echo "************* Upgrade succeeded, all patched up.
************"
echo "************ Now time to autoclean. ************"
else
echo "************ full-upgrade failed as well.
************"
# something somewhere to somehow notify someone about
something
mailalert
fi
fi

if sudo aptitude autoclean
then
echo "************ autoclean done. ************"
else
echo "************ autoclean failed. ************"
fi
exit

################################################################################

And here is what I just started to push that mess around to the hosts:

################################################################################
#!/bin/bash

# 20190114 scp the updateOne skript to the *[shnip]* hosts
# for updates, mostly
# When run from NEMS shouldn't need pw

#
for ip in $(<ips-ras-pis.txt); do
# winders keeps inserting its stupid carriage returns
# so just in case, this perl converts them all to newlines
perl -pi -e 's/\r\n/\n/g' updateOne.sh
scp updateOne.sh pi@"${ip}":/home/pi/
echo "************ All done. ************"
done

################################################################################

I welcome your advice. :-)

Yours -

--
freemont
0 new messages