strange CRON problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting strange CRON problem
# 1  
Old 10-06-2009
strange CRON problem

Hi All,

I am facing a strange problem with my shell script when I run the script from CRON.

script----
Code:
#!/bin/ksh
date_var=`date "+%Y%m%d%H%M%S"`
memory_file_name=Mem-"$date_var".csv

total_memory_mb=`prtconf -v | grep Memory |tr -s " " "," | cut -f3 -d ','`
total_memory_kb=`expr $total_memory_mb \* 1024`
echo total memory is $total_memory_kb >> script-"$date_var".log
free_memory=`vmstat 1 1 |grep -v memory |grep -v swap|tr -s " " "," |cut -f6 -d ','`
used_memory=`expr $total_memory_kb - $free_memory`
echo calaculated memory informations >>script-"$date_var".log
#write memory details to file
echo Used,Free,Total,Date >> $memory_file_name

echo $used_memory,$free_memory,$total_memory_kb,$date_var >> $memory_file_name
echo Finished writing to file >>script-"$date_var".log

when I run the script after logging into server it works fine...but when I run the script using CRON it doesn't give me output for total_memory_kb and used_memory ..

I couldn't understand why its happening...

any suggestions please....

Last edited by pludi; 10-06-2009 at 08:52 AM.. Reason: code tags please...
# 2  
Old 10-06-2009
Error

paste the cron entry .....
# 3  
Old 10-06-2009
CRON entry.....
Code:
15 * * * * /domain/appplication/memory/script.sh >> /domain/appplication/memory/log/cron.log


Last edited by pludi; 10-06-2009 at 08:52 AM.. Reason: code tags please...
# 4  
Old 10-06-2009
try using absolute pathnames in your script.
# 5  
Old 10-06-2009
can you please explain what you mean by "absolute pathnames in your script"

I have the script in /domain/appplication/memory/ directory which i have included in CRON entry... I get the $used_memory value...I am just not getting the total_memory_kb and used_memory value through CRON...

---------- Post updated at 01:01 PM ---------- Previous update was at 12:23 PM ----------

sorry to rectify the above note:-

can you please explain what you mean by "absolute pathnames in your script"

I have the script in /domain/appplication/memory/ directory which i have included in CRON entry... I get the $free_memory value...I am just not getting the total_memory_kb and used_memory value through CRON...
# 6  
Old 10-06-2009
Try sourcing your .profile in the script. Cron does not automatically source profiles. Different shells use different profiles. I'm assuming you have the Korne shell as your default since you are using ksh in your script. So my example is directed toward the use of the Korne shell as a default shell.

#!/bin/ksh

#
# Source the users profile.
#
# NOTE: There is a space between the first dot (.) and the tilde (~)
#
. ~/.profile

date_var=`date "+%Y%m%d%H%M%S"`
memory_file_name=Mem-"$date_var".csv
# 7  
Old 10-06-2009
cheers!!! mate its working now....Many thanks for your suggestion.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

2. Shell Programming and Scripting

strange problem

hello all, i am having problem in accessing a directory.I dont think its a permission issue.can anyone help me out. I am using korn sell code: $ ls -ltr sc* lrwxrwxrwx 1 essbase essbase 21 Oct 8 2010 sc_ssp -> /work/nfs/nas2/sc_ssp $ cd sc_ssp ksh: sc_ssp: not found $ (6 Replies)
Discussion started by: manid
6 Replies

3. Shell Programming and Scripting

Strange Problem

Hi All, I am encountering an unexpected problem while running my process, using daemon placed in /etc/init.d/. I have a process that is opening shared library using dlopen. When I run my process on the command line, it is able to open the library. But when I used daemon to run my process, I... (0 Replies)
Discussion started by: qwerty-1
0 Replies

4. AIX

strange CRON job

i want to schedule my backup thru cron job. my requirement is from 9am to 5pm i want hourly backup every day how can this be achived thru cron can any one help me with the this type of timing schedule in cronjob? (2 Replies)
Discussion started by: pchangba
2 Replies

5. Shell Programming and Scripting

Strange problem.

Well, my script started off to do what i wanted. Now, i think its not recognizing the pattern so its not moving anything. What i have to do is execute my script command for the move to take effect. So i did that and yayy it worked. Strange thing is that my DESTDIR was empty to begin with.... (2 Replies)
Discussion started by: oxoxo
2 Replies

6. Shell Programming and Scripting

Strange problem

I am using SunOS 5.9 and I don't know why all my commands are getting executed as if an extra 'enter' has been pressed. What could be the reason and how to correct it? Please help. Asty (2 Replies)
Discussion started by: Asty
2 Replies

7. Linux

very strange problem

I have installed Fedora Core on a Toshiba Satellite Pro4600 laptop recently I have experienced a rather mysterious problem if I touch anything specially the keyboard or mouse I see this stuff “67yujhnmyyy” straight away some time it won't stop for while like this... (5 Replies)
Discussion started by: kemobyte
5 Replies

8. UNIX for Dummies Questions & Answers

strange...problem

Hi.. Some of my application were not running properly due to lack of virtual memory.....so wht i did add one free harddisk as swap file system...and increased the swap memory.. But since than my root file system is showing 100% full thr is no space left...is thr any link between these two..... (1 Reply)
Discussion started by: Prafulla
1 Replies

9. UNIX for Dummies Questions & Answers

Strange Problem

I did an installation of Redhat 7.1 and it seem to install smoothly. I go and reboot and I get the following message: "INIT: Id "x" respawing too fast: disabled for 5 minutes" The screen flashes 4 times every 10 seconds or so. I can't seem to figure why this does this. It might be a simple... (2 Replies)
Discussion started by: forjohnny
2 Replies

10. UNIX for Dummies Questions & Answers

Strange problem.Please Help !

I¡¯m a network operator, mine is an IBM PC server 320, operating system SCO unix 3.2v4.2, triton 3.1 of Baan. Recently, my server went dead every a few hours, no sign & signal shows malfunction suddenly. It looks like a sudden power failure, but the indicator of main power supply is on. Normal... (1 Reply)
Discussion started by: lyhsm
1 Replies
Login or Register to Ask a Question