If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Unix Script scheduled in cron tab not able to write in log file.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-06, 11:42
pintu005 pintu005 is offline
Registered User
 
Join Date: Oct 2006
Posts: 7
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.
Reply With Quote
  #2 (permalink)  
Old 12-14-06, 12:02
hoffa4444 hoffa4444 is offline
Registered User
 
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 12:06.
Reply With Quote
  #3 (permalink)  
Old 12-14-06, 15:59
pintu005 pintu005 is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 12-14-06, 18:54
hoffa4444 hoffa4444 is offline
Registered User
 
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On