Find the answer to your Linux question:
Results 1 to 5 of 5
I'm playing with CRON to perform an automated shutdown. While I'm testing I want CRON to shutdown the PC every 10 min. Here is the crontab. # crontab -l 0,10,20,30,40,50 ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    8

    CRON shutdown fails

    I'm playing with CRON to perform an automated shutdown.
    While I'm testing I want CRON to shutdown the PC every 10 min.
    Here is the crontab.

    # crontab -l
    0,10,20,30,40,50 * * * * root /sbin/shutdown -h now

    I see the command being run in the CRON log, but the PC doesn't shutdown.

    Feb 11 11:06:17 localhost crontab[4808]: (root) LIST (root)
    Feb 11 11:07:31 localhost crontab[4813]: (root) BEGIN EDIT (root)
    Feb 11 11:07:58 localhost crontab[4813]: (root) END EDIT (root)
    Feb 11 11:10:01 localhost CROND[4821]: (root) CMD (root /sbin/shutdown -h now)

    How would I debug this to figure why my shutdown command is being ignored?

    I'd appreciate any pointers.

    Chris

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    is it set up to deliver mail? a lot of the times if there is output from a cron job it will be mailed (usually to root). So check root's mailbox, it should have some answers.
    linux user # 503963

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    8
    Good call!
    I had to cat /var/spool/mail/root to read the mail, and here's the problem:
    /bin/sh: root: command not found

    Looks like it doesn't like the "user" in there.
    I stripped out the user so the crontab reads:
    0,10,20,30,40,50 * * * * /sbin/shutdown -h now

    Now it works like a champ.
    Thanks for the help!.
    Chris

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=admin@somesite.com
    HOME=/

    Depending on the distro, I add these lines to my crontab file. Might help. Also a bit of advice, if you want to keep a cronjob from producing an output all together tack this onto the end of your line.

    Code:
    >/dev/null 2>&1
    linux user # 503963

  5. #5
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Quote Originally Posted by chris123 View Post
    Good call!
    I had to cat /var/spool/mail/root to read the mail, and here's the problem:
    /bin/sh: root: command not found

    Looks like it doesn't like the "user" in there.
    I stripped out the user so the crontab reads:
    0,10,20,30,40,50 * * * * /sbin/shutdown -h now

    Now it works like a champ.
    Thanks for the help!.
    Chris
    The "user" field is valid only in the /etc/crontab file.

Posting Permissions

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