Results 1 to 7 of 7

Thread: Crontab Help

  1. #1
    Join Date
    Oct 2011
    Location
    Canada
    Beans
    891
    Distro
    Ubuntu 12.04 Precise Pangolin

    Exclamation Crontab Help

    Hey guys, basically I installed Ubuntu on an old Dell desktop but the problem is it lacks fans and even the space to install new ones so it runs quite hot....I need it to run 24/7 but I am worried about the internals frying. Specifically, the HDD which is a Seagate (max operating temp = 50c) as it gets up to 47c sometimes which is too close for comfort....

    I found a potential command I can use (thanks to hddtemp) to shutdown the computer if temperatures ever hit a specific degree and I'd like to implement it, but have never manually added a job to crontab. Keep in mind it is a headless PC so I'll be doing this via command line and yes I do know where the crontab file is.

    Command:

    Code:
    $(hddtemp /dev/sda | awk '{ print $4}' | awk -F '°' '{ print $1}') -ge 50 ] && /sbin/shutdown -h 0 || :
    ^Do I just copy/paste that into the file? The stock options already there seem to be formatted completely different....Also, I have to use sudo to get a reading from hddtemp, do I have to specify that in the crontab?
    613websites.com Budget Canadian Web Design and Hosting

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,035
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Crontab Help

    You don't want to use sudo from your crontab. Instead use sudo to add the job to root's crontab, i.e.
    Code:
    sudo crontab -e
    When you have a fairly complex command with subshells, pipes and quotes, I would put all that in a script and run the script from crontab. For example create a script /usr/local/sbin/check-hddtemp
    Code:
    #!/bin/bash
    your command here
    Then in crontab, supposing you want to run it once a minute,
    Code:
    * * * * * /usr/local/sbin/check-hddtemp

  3. #3
    Join Date
    Oct 2011
    Location
    Canada
    Beans
    891
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Crontab Help

    Thanks for the reply! What if I want it to check every 15min instead? Also, how does the below bash script look?

    http://paste2.org/p/2090899
    Last edited by d4m1r; August 1st, 2012 at 10:52 PM.
    613websites.com Budget Canadian Web Design and Hosting

  4. #4
    Join Date
    Oct 2006
    Location
    New York
    Beans
    1,118
    Distro
    Xubuntu 12.10 Quantal Quetzal

    Re: Crontab Help

    If you want it to run every 15:
    */15 * * * * /path/to/script
    wikipedia does a respectable job of covering the syntax: http://en.wikipedia.org/wiki/Crontab#CRON_expression

    I'd also like to second everything said above, put it in root's crontab, and put it in a script instead of having a complicated command called from the crontab.

    Also, linebreaks in your script?
    xubuntu minimal, extensive experience, lshw: http://goo.gl/qCCtn
    blog: http://goo.gl/yLg78
    Linux viruses: http://goo.gl/6OCKA

  5. #5
    Join Date
    Oct 2011
    Location
    Canada
    Beans
    891
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Crontab Help

    Thanks for the help guys but I can't seem to get this to work....Here's what I've done:

    1) Copied THIS script to /usr/local/sbin and called it check-hddtemp

    2)sudo chmod +x

    3)Tried to run it (./) and nothing happens...no message nothing. Does this still mean it's working but didn't shutdown because the temperature is >50c?

    Should I now just specify that script location and the 15min formatting in my crontab file? Since I need need sudo to use hddtemp do I specify that in the crontab file or does it automatically run the file as root?
    Last edited by d4m1r; August 2nd, 2012 at 12:06 AM.
    613websites.com Budget Canadian Web Design and Hosting

  6. #6
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,035
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Crontab Help

    Quote Originally Posted by d4m1r View Post
    Thanks for the help guys but I can't seem to get this to work....Here's what I've done:

    1) Copied THIS script to /usr/local/sbin and called it check-hddtemp

    2)sudo chmod +x

    3)Tried to run it (./) and nothing happens...no message nothing. Does this still mean it's working but didn't shutdown because the temperature is >50c?
    The script you posted on pastebin doesn't output anything if the temperature is less than the threshold. For testing purposes, you could add an else branch with a message if the temperature is OK.

    Should I now just specify that script location and the 15min formatting in my crontab file? Since I need need sudo to use hddtemp do I specify that in the crontab file or does it automatically run the file as root?
    Yes. If you use
    Code:
    sudo crontab -e
    you will be editing the crontab that belongs to the root user and the job will run as root. There's no need to put sudo in the crontab file.

  7. #7
    Join Date
    Oct 2011
    Location
    Canada
    Beans
    891
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Crontab Help

    Perfect! Think I got it working...it does do some logging to /var/logs/syslog.
    613websites.com Budget Canadian Web Design and Hosting

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
  •