LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-01-2011, 01:09 AM   #1
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Rep: Reputation: Disabled
Bash shell scripting help ! RPM packages


Can someone help me write a bash script

- Accepts a single argument of an RPM package name
- Displays an error message if the user does not specify an argument and terminates
- Displays an error message if the service is not found and terminates
- Displays ONLY the description text for the RPM package
- Displays the boot status of any services installed by the package using the chkconfig command (Hint: services are identified by those files installed in the directory /etc/init.d)


can use any RPM package most found in linux

Last edited by gremlin007; 06-01-2011 at 01:12 AM. Reason: formatting
 
Old 06-01-2011, 01:13 AM   #2
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,247

Rep: Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128
Smells like homework!

Please try address each point one at a time and then come post back explaining what you have tried and what the problem is.

Cheers,

Evo2.
 
1 members found this post helpful.
Old 06-01-2011, 01:16 AM   #3
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Smells like homework!

Please try address each point one at a time and then come post back explaining what you have tried and what the problem is.

Cheers,

Evo2.
Well im new to this all

so far i have

#!/bin/bash
# rpm -q package_name

how do i manage error handling

and display only DESCRIPTION ?

# rpm -qi ( shows all the information)
 
Old 06-01-2011, 01:17 AM   #4
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Quote:
Originally Posted by evo2 View Post
Smells like homework!

Please try address each point one at a time and then come post back explaining what you have tried and what the problem is.

Cheers,

Evo2.
You just beat me to it. +1 to that.... These forums are for help and assistance, not to hire people to do your homework for you. If it is not homework, than please give us proof, and also what you have done so far, just like evo said.

Cheers,

Josh
 
1 members found this post helpful.
Old 06-01-2011, 01:18 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Try these links:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://kbase.redhat.com/faq/docs/DOC-2531
 
Old 06-01-2011, 01:19 AM   #6
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
thanks

appreciate it ... just i've only done basic shell work , not dealt with advanced bash scripting
some of you guys are very rude
 
Old 06-01-2011, 01:24 AM   #7
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
and display only DESCRIPTION ?

# rpm -qi ( shows all the information)

whats the command to show only description ?
 
Old 06-01-2011, 01:36 AM   #8
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,247

Rep: Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128
Quote:
Originally Posted by gremlin007 View Post
and display only DESCRIPTION ?

# rpm -qi ( shows all the information)

whats the command to show only description ?
It's in the rpm man page but may be a little hard for you to find or understand.
You need to use the --queryformat option.

I'll give you this one for free:
Code:
rpm -q --queryformat '%{description}' package_name
Evo2.
 
1 members found this post helpful.
Old 06-01-2011, 01:38 AM   #9
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
I wasn't being rude, I didn't see the post before mine...................

And as far as seeing only the description, I just came out with the following snippet:
Code:
rpm -qi NetworkManager | cut -f6 -d ":" | tr -s "\n"
Dirty, but it works

Edit - I hope you don't give me more negative rep for that

Last edited by corp769; 06-01-2011 at 01:39 AM.
 
1 members found this post helpful.
Old 06-01-2011, 01:43 AM   #10
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
oh soory man

now for the first bit

accepts a single argument

would that be something like

#!/bin/bash
# rpm -q package_name


or am i on the wrong track ?
 
Old 06-01-2011, 01:48 AM   #11
corp769
Guru
 
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Yes, you are getting there man.
Code:
#!/bin/bash
var1=$1
rpm -qi $var1 | cut -f6 -d ":" | tr -s "\n"
Notice how I used $1 to declare var1; $0 would return the name of the script you are running. Read over those links that were posted before, they will contain more information about it.

Cheers!

Last edited by corp769; 06-01-2011 at 01:49 AM.
 
Old 06-01-2011, 01:49 AM   #12
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,247

Rep: Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128
Arguments to bash scripts are referenced as integers. For example "$1" would be the first argument, "$2" the second and so on.

Evo2.
 
Old 06-01-2011, 02:01 AM   #13
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
so hang on is this wrong ?
Code:
#!/bin/bash
# rpm -q package_name
and should it be like this

Code:
#!/bin/bash
# rpm -q package_name
# var1=$0
# rpm -q --queryformat '%{description}' $var1

Last edited by gremlin007; 06-01-2011 at 02:01 AM. Reason: formatting
 
Old 06-01-2011, 02:03 AM   #14
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,247

Rep: Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128Reputation: 1128
As corp769 pointed out $0 is the name of the script, presumably you want the first argument which is $1.

Evo2.
 
Old 06-01-2011, 02:04 AM   #15
gremlin007
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
so

Code:
#!/bin/bash
# rpm -q package_name
# var1=$1
# rpm -q --queryformat '%{description}' $var1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash shell scripting help! computergeek7 Programming 2 04-27-2010 10:35 AM
Bash Shell scripting help! computergeek7 Programming 2 03-01-2010 05:55 AM
My first bash at shell scripting (sorry...) Daws Linux - Newbie 5 03-21-2007 06:20 PM
some bash shell scripting eltongeoff Linux - Newbie 2 10-22-2003 01:10 PM
Bash Shell Scripting Help Tangerine Programming 6 05-06-2003 02:10 PM


All times are GMT -5. The time now is 12:06 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration