1830061 Members
2937 Online
109998 Solutions
New Discussion

Script Question

 
Hunki
Super Advisor

Script Question

The attached script is failing on hosta while runs fine on hostb.

The set -x output on hosta gives the following output :

+ + date +%G-%m-%d
cdate=2007-02-19
+ + date +%H
chour=10
+ + date +%M
cmin=56
+ dated=2007-02-19_1056
+ uname -n
+ [ hosta = hostb ]

and comes back to the command prompt . The shell is ksh. Please help.
5 REPLIES 5
Sandman!
Honored Contributor

Re: Script Question

To troubleshoot this issue could you execute the following script on hosta and post the output here:

#!/usr/bin/ksh -x

if [ `uname -n` = hostb ]
then
echo "not on hosta"
else
echo "on hosta"
fi
Hunki
Super Advisor

Re: Script Question

+ uname -n
+ [ hosta = hostb ]
+ echo on hosta
on hosta
Sandman!
Honored Contributor

Re: Script Question

Try to break down the script into smaller parts in order to isolate the problem. Look inside the block of statements that get executed if the condition is true; do the same for the commands that get executed when the condition is false.

~hope it helps
Sandman!
Honored Contributor

Re: Script Question

Run the attached script and post the output of the set -x run. I inserted echo commands to aid in troubleshooting.

~cheers
Arturo Galbiati
Esteemed Contributor

Re: Script Question

Hi,
try:
if [[ $(uname -n) = hostb ]]

the improvment is using double [.
The $() is only good practice.

HTH,
Art