Creating zipped nightlies using cron

Creating zipped nightlies using cron

Posted by: romans1423
Posted on: 2009-08-25 04:27:00

I want to programmatically create ZIP files of an actively developed piece of software I'm writing, and I'd like to do so on a nightly basis.

In other words, I want to ZIP /home/username/example.com/path/to/sw/ (the sw/ directory and everything in it), and I'd like the ZIP file saved to /home/username/static.example.com/sw.zip

I know how to ZIP via Shell; while in the (using the above example) to/ directory, I ran "zip sw sw" and shell reported that the ZIP was created successfully. I just have NO idea where it saved it too... It's not in the path/, to/, sw/ or even in home/username/...

What I'd like is for the ZIP to be created each night at midnight.

I cannot for the life of me figure out what to put in the command box of the DH panel's cron interface. I've wasted a few hours on this, so I hope one of you is able to help me out. Thanks!

Re: Creating zipped nightlies using cron

Posted by: Atropos7
Posted on: 2009-08-25 12:38:00

In reply to:

I cannot for the life of me figure out what to put in the command box of the DH panel's cron interface. I've wasted a few hours on this, so I hope one of you is able to help me out. Thanks!



1. For cron jobs specify full paths, including to programs or shell scripts, eg:

$ whereis zip
zip: /usr/bin/zip /usr/share/man/man1/zip.1.gz

program = /usr/bin/zip
zip file = /home/username/static.example.com/sw.zip
source directory = /home/username/example.com/path/to/sw/

2. Second, I don't know what zip program you invoked, but the version on my machine is as follows: says this:

$ zip -v
This is Zip 2.31 (March 8th 2005), by Info-ZIP.
Currently maintained by Onno van der Linden. Please send bug reports to
the authors using http://www.info-zip.org/zip-bug.html; see README for details.

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip, as of
above date; see http://www.info-zip.org for other sites.

Compiled with gcc 3.3.5 (Debian 1:3.3.5-8) for Unix (Linux ELF) on Mar 23 2005.

3. If you want the file paths in the zip to start with 'sw/' then change to the parent directory first. Won't need to specify full path to sw directory in the call to zip as a result.

4. Need to add -r flag to recourse directories and -q to suppress output if necessary

5. So far you should have these commands to make the zip and then verify:

$ cd /home/username/example.com/path/to
$ /usr/bin/zip -r /home/username/static.example.com/sw.zip sw
adding: sw/ (stored 0%)
...
$ /usr/bin/stat /home/username/static.example.com/sw.zip
File: `/home/username/static.example.com/sw.zip'
Size: 41534 Blocks: 88 IO Block: 32768 regular file
Device: 10h/16d Inode: 281900410 Links: 1
Access: (0664/-rw-rw-r--) Uid: (4096/ username) Gid: (16384/ pg8192)
Access: 2009-08-25 12:21:17.694192000 -0700
Modify: 2009-08-25 12:21:17.711192000 -0700
Change: 2009-08-25 12:21:17.712193000 -0700
$

6. So if you want to run all 3 commands for the cronjob, you need to separate them using a semi-colon on one line:
cd /home/username/example.com/path/to; /usr/bin/zip -r /home/username/static.example.com/sw.zip sw; /usr/bin/stat /home/username/static.example.com/sw.zip


Customer since 2000 cool openvein.org

Re: Creating zipped nightlies using cron

Posted by: romans1423
Posted on: 2009-08-25 13:35:00

Genius, dude. Thanks!

Tags: shellinterface