Forum Moderators: bakedjake
I have a script and I want to offer the option for people to be able to update the script automatically.
Basically I have the script in http://www.[MyWebsite].com/script.tar.gz
What can I put in the cron tab so that customer's server can download it using wget, untar and copy it to the directory /usr/[SomeDirectory]/?
And can I do it using zip file instead of tar files?
0 0 * * * (cd /usr/somedir && wget -q -O - [someurl...] ¦ tar -xzf -) > /dev/null 2&>1
will do it at midnight
use tar/gz instead of zip, it lets you do it all through pipes rather than needing temp files and such
Sean
edit: forgot final - in tar command
cd /usr/somedir2 && wget -q -O - [someurl...] ¦ tar -xzf - && cp -r /usr/somedir2/ /usr/somedir/
Better?
FWIW, I would never, ever, do it like this, I'm just answering the poster's question. Real Men (TM) would make an RPM out of it and do it properly.
Sean
Is there any way of preventing any mishaps should the transaction fail? I don't wanna screw up my script users.
And I am new to the unix scene and definitely RPM is out of my league. Hence, I am not a Real Man(TM)
Will the Real Mens out there please help?!
[edited by: haryanto at 10:43 pm (utc) on Feb. 13, 2004]
wget the tarball to the filesystem
wget a checksum from the same site
compare the checksum on the local file to the one you downloaded
If they match, untar, else email
Clean up
checksums are easy enough to calculate with the "md5sum" command.
TMPFILE=`/bin/mktemp /tmp/download.XXXXXX` ¦¦ exit 1
wget -q -O $TMPFILE [yoururl...]
CHKSUM1=`wget -q -O - [yoururl...]
CHKSUM2=`/bin/md5sum $TMPFILE`
if [ "$CHKSUM1" -eq "$CHKSUM2" ]; then
(cd /usr/somedir && tar -xzf $TMPFILE)
else
echo "checksum failed" ¦ mail root
fi
rm $TMPFILE
Cron that script, you should be golden
Sean
Thanks I will save the script as a .sh file and get cron to chunch it out everyday.
bcc1234, where can I find info how to do an Rsync?
That will help me preserve the bandwidth a lil. We're talking about 1000+ files here, all I need is 1000 users and I have to file bankruptcy due to the bandwidth.
You don't need to setup cron tabs on customer's serves, just install rsync over there and you can selectively push updates from your own server whenever you need (you can run cron on your server if that's what you want) - as opposed to the pull model with all cusotmer's servers queriying your location at specified time intervals.