I wrote a ksh program which run scripts from remote server.
To check the status code I wrote the following function:
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:
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
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
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