Failed to check status code in "rsh" command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Failed to check status code in "rsh" command
# 1  
Old 07-01-2006
Failed to check status code in "rsh" command

Hi folks,

I wrote a ksh program which run scripts from remote server.
To check the status code I wrote the following function:


Code:
check_remote_status()
{
status_code=`tail -1 $installLog`
if [[ ${status_code} -ne 0 ]] ; then
  echo $errMsg | tee -a $installLog
  exit 1
else
  echo $validMsg >> $installLog
fi
}

The main function is:

Code:
run_install_sr()
{
cat ${CONF_FILE} | grep INSTALL_SR_ | grep :Y | while read line
do
  INSTALL_SR_DIR=`echo $line | cut -d= -f2 | cut -d: -f1`
  errMsg="ERROR: Failed to copy ${RESPONSE_FILE_SR} to ${DB_HOST_NAME}!"
  validMsg="-> VALID: ${RESPONSE_FILE_SR} was copied to ${DB_HOST_NAME}."
  rcp ${RESPONSE_FILE_SR} ${DB_HOST_NAME}:/tmp >> $installLog
  check_remote_status

  errMsg="ERROR: Failed to run SR database layer!"
  validMsg="-> VALID: SR Database layer completed successfully."
  rsh ${DB_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESONSE_FILE_SR##*/} -l database"'; echo $?"' | tee -a $installLog
  check_remote_status

  errMsg="ERROR: Failed to copy ${RESPONSE_FILE_SR} to ${ADMIN_HOST_NAME}!"
  validMsg="-> VALID: ${RESPONSE_FILE_SR} was copied to ${ADMIN_HOST_NAME}."
  rcp ${RESPONSE_FILE_SR} ${ADMIN_HOST_NAME}:/tmp >> $installLog
  check_remote_status

  errMsg="ERROR: Failed to run SR RiGHTv administration layer!"
  validMsg="-> VALID: SR RiGHTv administration layer completed successfully."
  rsh ${ADMIN_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESPONSE_FILE_SR##*/} -l administration"'; echo $?"' | tee -a $installLog
  check_remote_status

  if [[ ${RTESUB_LAYER} = 'YES' ]] && [[ ${ADMIN_LAYER} = 'YES' ]] ; then

     errMsg="ERROR: Failed to copy ${RESPONSE_FILE_SR} to ${RTESUB_HOST_NAME}!"
     validMsg="-> VALID: ${RESPONSE_FILE_SR} was copied to ${RTESUB_HOST_NAME}."
     rcp ${RESPONSE_FILE_SR} ${RTESUB_HOST_NAME}:/tmp >> $installLog
     check_remote_status

     errMsg="ERROR: Failed to run SR RTE subscriber layer!"
     validMsg="-> VALID: SR RTE subscriber layer completed successfully."
     rsh ${RTESUB_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESPONSE_FILE_SR##*/} -l subscriber"'; echo $?"' | tee -a $installLog
     check_remote_status
  fi
done
}

When the program call to check_remote_status function ,I get the following error message to the screen:
E.g:
./RiGHTvInstaller.ksh[2]: -> VALID: SR RiGHTv administration layer completed successfully.: syntax error

Any ideas why?

Thanks in advance,
Nir
# 2  
Old 07-01-2006
Normally there are two status "things" to check for remsh and rsh.
Your method will work if the remote script were to echo $? a different way, like this:
My example is remsh, but it doesn't matter
Code:
rc=$(remsh somenode "A really long comand && echo 'OKAY'")
status=$?
if [[ $status -eq 0 ]]    # remsh command successful, now get remsh rc...
        then
            if [[ `echo "$rc" | grep -q '^OKAY$'` -eq 0 ]]
            then
                echo " all is well"
            else
                echo "remote failure"
            fi
else
     echo "local failure: remsh"
fi


Last edited by jim mcnamara; 07-01-2006 at 05:24 PM..
# 3  
Old 07-01-2006
Hi Jim,

Thanks!
I'll test your suggestion.

Best regards,
Nir
# 4  
Old 07-02-2006
Hi Jim,

I wrote a small program:
Code:
#! /bin/ksh

CONF_FILE=nir.conf
export $(< $CONF_FILE)
run_install_sr()
{
nawk -F'[=:]' '$1 ~ "^INSTALL_SR_" && $NF = "Y" {print $2}' "${CONF_FILE}" | while read INSTALL_SR_DIR
do
  echo Install SR directory is $INSTALL_SR_DIR
  rc=$(rsh ${DB_HOST_NAME} hostname && echo OKAY)
status=$?
if [[ $status -eq 0 ]]    # remsh command successful, now get remsh rc...
        then
            if [[ echo "$rc" | grep -q '^OKAY$' ]]
            then
                echo " all is well"
            else
                echo "remote failure"
            fi
else
     echo "local failure: remsh"
fi

done
}
run_install_sr

I ran it :

Code:
buffy> ./nir.ksh
./nir.ksh[5]: syntax error at line 14 : `"$rc"' unexpected

And as you can see ,I failed.

I'll be glad to get your help again.

Thanks in advance,
Nir
# 5  
Old 07-03-2006
nir_s, I think that you have the syntax wrong there. Replace
Code:
if [[ echo "$rc" | grep -q '^OKAY$' ]]

with
Code:
if [[ "$rc" == 'OKAY' ]]

# 6  
Old 07-03-2006
Thanks pal but now I'm getting another syntax error:

Code:
./nir.ksh[5]: rc=${rsh ${DB_HOST_NAME} hostname && echo OKAY}: bad substitution

# 7  
Old 07-03-2006
Shouldn't it be

Code:
rc=$(rsh ${DB_HOST_NAME} hostname && echo OKAY)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

5. UNIX for Dummies Questions & Answers

Unable to use the Sudo command. "0509-130 Symbol resolution failed for sudo because:"

Hi! I'm very new to unix, so please keep that in mind with the level of language used if you choose to help :D Thanks! When attempting to use sudo on and AIX machine with oslevel 5.1.0.0, I get the following error: exec(): 0509-036 Cannot load program sudo because of the following errors:... (1 Reply)
Discussion started by: Chloe123
1 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

9. UNIX for Dummies Questions & Answers

Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error mes

I would like to know what means this error and how to fix it Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error message Thank you (3 Replies)
Discussion started by: linuxbee
3 Replies

10. Shell Programming and Scripting

check input = "empty" and "numeric"

Hi how to check input is "empty" and "numeric" in ksh? e.g: ./myscript.ksh k output show: invalid number input ./myscript.ksh output show: no input ./myscript.ksh 10 output show: input is numeric (6 Replies)
Discussion started by: geoffry
6 Replies
Login or Register to Ask a Question