Solved

Solaris 8 Crontab cron entry output unexpected

Posted on 2009-05-08
15
1,424 Views
Last Modified: 2013-12-21
Hi,

When I issue at # prompt using root,
"prtdiag -v | grep -i ambie"  gave   "AMBIENT   18"

but when I place following script in root's crontab, it gave outputs that belongs
to other portions of prtdiag  :
Sat May  9 10:20:00 SGT 2009
$ rm system_uat_1.da BMCINSTALL DeadLetters Mail Software TT_DB a.a adm afiedt.buf awk backup bin ca_li
c cdrom cdrom1 cdrom2 crontab.out csa dev devices etc export home kernel ldau_application.log lib lost+
found lp ls mbox mnt net nsmail opt oracle platform proc raidrvcmd.o rm_tables.lst sbin script sla sqln
et.log start sys-logs t.t tftpboot tmp usr var vol xfn


temperature_script.sh content is :
echo ======== >> /backup/tempcap.o
date >> /backup/tempcap.o
prtdiag -v | grep -i ambie >> /backup/tempcap.o

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59 * * * * /var/tmp/temperature_script.sh


I think Blu or someone ever told me Solaris 8 cron has some problem but
I can't recall
0
Comment
Question by:sunhux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 1

Assisted Solution

by:whiteonline
whiteonline earned 80 total points
ID: 24342268
Hello,
First off, to run every minute you can clean up your entry to:
* * * * * /var/tmp/temperature_script.sh

Are you running the cron entry as a specific user? Are there any special environmental variables set when logged in that may be be getting set under cron? You may have to set those in your shell script.

Another thing to look at is the duration of prtdiag -v. Are you running into race conditions?

Depending on your platform, take a look at the command: /usr/sbin/prtpicl. If you run with options '-v -c temperature-sensor' it will provide various CPU metrics. There is a wealth of information returned from prtpicl -v and it is MUCH faster than prtdiag.
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 290 total points
ID: 24342622
you need to use the * for the min part in cron job to run every min. Also, you need to

- set required env variables like PATH
- use full path name to files, dirs, commands
- redirect stdin, stdout and stderr to files
0
 

Author Comment

by:sunhux
ID: 24343085
Thanks guys for correcting the every minute crontab entry.

> prtdiag -v. Are you running into race conditions?
What's race conditions & how to fix these?

> redirect stdin, stdout and stderr to files
Thought by doing "prtdiag -v | grep -i ambie >> file",
the >> already redirects, or is it?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 290 total points
ID: 24343256
race condition is when you are overrunning the job e.g. every min and the job starts before the previous one finishes. If this is the case then consider running it at 5 min intervals (or 2 min)

The redirection with >> is ok as long as you put full path name e.g. >> /path/to/file
0
 

Author Comment

by:sunhux
ID: 24346930

Yep, I did specify the full path and don't think there's race condition as the
echo & "prtdiag -v"  would have finished within a minute.

So I can't really see how it is the "prtdiag -v | grep -i ambie" in script run from
crontab would have given the output below :
$ rm system_uat_1.da BMCINSTALL DeadLetters Mail Software  ......

I've just run this script manually at command prompt ie ./script_name
and it creates the correct output (ie "AMBIENT   18") in the right directory.
So it's something in the cron that interferes with this
0
 

Author Comment

by:sunhux
ID: 24346932
Also I'm sure it's not due to race condition because the very first output already
contain that unexpected output and not the 2nd output onwards
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 290 total points
ID: 24346941
can you show the full script?
0
 
LVL 1

Assisted Solution

by:whiteonline
whiteonline earned 80 total points
ID: 24346977
Does your /var/cron/log show anything out of the ordinary?

Maybe for sanity's sake, install patch 109007-28, which will patch cron.
0
 

Author Comment

by:sunhux
ID: 24347143
This is the content (only 3 lines) of the Shell script :

echo ======== >> /backup/tempcap.o
prtdiag -v | grep -i ambie >> /backup/tempcap.o
date >> /backup/tempcap.o

The cron entry looks as follows :
* * * * * /var/tmp/tempcap.sh

This time, nothing from "prtdiag -v | ....." was output to the file
/backup/tempcap.o, only the date/time as shown :

Sun May 10 15:29:00 SGT 2009
========
Sun May 10 15:30:01 SGT 2009
========
Sun May 10 15:31:00 SGT 2009




During the last few minutes when the above cron entry was executed,
nothing abnormal spotted in  /var/cron/log :

