Results 1 to 7 of 7

Thread: help with my cronjob

  1. #1
    Join Date
    Mar 2005
    Location
    Seattle
    Beans
    161
    Distro
    Edgy Eft Testing

    help with my cronjob

    I'm trying to run wget via a cronjob on ubuntu server 12.04 LTS (GNU/Linux 3.2.0-25-virtual x86_64). It seems that via syslog it that the cronjob is run, however the output file from wget isn't created.

    If I run the same wget command manually, the file is created.


    the cronjob itself:


    Code:
    crontab -e
    
    
    # m h  dom mon dow   command
    00 05 * * Sun wget http://private.ip/ -O /home/ubuntu/store/`date +%s`
    
    00 08 * * Sun /usr/bin/killall wget



    relevant parts of the syslog show that the cron jobs execute:


    Code:
    Jul 22 05:00:01 private.ip2 CRON[6104]: (ubuntu) CMD (wget http://private.ip/ -O /home/ubuntu/store/`date +)
    
    Jul 22 08:00:01 private.ip2 CRON[6467]: (ubuntu) CMD (/usr/bin/killall wget)

    when i run the wget code from the terminal via the ubuntu user account it works:

    Code:
    ubuntu@ip-10-245-74-62:~$ wget http://private.ip/ -O /home/ubuntu/store/`date +%s`
    --2012-07-23 18:44:33--  http://private.ip
    Resolving private.ip (private.ip)... private.ip,private.ip
    Connecting to private.ip (private.ip)|private.ip... connected.
    HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
    Length: unspecified
    Saving to: `/home/ubuntu/store/1343069073'
    
        [                                                <=>                                             ] 391,704     56.4K/s              ^C
    
    ubuntu@private.ip2:~$ ls -lah /home/ubuntu/store/
    total 404K
    drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 23 18:44 .
    drwxr-xr-x 6 ubuntu ubuntu 4.0K Jul 23 18:41 ..
    -rw-rw-r-- 1 ubuntu ubuntu 396K Jul 23 18:44 1343069073


    Am I having a permissions error, because the cron user doesn't own the store folder, or is it something else?

  2. #2

    Re: help with my cronjob

    maybe try...
    Code:
    00 05 * * Sun wget http://private.ip/ -O /home/ubuntu/store/$(date +%s)
    should work.

    edit:
    Oops: "perm error" - sure it will matter, who owns the /home/ubuntu/store directory?/
    Code:
     ls -ld /home/ubuntu/store/
    and who is running the script.
    Last edited by Habitual; July 23rd, 2012 at 08:25 PM.


  3. #3
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,697
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: help with my cronjob

    Hi discord.

    crontab uses the character % as an special character (it replaces it with a newline).

    Escape the character with a \, and you'll be fine.

    BTW, I'd recommend using a more up-to-date syntax for the execution by using $() instead of back-ticks:
    Code:
    $(date +\%s)
    Hope it helps, and let us know how it goes.
    Regards.

  4. #4
    Join Date
    Jan 2009
    Location
    ::1
    Beans
    2,461

    Re: help with my cronjob

    Quote Originally Posted by papibe View Post
    BTW, I'd recommend using a more up-to-date syntax for the execution by using $() instead of back-ticks:
    Code:
    $(date +\%s)
    Oh. I didn't know that. Is the $(...) safer/better than `...` ? Not bound to a certain shell?

  5. #5
    Join Date
    Aug 2009
    Location
    Montevideo, Uruguay
    Beans
    259
    Distro
    Ubuntu

    Re: help with my cronjob

    Simple tip:

    Use full paths, ie /usr/bin/wget instead of wget

    Can save you a headache, or two.

  6. #6
    Join Date
    Mar 2005
    Location
    Seattle
    Beans
    161
    Distro
    Edgy Eft Testing

    Re: help with my cronjob

    Thanks for the help. I believe my problem was due to not escaping the % sign. It is working !

  7. #7
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,697
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: help with my cronjob

    Oops, too slow.


    Great

    Please mark the thread solved (read here) when you have the chance.

    Regards

Tags for this Thread

Bookmarks

Posting Permissions

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