I have a Shell script that handles Satellite server and Redhat IDM registrations. I don't have rights to update the script. The -i argument in the command below is for IDM registration and -s for Satellite server registration.
/usr/local/sbin/new-clone.sh -i aws -s aws-prod
Error handling is done as follows: Satellite registration:
if [ "${RETURN_VALUE}" -ne 0 ]; then
echo -e "\n\nSatellite registration failed. Please correct and re-run this script.\n\n"
exit 2
fi
IDM registration:
idm_failed ()
{
echo -e "\n- IDM registration failed to $1. This script did not complete. Please check network connection between this system and $1 servers. Re-run this script after troubleshooting. Exiting.."
exit 2
}
I am executing the Shell script from Python as follows.
The server.execute_script
command is proprietary to a COTS application.
registration_command = "/usr/local/sbin/new-clone.sh -i aws -s aws-pro"
join_script = """#!/bin/bash
{}
yum clean all
yum -y upgrade
systemctl reboot && exit 0
""".format(registration_command)
try:
server.execute_script(script_contents=join_script, runas_username='ec2-user', run_with_sudo=True,timeout=1200)
except:
logger.info('Failed with SEC satellite or IDM')
I want to update the logic in this try-catch statement so that it's more specific to whether the issue was with IDM registration or the Satellite registration. Since both these functions have a return code of 2, I was wondering it's possible to use the output of the echo command to implement. I would love to hear from the community on what makes sense here.
Please stay safe and be kind.