>  sys 27934 c Sun May 10 15:15:00 2009
<  sys 27934 c Sun May 10 15:15:00 2009
<  FTPFRS 27933 c Sun May 10 15:15:06 2009
>  CMD: ksh /sla/prod/ftp_data/bin/checkftp.sh 1> /sla/prod/ftp_data/logs/cronlo
g 2>/sla/prod/ftp_data/logs/cronerr
>  FTPFRS 28163 c Sun May 10 15:20:00 2009
>  CMD: /usr/lib/sa/sa1
>  sys 28164 c Sun May 10 15:20:01 2009
<  sys 28164 c Sun May 10 15:20:01 2009
<  FTPFRS 28163 c Sun May 10 15:20:01 2009
>  CMD: ksh /sla/prod/ftp_data/bin/checkftp.sh 1> /sla/prod/ftp_data/logs/cronlo
g 2>/sla/prod/ftp_data/logs/cronerr
>  FTPFRS 28342 c Sun May 10 15:25:00 2009
>  CMD: /usr/lib/sa/sa1
>  sys 28343 c Sun May 10 15:25:00 2009
<  sys 28343 c Sun May 10 15:25:00 2009
<  FTPFRS 28342 c Sun May 10 15:25:06 2009
! unexpected pid returned 28422 (ignored) Sun May 10 15:26:25 2009
>  CMD: /var/tmp/tempcap.sh
>  root 28440 c Sun May 10 15:27:00 2009
<  root 28440 c Sun May 10 15:27:00 2009 rc=1
>  CMD: /var/tmp/tempcap.sh
>  root 28516 c Sun May 10 15:28:00 2009
<  root 28516 c Sun May 10 15:28:00 2009 rc=1
>  CMD: /var/tmp/tempcap.sh
>  root 28535 c Sun May 10 15:29:00 2009
<  root 28535 c Sun May 10 15:29:00 2009 rc=1
>  CMD: /usr/lib/sa/sa1
>  sys 28596 c Sun May 10 15:30:00 2009
>  CMD: ksh /sla/prod/ftp_data/bin/checkftp.sh 1> /sla/prod/ftp_data/logs/cronlo
g 2>/sla/prod/ftp_data/logs/cronerr
>  FTPFRS 28597 c Sun May 10 15:30:00 2009
>  CMD: /var/tmp/tempcap.sh
>  root 28598 c Sun May 10 15:30:01 2009
<  sys 28596 c Sun May 10 15:30:01 2009
<  root 28598 c Sun May 10 15:30:01 2009
<  FTPFRS 28597 c Sun May 10 15:30:01 2009
>  CMD: /var/tmp/tempcap.sh
>  root 28648 c Sun May 10 15:31:00 2009
<  root 28648 c Sun May 10 15:31:00 2009
>  CMD: /var/tmp/tempcap.sh
>  root 28704 c Sun May 10 15:32:00 2009
<  root 28704 c Sun May 10 15:32:00 2009
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 290 total points
ID: 24347165
can you change it to

echo ======== >> /backup/tempcap.o
/usr/platform/`uname -m`/sbin/prtdiag -v | /usr/bin/grep -i ambie >> /backup/tempcap.o
/usr/bin/date >> /backup/tempcap.o
0
 
LVL 22

Assisted Solution

by:blu
blu earned 20 total points
ID: 24349023
I'm sorry, I am a bit confused about what you actually get. Are  you saying that after it runs, the content of
the /backup/tempcap.o file actually has some kind of "rm.." command in it? Could you post the actual output you get in the file as an attachment here?

Do you get any output from the job in a cron output mail message?
0
 
LVL 1

Assisted Solution

by:whiteonline
whiteonline earned 80 total points
ID: 24349030
Also, please provide the crontab for the user which is having the issue.
0
 

Author Comment

by:sunhux
ID: 24356420
Thanks a lot for chipping in, guys.

Basically the command in (a) works in the script when executed
at Unix command prompt but when it's embedded in a Shell script
& the Shell script is executed by cron, it did not work :

a) prtdiag -v | grep -i ambie >> /backup/tempcap.o

What Omar gave in (b) below to replace line in (a) above fixed the problem :
b) /usr/platform/`uname -m`/sbin/prtdiag -v | /usr/bin/grep -i ambie >> /backup/tempcap.o
0
 
LVL 1

Expert Comment

by:whiteonline
ID: 24356509
Good catch, Omar.
The reason for this is because the PATH environment variable was not the same under cron as it was when you were logged in (why you had to specify the full path to each program).

In the future, it helps to make a file that sets these particular variables and source it in the crontab prior to running your actual job.
ie.
* * * * * . /path/to/set_env_file; /var/tmp/temperature_script.sh
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24356948
if you see my comment no. 24342622 above you will see the 3 things you need to take care of when writing script to run as crontab job
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Agile (http://en.wikipedia.org/wiki/Agile_software_development), time and again people ask this question "How would you estimate a release for a product?". When it comes from management they want to know the following: Calculate the man hours wh…
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Starting up a Project

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question