You are not logged in.

#1 2012-08-01 00:26:03

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Why can't cron run one of my scripts [SOLVED]

I'm confused why cron can't run one of my scripts which runs just fine interactively.  I see no errors in messages.log or crond.log.

My crontab:

$ crontab -l
#     *     *   *    *        command to be executed
#-     -     -   -    -
#|     |     |   |    |
#|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
#|     |     |   +------- month (1 - 12)
#|     |     +--------- day of month (1 - 31)
#|     +----------- hour (0 - 23)
#+------------- min (0 - 59)

#MAILTO=""
25 20 * * *   ~/bin/cpuz s

Here is the code to that script:

run() {
  tmpfile=/tmp/.sensors_unique.txt  # temp output
  verbose=/tmp/.verbose_unique.txt  # verbose temp output with three decimals
  logfile=/scratch/unique.csv       # data file to write

  sensors >$tmpfile && sensors -u >$verbose

  phys=$(grep Physical $tmpfile | cut -c 18-21)
  c0=$(grep "Core 0" $tmpfile | cut -c18-21)
  c1=$(grep "Core 1" $tmpfile | cut -c18-21)
  c2=$(grep "Core 2" $tmpfile | cut -c18-21)
  c3=$(grep "Core 3" $tmpfile | cut -c18-21)

  vcc=$(grep in0_input $verbose | cut -c14-18)

  fan1=$(grep fan1 $tmpfile | cut -c24-27)
  pwm1=$(cat /sys/class/hwmon/hwmon3/device/pwm1)
  per1=$(echo "scale=2; $pwm1/2.55" | bc)

  fan3=$(grep fan3 $tmpfile | cut -c24-27)
  pwm3=$(cat /sys/class/hwmon/hwmon3/device/pwm3)
  per3=$(echo "scale=2; $pwm3/2.55" | bc)

  fan4=$(grep fan4 $tmpfile | cut -c24-27)
  pwm4=$(cat /sys/class/hwmon/hwmon3/device/pwm4)
  per4=$(echo "scale=2; $pwm4/2.55" | bc)

  fan5=$(grep fan5 $tmpfile | cut -c24-27)
  pwm5=$(cat /sys/class/hwmon/hwmon3/device/pwm5)
  per5=$(echo "scale=2; $pwm5/2.55" | bc)

  dts=$(date +"%m-%d-%y %r")
  [[ ! -f $logfile ]] && echo "dts,vcc,temp,core0,core1,core2,core3,120mm_rpm,120mm_pwm,140mm_rpm,140mm_pwm,comment" > $logfile

  echo "$dts,$vcc,$phys,$c0,$c1,$c2,$c3,$fan4,$pwm4,$fan5,$pwm5,$comment" >> $logfile

  if [ -n "$output" ]; then
    echo "Vcore : $vcc"
    echo "back  : $fan1 ($pwm1/255) = $per1 %"
    echo "top   : $fan3 ($pwm3/255) = $per3 %"
    echo "120mm : $fan4 ($pwm4/255) = $per4 %"
    echo "140mm : $fan5 ($pwm5/255) = $per5 %"
  fi
}

case "$1" in
  s)
    limit=600                 # number of times to run
    wait=2                      # delay in sec before taking a new reading
    echo running in silent mode...
    x=0
    while [ "$x" -lt "$limit" ]; do
      x=$(( $x + 1 ))
      run
      sleep "$wait"s
    done
    ;;
  v)
    export output="not null"
    export -f run
    /usr/bin/watch run
    ;;
  *)
    echo "usage $0 {s|v}"
    echo
    echo "s) silent mode/logfile only"
    echo "v) verbose mode/logfile + output"
    exit 0
    ;;
esac

Last edited by graysky (2012-08-01 00:44:16)

Offline

#2 2012-08-01 00:30:39

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: Why can't cron run one of my scripts [SOLVED]

I hate to suggest something obvious to someone with 4000 posts (and such a scary avatar), but have you tried it with the full path: /home/user/... ?

Are you sure the script is not being run at all?
(edit -- never mind, I see the file lines in there)

Last edited by 2ManyDogs (2012-08-01 00:33:03)

Offline

#3 2012-08-01 00:44:05

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Why can't cron run one of my scripts [SOLVED]

@2many - That was the problem.  Thought I remembered using ~ in the crontab with no problem before... oh well.  Thx.

Last edited by graysky (2012-08-01 00:44:35)

Offline

#4 2012-08-01 00:49:15

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: Why can't cron run one of my scripts [SOLVED]

You're welcome.

Offline

Board footer

Powered by FluxBB