Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    7

    Unanswered: Unix Script scheduled in cron tab not able to write in log file.

    Hello experts,

    I have the following script,which I have scheduled in cron tab.

    **************************
    ps -u "user,pid,stime,pcpu,pmem,etime,args" | tail +2 | cut -c1-75 | sort -nr |

    pcpuinformat=$((ps -u informat -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmeminformat=$((ps -u informat -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcpudb2eod=$((ps -u db2eod -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmemdb2eod=$((ps -u db2eod -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcpudb2emd=$((ps -u db2emd -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmemdb2emd=$((ps -u db2emd -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcputrillium=$((ps -u trillium -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmemtrillium=$((ps -u trillium -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcpuinfouser=$((ps -u infouser -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmeminfouser=$((ps -u infouser -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcputriluser=$((ps -u triluser -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmemtriluser=$((ps -u triluser -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    pcpuroot=$((ps -u root -o pcpu | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)
    pmemroot=$((ps -u root -o pmem | tail +2 | tr "\n" "+" ; echo 0 ) | bc -l)

    printf '%s\n' "$(date '+%b %d %Y %H.%M') informat $pcpuinformat $pmeminformat db2eod $pcpudb2eod $pmemdb2eod db2emd $pcpudb2emd $pmemdb2emd trillium $pcputrillium $pmemtrillium infouser $pcpuinfouser
    $pmeminfouser triluser $pcputriluser $pmemtriluser root $pcpuroot $pmemroot" >> logfile

    echo "$(date '+%b %d %Y %H.%M') informat $pcpuinformat $pmeminformat db2eod $pcpudb2eod $pmemdb2eod db2emd $pcpudb2emd $pmemdb2emd trillium $pcputrillium $pmemtrillium infouser $pcpuinfouser $pmeminfo
    user triluser $pcputriluser $pmemtriluser root $pcpuroot $pmemroot"
    ~
    ~
    ~
    ~
    ~
    ~
    **************************
    Cron tab : 0,10,20,30,40,50 * * * * /informatica/pc/cpu_stats.sh >> /informatica/pc/logfile

    This script is not able to write the out put in log file. But if I am running independantly (sh.cpu_stats.sh) it's creating the log file and also writing the out put .

    Can you please help me in getting the out put appended in the log file, when the script is scheduled and run through cron tab.

    Thanks
    Himansu.

  2. #2
    Join Date
    Jul 2005
    Posts
    16
    Hello,

    Since you're already specifying the name of your logfile in the script, try adding the location as well. /informatica/pc/logfile. Then, in your crontab, replace the ">> /informatica/pc/logfile" with "2&>1"

    It should look like the following:

    : 0,10,20,30,40,50 * * * * /informatica/pc/cpu_stats.sh 2&>1


    Hopefully that does it for you. I've tested it on my end and all worked.

    PS - Here's what I placed in my crontab: 0 1,2,3,4,5,6,7,8,9,10,11,12 * * 0,1,2,3,4,5,6 /home/me/thisisatest 2>&1
    Last edited by hoffa4444; 12-14-06 at 13:06.

  3. #3
    Join Date
    Oct 2006
    Posts
    7
    Thanks for responding.As adviced, I did the necessary changes but it's not working for me. The logfile is not getting created.

  4. #4
    Join Date
    Jul 2005
    Posts
    16
    hmm.

    When running the script manually, where is it placing the log file? And, what are the current permissions for the directory you want the log file to go to?

Posting Permissions

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