Error while running a script through cron job


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Error while running a script through cron job
# 8  
Old 03-17-2014
You have to capture stderr in a file to see the log.
# 9  
Old 03-17-2014
Please find the output
Code:
++ export PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/sar
++ PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/sar
++ ADMIN=abc@abc.com
+++ /usr/bin/sar
+++ /usr/bin/awk '{print $9}'
+++ /bin/sort -n
+++ /usr/bin/head -5
+++ /bin/sed -n 5p
++ CPU_HIGH=
+++ echo 'scale=3; 100-'
+++ /usr/bin/bc
(standard_in) 2: parse error
++ CPU_MAX=
+++ /usr/bin/sar
+++ awk '{print $9}'
+++ sort -n
+++ tail -1
++ CPU_LOW=
+++ echo 'scale=3; 100-'
+++ /usr/bin/bc
(standard_in) 2: parse error
++ CPU_MIN=
+++ awk '{print $2}'
++++ date +%d-%B-%Y
+++ sort -n
+++ tail -1
+++ cat /root/admin_files/server_monitor/datewise_monitor/ram_monitor-17-March-2014
++ MEM_MAX=12.200
+++ awk '{print $2}'
++++ date +%d-%B-%Y
+++ sort -n
+++ head -1
+++ cat /root/admin_files/server_monitor/datewise_monitor/ram_monitor-17-March-2014
++ MEM_MIN=11.800
+++ date +-%Y-%m-%d-%H:%M:%S
++ now=-2014-03-17-18:20:01
++ file=utilization_-2014-03-17-18:20:01.log
++ filename=/root/admin_files/server_monitor/datewise_monitor/utilization_-2014-03-17-18:20:01.log
+++ date
+++ hostname
++ echo 'Mon Mar 17 18:20:01 GMT 2014: Memory Utilization Report for server mmv0pfecdel0070 is'
++ echo -----------------------------------
++ echo '                                   '
++ echo 'CPU Max Utilization :   %  '
++ echo 'CPU Min Utilization  :   % '
++ echo '                                   '
++ echo 'Max Ram Utilization :  12.200 %  '
++ echo 'Min Ram Utilization  :  11.800 % '
++ cat /root/admin_files/server_monitor/datewise_monitor/utilization_-2014-03-17-18:20:01.log
+++ date +%d-%B-%Y
+++ hostname
+++ ifconfig eth0
+++ sed -n '/inet /{s/.*addr://;s/ .*//;p}'
++ mail -s '17-March-2014: CPU & Memory Summarization Report for server mmv0pfecdel0070 : 10.129.192.198 ' abc@abc.com
++ sar
+++ date +-%d-%B-%Y
++ sar -r
+++ date +-%d-%B-%Y

---------- Post updated at 01:45 PM ---------- Previous update was at 01:44 PM ----------

The same code is working when running manually.

---------- Post updated at 02:34 PM ---------- Previous update was at 01:45 PM ----------

i guess there is an issue when using bc in the crontab.

Last edited by Franklin52; 03-18-2014 at 04:02 AM.. Reason: Please use code tags
# 10  
Old 03-17-2014
It is not the problem with bc.

The problem is sar output is different when running from cron and from command line.

From command line:
Code:
12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM     all     51.22      0.01      6.16      0.23      0.00     42.37

From crontab:
Code:
00:00:01        CPU     %user     %nice   %system   %iowait    %steal     %idle
00:10:01        all     51.22      0.01      6.16      0.23      0.00     42.37

Set LC_TIME before running sar to display AM/PM data:
Code:
LC_TIME=en_US.UTF-8 sar

# 11  
Old 03-17-2014
One question :

1) what if instead of awk'{print $9}' i try using awk'{print $8}'

2) Will adding the line
LC_TIME=en_US.UTF-8 in the beginning of the script will suffice??
# 12  
Old 03-17-2014
Yes, you can try awk'{print $8}' instead. But then it will not work from command line.

So the best approach is to set LC_TIME and it will work either way.
# 13  
Old 03-17-2014
so i need to add LC_TIME in the beginning of the script??
# 14  
Old 03-17-2014
Quote:
Originally Posted by Ekamjot
so i need to add LC_TIME in the beginning of the script??
Yes
Code:
export LC_TIME=en_US.UTF-8

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CRON job still running?

Hi All, I am writing a script that will eventually be executed by a cron job every 15 minutes. I want to make sure that my logic/script doesn't get executed if a previous job is still running. What would be the best way to handle that scenario? I was thinking to make my script create a temporary... (1 Reply)
Discussion started by: rdogadin
1 Replies

2. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

3. Solaris

Cron job is not running

Hi, I have set up the crontab as follows. root@IDC4VASAPP07 # crontab -l 0-59 * * * * /var/tmp/r.sh 0-59 * * * * date >> /var/tmp/log root@IDC4VASAPP07 # r.sh is as follows. root@IDC4VASAPP07 # cat r.sh #!/bin/bash dt1=$(perl -e 'use POSIX;print strftime... (10 Replies)
Discussion started by: SunilB2011
10 Replies

4. Solaris

Shell Script gives error when run through cron job.

Hi, The following shell script runs without any problem when executed manulally. USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1) if then find /arch/AUBUAT/ -type f -mtime +0 | xargs rm find /arch/AUBMIG/ -type f -mtime +0 | xargs rm fi But the same gives below... (6 Replies)
Discussion started by: ksadiq79
6 Replies

5. Shell Programming and Scripting

Running script file using cron job every 5 second

Hi All, I beginner in unix, i have no idea how to set the script file using cron job every 5 second. I also want to execute automatically the output to text file.This is my script name countsys.sh and my textfile abc.txt. (6 Replies)
Discussion started by: mastercar
6 Replies

6. UNIX for Dummies Questions & Answers

Cron job not running

Hi All, I am editing crontab using -e option to add a new job Below is the line 30 * * * * scriptpath This job is not executing every thirty minutes. I have checked, cron daemon is running. What did I miss? Can some one help? I am using cron shell..ksh (7 Replies)
Discussion started by: yabhi_22
7 Replies

7. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies

8. Shell Programming and Scripting

Cron job giving error while running SSH command

Hi All, The script which i am using to SSH to remote server is working fine when i run is using ./ but when cron runs it it gives error that "ssh: not found" please help!!! (3 Replies)
Discussion started by: visingha
3 Replies

9. UNIX for Advanced & Expert Users

cron job is not running

hi, i have the following line in the crontab 15 5 * * 6 /home/adw/BCE_ADW.pl The problem is the cron job is not getting started automatically. But this was working til last week. now it is not working. what could be the problem. Any idea? (3 Replies)
Discussion started by: Suguna
3 Replies

10. HP-UX

Cron Job Not Running

Hi, I have a cron schedule like this 04,16,28,40,52 * * * * /nag/startProcessABatch (unix script) i want to add new lines in this file (like Logging), i just copy this file into a /tmp folder (for backup copy), and i have edited this file (added few lines of code for logging). ... (1 Reply)
Discussion started by: nag_sundaram
1 Replies
Login or Register to Ask a Question