linux - BASH shell script works properly at command prompt but doesn't work with crontab -


here script want execute crontab.

#!/bin/bash # file of path /home/ksl7922/memory_test/run_process.sh # 'mlp' name of process, , 'ksl7922' user account.  prgep mlp > /home/ksl7922/proc.txt  # line give number of process of 'mlp' result=`sed -n '$=' /home/ksl7922/proc.txt` echo "result = ${result}"  # if 'mlp' processes run less six, read text file 1 line , delete  # it, , execute line.  if ((result < 6));     filename="/home/ksl7922/memory_test/task_reserved.txt"     cat $filename | while read line              # delete line first.         sed -i "$line/d" $filename          # execute line         eval $line          break;     done else     echo "you're doing great." fi 

after that, editted crontab , checked crontab -l

*/20 * * * * sh /home/ksl7922/memory_test/run_process.sh 

this scripts works command line, however, doesn't work crontab.

it seems shell script works crontab anyway, because 'proc.txt' file generated, , first line of 'task_reserved.txt' removed.

however, didn't see messages, , result file of 'mlp' processes.

since i'm not @ english, i'm afraid guys don't understand intention. anyway, can let me know how handle this?

  1. my bet path environment variable not correctly set within cron. insert

    echo $path > /tmp/cron-path.txt 

    to see value has. perhaps need manually set proper value within script.

    this faq

  2. if don't have mail installations on system cron forward error messages script, it's practice manually redirect error messages preferred location. eg.

    #! /bin/bash {     date      prgep mlp > /home/ksl7922/proc.txt     ... snip ...     fi } &> /tmp/cron-msg.txt 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -