Forum Moderators: bakedjake

Message Too Old, No Replies

How to setup a cron to update script automatically?

         

haryanto

8:05 am on Feb 13, 2004 (gmt 0)

10+ Year Member



Hi guys,

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?

SeanW

2:11 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



OTTOMH:

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

bcc1234

2:50 pm on Feb 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's not a very good solution.
If the transmission fails for any reason - your customer is screwed until the next update.

SeanW

3:07 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



If the transmission fails for any reason - your customer is screwed until the next update

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

bcc1234

3:15 pm on Feb 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

Real men would use rsync over ssh :)

SeanW

3:35 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



For updating a web site, sure, for updating software, still not a great way. RPM is transactional, rsync isn't. RPM has versioning, rsync doesn't. ;)

Sean

bcc1234

6:46 pm on Feb 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not a linux land, and don't use ports of RPM, but for the sake of an argument: what benefit will transactions bring for a single file script?

SeanW

7:04 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



The original poster used a compressed tarball, which lead me to believe that there may be more than one file.

Mostly I'd want the versioning and config file handling (ie rpm won't blow away a config file if it's there, but if it isn't, can install a default one)

Sean

haryanto

10:41 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



Basically there is one Tarball. In the tarball theres 1000+ HTML,PHP and Images.

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]

haryanto

10:42 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



;-)

SeanW

10:56 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



You might want to look at the following:

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

bcc1234

2:37 am on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...or you can use rsync without tarballing anything, and it will only transfer new or changed files while calculating checksums as well...

this can go on forever...

SeanW

3:35 am on Feb 14, 2004 (gmt 0)

10+ Year Member



The moral of the story is there is more than one way to skin a cat ;)

Sean

haryanto

5:19 am on Feb 14, 2004 (gmt 0)

10+ Year Member



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.

bcc1234

6:09 am on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just search for rsync on google :)

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.