The first command you want to know is yum check-update. If you are not familiar with yum, read our primer on yum first and then come back here. The check-update command will print out a list of any packages for which an update is available. For scripting purposes it will also return an exit value of 100 if updates are required, 0 if no updates are required or 1 if an error occurred.
Here is an example of how to check for updates in CentOS:
RC=$?
if [ $RC -eq 100 ]; then
echo "Updates are needed"
elif [ $RC -eq 0 ]; then
echo "No updates are needed"
else
echo "An error occurred in the package update check, try again"
fi
And here is an example of printing out the updates as needed:
RC=$?
if [ $RC -eq 100 ]; then
cat ./output
fi
We can also check updates for a single package with yum update and NOT specifying Y, for yes, when asked. If you do press Y, for yes, the update will proceed for the specified package. For example I will do a check on the package vim-minimal now:
If you want to proceed and update all packages, then go ahead and run yum update and do not provide any package names. It will find all out of date packages and update them all after you confirm Y for yes at the prompt.
After the update is complete you can re-run the check script above and expect to see nothing to update.
RC=$?
if [ $RC -eq 100 ]; then
echo "Updates are needed"
elif [ $RC -eq 0 ]; then
echo "No updates are needed"
else
echo "An error occurred in the package update check, try again"
fi
Conclusion
Its important to keep your CentOS system up to date. You can use the above methodology to help.