Operating System - HP-UX
1837896 Members
3351 Online
110122 Solutions
New Discussion

Re: Nested if statement help

 
SOLVED
Go to solution
steven Burgess_2
Honored Contributor

Nested if statement help

Hi everyone.

Currently implementing UniQ , upgrade from openspool. Problem is when attempting to remsh and pass print to another server that may or may not be running UniQ

Usual scenario , I have to ammend a script written some time ago in a galaxy.......

I need to check the status of an error code before performing a set of commands. I need then to perform an action depending on the status code of the last command etc etc

Have a look and see if you can see what is wrong with what I have up to now

# Check to see if the host is running UniQ

remsh $host -n 'ps -ef | grep uq | grep -v grep'

if [[ $? != 0 ]]
then
this_host=$(hostname)
title="remote print from $this_host to $QUEUE@$host via $host_path user $user"
command="np -q$QUEUE -boff $form $font $opts -T'$title' $name"
command="remsh $host -l remprt $command"
output=$($command 2>&1)
status=$?
if [[ $status != 0 ]]
then
ERROR="MSG: remprt failed [$status]\nCOMMAND: $command\nOUTPUT: $output"
error_routine
fi

# If the host is running UniQ then source the setup

else

this_host=$(hostname)
title="remote print from $this_host to $QUEUE@$host via $host_path user $user"
command="np -q$QUEUE -boff $form $font $opts -T'$title' $name"
command="remsh $host -l remprt '. /usr/UniQ/print/setup;$command'
output=$($command 2>&1)
status=$?
if [[ $status != 0 ]]
then
ERROR="MSG: remprt failed [$status]\nCOMMAND: $command\nOUTPUT: $output"
error_routine

fi
fi

Any help appreciated. Thanks in advance

Steve

take your time and think things through
3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: Nested if statement help


You are missing an ENDING quote (") on this line:

command="remsh $host -l remprt '. /usr/UniQ/print/setup;$command'


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Nested if statement help

How about sprucing it up a little?


remsh $host -n 'ps -ef | grep uq | grep -v grep'
errchk=$?
#
this_host=$(hostname)
title="remote print from $this_host to $QUEUE@$host via $host_path user $user"
command="np -q$QUEUE -boff $form $font $opts -T'$title' $name"
#
# did remsh work?
#
if [[ $errchk != 0 ]]
then
command="remsh $host -l remprt $command"
output=$($command 2>&1)
status=$?
else
command="remsh $host -l remprt '. /usr/UniQ/print/setup;$command'"
output=$($command 2>&1)
status=$?
fi
#
# check error status
#
if [[ $status != 0 ]]
then
ERROR="MSG: remprt failed [$status]\nCOMMAND: $command\nOUTPUT: $output"
error_routine
fi



live free or die
harry
Live Free or Die
steven Burgess_2
Honored Contributor

Re: Nested if statement help

Harry

Thanks for spotting that mate. Really appreciated

Thanks again

Steve
take your time and think things through