crontab script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab script
# 1  
Old 09-12-2011
crontab script

Hi All,

I am running a script to find the CPU and memory utilization of the server. Script name is atul. When i run this script then it gives the desired output as DATE, CPU and MEMORY utilization....as mentioned below:

Code:
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat atul
A=`date| cut -d" " -f1-4; top -d 1 -n 1 | awk '/^CPU states/ {print $3,$5,$7,$9} /^Mem/ {print $2,$3,$4,$5,$6,$7,$8,$9,$10}'`
echo $A
[core4.1_txn5@stack1-srv1 SCRIPTS]$ ./atul
Mon Sep 12 12:49:33  8309804k total, 1758772k used, 6551032k free, 55464k buffers
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ ./atul >> output
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat output
Mon Sep 12 12:50:03  8309804k total, 1759764k used, 6550040k free, 55736k buffers
[core4.1_txn5@stack1-srv1 SCRIPTS]$

However, when i run this script through crontab, it gives incomplete output. It only display the date and not the cpu and memory utilization Smilie:

Code:
[core4.1_txn5@stack1-srv1 SCRIPTS]$ crontab -l
* * * * * ./SCRIPTS/atul >> /home/core4.1_txn5/SCRIPTS/output
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat output
Mon Sep 12 12:50:03  8309804k total, 1759764k used, 6550040k free, 55736k buffers
Mon Sep 12 12:51:01
Mon Sep 12 12:52:01
Mon Sep 12 12:53:01

Kindly, provide me the solution....as i want complete output after running the CRONTAB.

Last edited by pludi; 09-12-2011 at 04:58 AM..
# 2  
Old 09-12-2011
just give a try with " (double quotes)

Code:
 
echo "$A"

# 3  
Old 09-12-2011
same issue

Thanks for the reply..i have tried but still result is same.. SmilieSmilie
Code:
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat atul
A=`date| cut -d" " -f1-4; top -d 1 -n 1 | awk '/^CPU states/ {print $3,$5,$7,$9} /^Mem/ {print $2,$3,$4,$5,$6,$7,$8,$9,$10}'`
echo "$A"
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ crontab -l
* * * * * ./SCRIPTS/atul >> /home/core4.1_txn5/SCRIPTS/output
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ date
Mon Sep 12 13:51:02 IST 2011
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat output
Mon Sep 12 13:47:01
Mon Sep 12 13:48:01
Mon Sep 12 13:49:01
Mon Sep 12 13:50:02


Last edited by Franklin52; 09-12-2011 at 08:26 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 09-12-2011
Code:
 
A=`top -d 1 -n 1 | awk '/^CPU states/ {print $3,$5,$7,$9} /^Mem/ {print $2,$3,$4,$5,$6,$7,$8,$9,$10}'`
B=`date| cut -d" " -f1-4`
echo $B $A

# 5  
Old 09-12-2011
Thanks for the suggestion...I have executed only $A as per your suggestion..its working fine from command but displaying NO/BLANK Output.

[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat aa
A=`top -d 1 -n 1 | awk '/^CPU states/ {print $3,$5,$7,$9} /^Mem/ {print $2,$3,$4,$5,$6,$7,$8,$9,$10}'`
echo $A

[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ ./aa >> opt
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat opt
8309804k total, 2025836k used, 6283968k free, 100812k buffers
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ crontab -l
* * * * * ./SCRIPTS/aa >> /home/core4.1_txn5/SCRIPTS/opt
[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$ cat opt
8309804k total, 2025836k used, 6283968k free, 100812k buffers





[core4.1_txn5@stack1-srv1 SCRIPTS]$
[core4.1_txn5@stack1-srv1 SCRIPTS]$

As you can see, its showing blank output in the OPT file.

As i m reading many forums..i think the problem is that, in my case, the AWK command is not working through Crontab. I am not sure but i think this is due to some ENVIREMENT ISSUE...something I have to declare in the script so that it can read..

Please correct me if m wrong..
# 6  
Old 09-12-2011
try with full path of awk command
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crontab in script

I have crontab setup via crontab -e I was wondering if its possible to create a cron job from a script so when the script is run the cron job is created? (3 Replies)
Discussion started by: scriptnewbie
3 Replies

2. UNIX for Dummies Questions & Answers

crontab not running script

Hi All, I am having the below script to be run from crontab, it it doesnt run. 1 * * * * /home/cobr_ext/test.sh > /home/cobr_ext/temp.txt when i run i manally it runs without any issues. Could please help me as to why doesnt it run the script.:( (7 Replies)
Discussion started by: abhi_123
7 Replies

3. UNIX for Dummies Questions & Answers

Crontab + Script + .sql

Hi guys today i'll bring to you a new problem that i need to execute. So what i need to do it's create a script that: conect to some database logon run a .sql script logoff and close the connection after that, put this script on the crontab To set up the crontab it's ok for me, i think... (3 Replies)
Discussion started by: Newer
3 Replies

4. UNIX for Dummies Questions & Answers

crontab script

Hi guys Can someone help me with a crontab script please? I have to sort the files from /bin and put the first 3 of then (with size and path) in /home/user/bin_size i write the command: find /bin/ | xargs ls -lS | awk 'FNR<4{print($5, $9)}' > /home/user/bin_size which is working but when... (6 Replies)
Discussion started by: G30
6 Replies

5. UNIX for Dummies Questions & Answers

crontab script

Hi guys Can someone help me with a crontab script please? I have to sort the files from /bin and put the first 3 of then (with size and path) in /home/user/bin_size i write the command: find /bin/ | xargs ls -lS | awk 'FNR<4{print($5, $9)}' > /home/user/bin_size which is working but when I... (2 Replies)
Discussion started by: G30
2 Replies

6. Solaris

pl script in crontab

Hi I have successfukky created a sh script that runs perfectly well when run. It contains within a pl script that when run through a crontab will not run. Are there restrictions running a pl in cron? (14 Replies)
Discussion started by: rob171171
14 Replies

7. Shell Programming and Scripting

How to add a script to Crontab?

Hi! We are on AIX 5.3 I have a script that must be run once every hour. How do i add this to the crontab? I know how to access crontab which is, crontab -e. What do i do after that ? If i have the path to the script? Thank you!!! (4 Replies)
Discussion started by: atechcorp
4 Replies

8. Shell Programming and Scripting

Crontab a Script

I know my question maybe eazy, but it realy cause a problem for me I have a Perl script to run and get some output, I run this script using perl /moutaz/ciscolog/telnet.pl I made another script as follow:(/moutaz/ciscolog/script) #!/bin/bash perl /moutaz/ciscolog/telnet.pl cp... (6 Replies)
Discussion started by: moutaz1983
6 Replies

9. UNIX for Dummies Questions & Answers

Using a script to modify the crontab

I want to add one line to the end of my crontab using a script. I have tried piping in the editor commands, but I can't get it to work. crontab -e user << EX $a This is the text I want to add. . wq EX This doesn't work. Is there an easier way to do this? (2 Replies)
Discussion started by: johnmsucpe
2 Replies

10. Shell Programming and Scripting

how can i use crontab in a script?

hi.. i wolud like to know if itīs possible use the crontab command in my script. the idea is what the script starts automatically, but i donīt know how to do it. please, help me.... thanks jonathan (1 Reply)
Discussion started by: DebianJ
1 Replies
Login or Register to Ask a Question