LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2010, 02:58 PM   #1
macking
LQ Newbie
 
Registered: May 2010
Posts: 27

Rep: Reputation: 0
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!
 
Old 07-27-2010, 03:04 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

how about redirecting stdout and stderr to /dev/null ?

Code:
yum update w3m &> /dev/null
 
Old 07-27-2010, 06:35 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM
Creating a script that will check possible updates Echo Kilo Programming 12 05-14-2008 09:46 AM
script to download package updates thunyiwe Linux - Newbie 1 04-30-2008 08:06 AM
help improve my script that updates the system by cron fakie_flip Programming 1 10-08-2006 12:12 PM
need some help with script to dl mcafee updates zen0n Programming 2 10-05-2004 12:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration