Script for updates
I mistakingly posted in the wrong place, so I am posting it here as it is programming.
I am trying to automate yum update of specific package on a remote machine. Essentially, the script executes, does a yum update, if not needed it would return echo result "update successful", if it needs the update and it installs it without error, it will return echo result "update successful", or if it fails the update it would echo "update failed". So far I have this: #!/bin/bash # Update my system if ! yum update w3m then failure=1 fi if [ $failure ] then echo "Could not update system." >&2 exit 1 fi echo "Update successful" exit 0 The script runs fine and shows: Loading "installonlyn" plugin Loading "security" plugin Loading "rhnplugin" plugin This system is not registered with RHN. RHN support will be disabled. Setting up Update Process Setting up repositories Reading repository metadata in from local files Skipping security plugin, no data Could not find update match for w3m No Packages marked for Update/Obsoletion Update successful This is OK, but I NEED it to just return the final echo "Update successful". I can't have all the other lines. How can I do this? I was thinking of stdout somehow but have had absolutely no luck in doing that for 2 days now. So, I need some help. Thanks for all the help! |
Hi,
how about redirecting stdout and stderr to /dev/null ? Code:
yum update w3m &> /dev/null |
Also, unless this is only a portion of the script and you are using the failure variable later, why not just use the first if to produce your echo statements?
You also have an exit call in your failure if but this script is not failing. |
All times are GMT -5. The time now is 12:56 PM. |