1753971 Members
7816 Online
108811 Solutions
New Discussion юеВ

shell script question??

 
SOLVED
Go to solution
Penny Patch
Occasional Advisor

shell script question??

isReachable () {
commandlist="$@" ;
status="noproblem"
for command in $commandlist
do
echo "Testing $command"
location=`which $command 2>/dev/null`
echo $location
if [ "x$location" = "x" ]; then
echo
echo "*** System command \"$command\" could not be found ! ***"
echo
status="error"
fi
done
if [ "$status" = "error" ]; then
return 1;
else
return 0;
fi
}

##
# Get the OS
##
OS=`uname`

##
# Check for the presence of system commands
##
if [ "$OS" = "SunOS" ]; then
isReachable "unzip sameer /usr/ucb/ps showrev patchadd pkginfo grep find ls uname cat rm chmod ln bc hostname df
sed awk head cpio cut dc wc expr nawk uniq jar"
fi

result=$?

if [ "$result" = "1" ]; then
echo "The above listed missing command(s) are necessary.Please make sure that these commands are in the environment path."
echo " Exiting..."

On Solaris the ├в which├в command writes to standard output instead of standard error and therefore isReachable returns a 0 even when the command is not found.

Can anybody please help me solve this problem?
Thanks in adv
5 REPLIES 5
Michael Steele_2
Honored Contributor

Re: shell script question??

Hi Penny:

Could you repost the question? Last post got some garbage in it.

Thanks!
Support Fatherhood - Stop Family Law
Ron Kinner
Honored Contributor

Re: shell script question??

What does it write to the standard output if which fails? Surely something like "File not found." Can you not test for that instead of your $Status?

if [ "$Location" = "File not found." ]; then
return 1;
else
return 0;
fi


Does
whereis -b
give you a different output?

Also my manual says you need to run this in csh so I would expect you might want to add

#!/bin/csh

as the first line.


Ron
Madhu Sudhan_1
Respected Contributor
Solution

Re: shell script question??

Penny,
I think you need to check for the return code returned by isReachable function ,inside the if [ "$OS = "SunOS];
So, your script looks like,

if [ "$OS" = "SunOS" ]; then
isReachable "unzip sameer /usr/ucb/ps showrev patchadd pkginfo grep find ls uname cat rm chmod ln bc hostname df
sed awk head cpio cut dc wc expr nawk uniq jar"

result=$?

if [ "$result" = "1" ]; then
echo "The above listed missing command(s) are necessary.Please make sure that these commands are in the environment path."
echo " Exiting..."
fi

fi

-Madhu
Think Positive
Michael Schulte zur Sur
Honored Contributor

Re: shell script question??

Hi,

make these adjustments and it should run:
which $command > /tmp/check.$$ 2>&1
location=`grep -v "no ${command} in" /tmp/check.$$`

greetings,

Michael
Michael Schulte zur Sur
Honored Contributor

Re: shell script question??

Hi,

if the problem is solved, could you spare some points from the endless supply of points, HP has, for those, who could help you? ;-)

greetings,

Michael