1844929 Members
1458 Online
110233 Solutions
New Discussion

Script help needed

 
SOLVED
Go to solution
Craig A. Sharp
Super Advisor

Script help needed

Hi all,

I am running the following script from cron:

set -x
host=`hostname`
if [ $host = "db05461" -o $host = "dbumegan" ]
then
tapeid=`/usr/sbin/mc -r DS | grep DT_slot_1 | awk '{print $3}'`
fi
echo $tapeid

Here is the data that the script is looking at:

#mc -r DS
DT_slot_1 FULL W2T004
DT_slot_2 EMPTY
ST_slot_1 FULL W2T001
ST_slot_2 FULL W2T002
ST_slot_3 FULL W2T003
ST_slot_4 FULL W2T004
ST_slot_5 FULL W2T005
ST_slot_6 FULL W2T001
ST_slot_7 FULL W2T002
ST_slot_8 FULL W2T003
ST_slot_9 EMPTY
ST_slot_10 FULL W2T005
ST_slot_11 FULL W2T001
ST_slot_12 FULL W2T002
ST_slot_13 FULL W2T003
ST_slot_14 FULL W2T004
ST_slot_15 FULL W2T005
ST_slot_16 EMPTY
ST_slot_17 EMPTY
ST_slot_18 EMPTY
ST_slot_19 EMPTY

Now here is the problem. If I run the script manually from a prompt, it works correctly and tapeid gets the correct value (W2T004).

+ + hostname
host=db05461
+ [ db05461 = db05461 -o db05461 = dbumegan ]
+ + /usr/sbin/mc -r DS
+ awk {print $3}
+ grep DT_slot_1
tapeid=W2T004
+ echo W2T004
W2T004

When I run from cron, the script gives me the following error in the log file (tapeid gets no value):

+ + hostname
host=db05461
+ [ db05461 = db05461 -o db05461 = dbumegan ]
+ + grep DT_slot_1
+ awk {print $3}
+ /usr/sbin/mc -r DS
ERROR: No such file or directory
tapeid=
+ echo

I am completely stumped. What is going wrong?

Thanks,

Craig
8 REPLIES 8
Ian Dennison_1
Honored Contributor

Re: Script help needed

The first line of commands (After the #!/usr/bin/sh) should be '. /.profile'. (Or whatever profile for the user you are running it as!)

'mc' command must require something set inside either the PATH or environment variables, which 'cron' will not do by default.

Share and Enjoy! Ian
Building a dumber user
Uday_S_Ankolekar
Honored Contributor

Re: Script help needed

While running from cron are you giving entire path? If not try it in that way.
It's probably because the PATH variable is not set in the cronjob

-USA..
Good Luck..
Wilfred Chau_1
Respected Contributor

Re: Script help needed

add PATH=PATH:/usr/bin to your script

and try running in cron again.

cron didn't use profile and hence may not have all the paths available.
Pete Randall
Outstanding Contributor

Re: Script help needed

export PATH=$PATH:/usr/bin might be better. Better yet, try

export PATH=`cat /etc/PATH`

Pete

Pete
James Odak
Valued Contributor

Re: Script help needed

when writing scripts for cron or remote execution always set the PATH var or fully path ever command
mean instead of grep do /usr/bin/grep and for awk /usr/bin/awk

if you do not know the run path for a command use the whereis command
example
whereis awk
awk: /sbin/awk /usr/bin/awk /usr/share/man/man1.Z/awk.1
Tom Jackson
Valued Contributor
Solution

Re: Script help needed

Hi Craig:

I need to add the option "-p /dev/rac/c2t0d0" to the mc command to get the output you are showing.

hth,

Tom
Pete Randall
Outstanding Contributor

Re: Script help needed

It's interesting that the order of the commands seems to be reversed in the cron example - is that actually how it appears?

Pursuing the no such file or directory angle, this seems to be coming from the mc command, and the only file mc uses is /dev/scsi/3.

Try adding /dev/scsi into your PATH.

Pete

Pete
Craig A. Sharp
Super Advisor

Re: Script help needed

Got it!

The fix was the -p switch in the mc command.

Thanks to all for your excellent replies.

Craig