Results 1 to 10 of 10

Thread: Crontab on Ubuntu 6.06

  1. #1
    Join Date
    Jun 2009
    Beans
    5

    Crontab on Ubuntu 6.06

    Hi,
    I'm trying to set up crontab to execute a php script.

    My crontab file content is:

    * * * * * php /var/myDirectory/myfile.php>/tmp/myfile.log 2>/tmp/myfile.err

    The file is successfully executed from command line typing:

    php /var/myDirectory/myfile.php

    Using crontab it doesn't work.
    Crontab service is running, in crontab log file I can't see anything regarding the execution of my script.
    I've even tried to run a simpler command:

    * * * * * echo "hello" > /tmp/log.txt

    but it doesn't work at all.

    My crontab file is located in /var/spool/cron/crontabs and it's called "root" as I access with root profile to the command line.

    Anyone knows why it's not working?

    Thanks

  2. #2
    Join Date
    Jun 2009
    Location
    Philadelphia PA
    Beans
    114
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Crontab on Ubuntu 6.06

    Edit crontabs directly using:
    Code:
    crontab -e
    View crontabs using:
    Code:
    crontab -l
    If crontab -l doesn't show you anything, no crontab is installed.

    -Dan
    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    Think we're being rude? Read this. Trying to argue intelligently? Read this.

  3. #3
    Join Date
    Jun 2009
    Beans
    5

    Re: Crontab on Ubuntu 6.06

    Quote Originally Posted by ManiacDan View Post
    Edit crontabs directly using:
    Code:
    crontab -e
    View crontabs using:
    Code:
    crontab -l
    If crontab -l doesn't show you anything, no crontab is installed.

    -Dan
    Already done.

    Crontab is installed, my crontab file is read and written, but crontab doesn't run and no errors are shown in log.

  4. #4
    Join Date
    Nov 2007
    Location
    Wisconsin
    Beans
    1,139

    Re: Crontab on Ubuntu 6.06

    User crontabs are stored at /var/spool/cron/crontabs
    If you are running a user-level cron job, use the crontab -e and -l commands to set the user-level crontab.


    But root's crontab is stored at /etc/crontab. That's why your particular crontab isn't working.

    Editing root's crontab is a *really* *bad* *idea*. Instead, use the cron.* folders provided.

    If you are running a periodic script (hourly, daily, weekly, monthly) as root, put a link to the script in the /etc/cron.hourly (or .daily or .weekly or .monthly) folder.

    Special scripts that run at different intervals should be linked to the /etc/cron.d folder.

    Think about permissions - these scripts will run as root, not a user, and may have different consequences than you may expect.

    There are several very good cron tutorial scattered around the web to explain the how and why of the root crontab without damaging your system.
    Last edited by Cheesehead; June 30th, 2009 at 03:40 PM.

  5. #5
    Join Date
    Jun 2009
    Beans
    5

    Re: Crontab on Ubuntu 6.06

    Quote Originally Posted by Cheesehead View Post
    User crontabs are stored at /var/spool/cron/crontabs
    If you are running a user-level cron job, use the crontab -e and -l commands to set the user-level crontab.


    But root's crontab is stored at /etc/crontab. That's why your particular crontab isn't working.

    Editing root's crontab is a *really* *bad* *idea*. Instead, use the cron.* folders provided.

    If you are running a periodic script (hourly, daily, weekly, monthly) as root, put a link to the script in the /etc/cron.hourly (or .daily or .weekly or .monthly) folder.

    Special scripts that run at different intervals should be linked to the /etc/cron.d folder.
    Thank you very much!
    So, if I save my file in folder /etc/cron.d - as I'm running the script every minute - it should work, right?

    Think about permissions - these scripts will run as root, not a user, and may have different consequences than you may expect.

    There are several very good cron tutorial scattered around the web to explain the how and why of the root crontab without damaging your system.
    Any link? I'm a bad searcher, in two days I've found nothing about this

  6. #6
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Crontab on Ubuntu 6.06

    1-59 * * * * /usr/bin/php yourscriptname>> your.txt

    Cron doesn't even know where php is

    I do it that way anyways with perl, and it works. If its a root level cron job, you need to sudo crontab -e.

    EDIT:
    nm, the sudo crontab -e was on my trixbox which already was a root login, I wasn't reading my terminal properly...
    Last edited by t4thfavor; June 30th, 2009 at 04:02 PM.

  7. #7
    Join Date
    Jun 2009
    Beans
    5

    Re: Crontab on Ubuntu 6.06

    Quote Originally Posted by t4thfavor View Post
    1-59 * * * * /usr/bin/php yourscriptname>> your.txt

    Cron doesn't even know where php is

    I do it that way anyways with perl, and it works. If its a root level cron job, you need to sudo crontab -e.
    I tried also that, but the problem is that my file is not being executed at all.
    And now I'm concentrating on this simple script:

    * * * * * echo "hello" > /tmp/log.txt

    just to see if it runs at least.

  8. #8
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Crontab on Ubuntu 6.06

    1-59/5 * * * * perl /etc/asterisk/MonitorTrunks.pl >> /etc/asterisk/trunks.log

    runs a cron job every 5 minutes. I would not understand why your script does not run.

    Perhaps Ubuntu runs them differently.


    Nope,

    1-59 * * * * /bin/bash /home/chance/bob.sh >> /home/chance/bob.out

    executes bob.sh and puts its contents into /home/chance/bob.out every minute without fail.

    your doing it wrong...


    did you make sure your outfiles were created, that may be what I did differently.
    Last edited by t4thfavor; June 30th, 2009 at 04:08 PM.

  9. #9
    Join Date
    Jun 2009
    Beans
    5

    Re: Crontab on Ubuntu 6.06

    Quote Originally Posted by t4thfavor View Post
    did you make sure your outfiles were created, that may be what I did differently.
    I've created an empty file log.txt but my crontab doesnt' edit it.
    According to log, there are some files in folder cron.d that runs as root when they have to, but my file is totally ignored.
    Really don't know what I'm doing wrong...

  10. #10
    Join Date
    May 2009
    Beans
    265

    Re: Crontab on Ubuntu 6.06

    The files need not be created in advance but be careful: if you have been touching things around, watch for the permissions

    sudo echo "hello" > somefile

    won't write in somefile anything if you don't have permissions to write in it.
    Last edited by HotForLinux; July 13th, 2009 at 07:38 PM.

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
  •