LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash shell scripting help ! RPM packages (http://www.linuxquestions.org/questions/linux-newbie-8/bash-shell-scripting-help-rpm-packages-883871/)

gremlin007 06-01-2011 01:09 AM

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

evo2 06-01-2011 01:13 AM

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.

gremlin007 06-01-2011 01:16 AM

Quote:

Originally Posted by evo2 (Post 4372697)
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)

corp769 06-01-2011 01:17 AM

Quote:

Originally Posted by evo2 (Post 4372697)
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

chrism01 06-01-2011 01:18 AM

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

gremlin007 06-01-2011 01:19 AM

thanks :)

appreciate it ... just i've only done basic shell work , not dealt with advanced bash scripting :(
some of you guys are very rude

gremlin007 06-01-2011 01:24 AM

and display only DESCRIPTION ?

# rpm -qi ( shows all the information)

whats the command to show only description ?

evo2 06-01-2011 01:36 AM

Quote:

Originally Posted by gremlin007 (Post 4372712)
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.

corp769 06-01-2011 01:38 AM

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 :p

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

gremlin007 06-01-2011 01:43 AM

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 ? :(

corp769 06-01-2011 01:48 AM

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!

evo2 06-01-2011 01:49 AM

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

Evo2.

gremlin007 06-01-2011 02:01 AM

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


evo2 06-01-2011 02:03 AM

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

Evo2.

gremlin007 06-01-2011 02:04 AM

so

Code:

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



All times are GMT -5. The time now is 07:44 AM.