+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
*nix Thread, Cronjob oddity in Technical; I use the following script to create a gzipped tarball of my main website (/var/www/) and another of our extra ...
  1. #1

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498

    Cronjob oddity

    I use the following script to create a gzipped tarball of my main website (/var/www/) and another of our extra sites with a datestamp on the file name:

    Code:
    #/bin/sh
    /bin/tar -cvf /backups/websites.tar /usr/share/websites/
    /bin/gzip /backups/websites.tar
    mkdir -p /backups/websites/`/bin/date +%Y/%b`
    /bin/mv /backups/websites.tar.gz /backups/websites/`/bin/date +%Y/%b/websites_%d-%b-%Y.tar.gz`
     
    /bin/tar -cvf /backups/joomla.tar /var/www/
    /bin/gzip /backups/joomla.tar
    mkdir -p /backups/joomla/`/bin/date +%Y/%b`
    /bin/mv /backups/joomla.tar.gz /backups/joomla/`/bin/date +%Y/%b/joomla_%d-%b-%Y.tar.gz`
    When I run the script manually with
    Code:
    /path/to/scripts/scriptname.sh
    It works perfectly (about 24M for Joomla, and about 1.5GB for the websites)

    However when I run the same script via crontab, it only creates a tarball about 300k in size?

    cronjob is:

    Code:
    @daily /path/to/scripts/scriptname.sh  #Backup all websites
    Am stumped as to why it doesnt work as a cronjob....

  2. #2


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,463
    Thank Post
    866
    Thanked 845 Times in 667 Posts
    Rep Power
    195
    cron job running as a user who cn't read those files?

  3. #3

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    Nope - running as root - other cronjob runs fine - does the same thing with mysql (mysqldump, gzip with date appeneded..)

    Wondering if cron timse out at all?

  4. #4


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,463
    Thank Post
    866
    Thanked 845 Times in 667 Posts
    Rep Power
    195
    Try re-ordering it - make the directory first, and then do the tar as a one liner (add "z" to the commandline opts to make it zip automatically).

  5. #5


    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    4,463
    Thank Post
    866
    Thanked 845 Times in 667 Posts
    Rep Power
    195
    Oooh... and check that the output of "date" isn't changing while your cron is taking place. You might stick that in a variable first before use.

  6. #6

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Default installations of cron on Ubuntu mail the job output to root, unless you redirect it (which you haven't). Take a look there.

    You also don't have a bang (!) in your shebang, line 1 (should read #!/bin/sh)

  7. #7

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    Eek! good spot powdarrmonkey!!
    @tom_newton - the cron job runs at 00:00 so date should have already changed before it runs!

  8. #8

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    Also @ powdarrmonkey - i cant read teh system mail?? installed mutt and ran it as root and main user (the one created at install) but all empty?

  9. #9

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Check cat /var/mail/root or /var/spool/mail/root? See if it's being directed somewhere else (/dev/null is a favourite) in /etc/aliases.

  10. #10

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    nothing in /var/mail or /var/spool/mail (which is ointing to /var/mail/ anyway!)

  11. #11

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Always worth a check How about /etc/aliases?

  12. #12

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    Code:
    root@web01:~# cat /etc/aliases
    # See man 5 aliases for format
    postmaster:    root
    root@web01:~#

  13. #13

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Hmm. Ubuntu folks do even more silly things than I thought.

    In that case, redirect it to a log file yourself - in cron,

    Code:
    @daily /path/to/scripts/scriptname.sh > /var/mail/mybackup.log 2>&1 #Backup all websites
    It will be easier to read if you do the gzip inline, as Tom suggests:

    Code:
    /bin/tar -czvf /backups/joomla.tar.gz /var/www/
    and get rid of the calls to gzip. Add the -v (verbose) flag to your calls to mv too.

  14. #14

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,658
    Thank Post
    858
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    can I still datestamp it that way
    Would be a heck of a ot easier i admit..

    gonna redirect it to /var/log/backups/websites.log - does it need to be >> though to append?
    Last edited by Gatt; 16th February 2010 at 10:20 AM.

  15. #15

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Yes, your mv command will still rename it, you're just combining the tar and gzip steps (why have two processes when tar can do it all? )

  16. Thanks to powdarrmonkey from:

    Gatt (16th February 2010)

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. NOD32 oddity
    By cookie_monster in forum Windows
    Replies: 4
    Last Post: 7th July 2008, 10:33 AM
  2. Re-directed folder oddity
    By mark in forum Windows
    Replies: 3
    Last Post: 21st April 2006, 08:22 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •