Operating System - HP-UX
1828481 Members
3562 Online
109978 Solutions
New Discussion

Script problem Please help !

 
Kenn Chen
Advisor

Script problem Please help !

I have write following scritp to retrieve some data from omstat command. It work fine when I run it manually (output : 12:57:35 1133). But when I schedule crontab (* 8-18 * * * /home/user.ksh) it output only the time only without show the quantity. WHY ??

Script file contents:-

#! /bin/ksh

cd /home
clear

count=`omstat -s |grep Remote |awk '{print $6}'`
time=`date|awk '{print $4}'`

echo ""$time"\t"$count"" >> user.txt

=============================================
Cyber Zen
5 REPLIES 5
Frank Li
Trusted Contributor

Re: Script problem Please help !

Because when Cron run , it does't the environment ( especially the PATH), so you should use the command with the absolute path .

One more thing , cron is always run in "sh".
Hi Friend
Tim D Fulford
Honored Contributor

Re: Script problem Please help !

You could get your environment variables in relatively easily by sourcing your .profile

eg add near the top of your script

. /.profile

Tim
-
Praveen Bezawada
Respected Contributor

Re: Script problem Please help !

Hi
When run in cron the goodies like PATH etc are not set.
Cron does not login so the all the setting need to be specially set.

PRB
Victor_5
Trusted Contributor

Re: Script problem Please help !

Always use full path names for your commands and file names, since cron uses only the standard environment of /usr/bin/sh and does not know about your environment, for example, your current directory, variables and PATH. By default, crontab opens the user's own cron file. Check your ~/.profile.
someone_4
Honored Contributor