Results 1 to 4 of 4

Thread: Bash script running in cron

  1. #1
    Join Date
    Nov 2007
    Location
    USA Michigan
    Beans
    33
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Bash script running in cron

    I have a script with the following lines
    current_temp=70
    date=`date`
    echo $date,$current_temp >> log.csv

    Its running in my crontab every 15 minutes along with some other code but I cannot get the above lines to append data to log.csv. Do I have a syntax error? If I run it manually everything is fine....
    Ubuntu 9.04 X64, AMD 5000 BE, K9A2-Platinum, GTX260 - Dual Display.

  2. #2
    Join Date
    Jan 2012
    Beans
    342

    Re: Bash script running in cron

    Quote Originally Posted by powertower View Post
    I have a script with the following lines
    current_temp=70
    date=`date`
    echo $date,$current_temp >> log.csv

    Its running in my crontab every 15 minutes along with some other code but I cannot get the above lines to append data to log.csv. Do I have a syntax error? If I run it manually everything is fine.
    I can't say exactly but you should make it a habit of 'bracing' your variables, and not using (depreciated) backticks. Also, where is crons ${PWD}? .... use a path to a log.csv

    Code:
    #!/bin/bash
    
    CURRENT_TEMP="70"
    DATE=$(date)
    echo ${DATE},${CURRENT_TEMP} >> /path/to/log.csv
    HTH ... khay
    Last edited by Khayyam; February 29th, 2012 at 09:15 PM.

  3. #3
    Join Date
    Nov 2007
    Location
    USA Michigan
    Beans
    33
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Thumbs down Re: Bash script running in cron

    Quote Originally Posted by Khayyam View Post
    I can't say exactly but you should make it a habit of 'bracing' your variables, and not using (depreciated) backticks. Also, where is crons ${PWD}? .... use a path to a log.csv

    Code:
    #!/bin/bash
    
    CURRENT_TEMP="70"
    DATE=$(date)
    echo ${DATE},${CURRENT_TEMP} >> /path/to/log.csv
    HTH ... khay
    Reading your comment made everything come together. It was not storing the log.csv in my working directory, I need to specify the full log path...Thanks for the help.
    Ubuntu 9.04 X64, AMD 5000 BE, K9A2-Platinum, GTX260 - Dual Display.

  4. #4
    Join Date
    Jan 2012
    Beans
    342

    Re: Bash script running in cron

    Quote Originally Posted by powertower View Post
    Reading your comment made everything come together. It was not storing the log.csv in my working directory, I need to specify the full log path...Thanks for the help.
    Your welcome, I imagined it was the path (or lack thereof) to the logfile that was at issue. You should take the comments re bracing and backticks as a bonus .. heh

    You should now mark this thread as [SOLVED]

    best ... khay

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
  •