LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-11-2005, 12:51 AM   #1
hoffmanyew
LQ Newbie
 
Registered: Aug 2004
Posts: 23

Rep: Reputation: 15
Question bash scripts


I wanted to create a script where it will grep the service, output it into a file and kill the services as listed and print it as a log into other file.

How can i capture only the right name services as other might have the same name. For example,

ps -ef | grep vi

root 2138 1 0 09:11:41 ? 0:00 vi something1
root 2709 1072 0 09:13:16 ? 0:01 bvia
root 1511 1466 0 09:10:40 ? 0:04 asbvi

In this case, i just wanted to capture the 'vi' = vi and nothing else...... Can anyone provide a guidance or hints or anything deal with this script?

thanks
 
Old 08-11-2005, 12:55 AM   #2
hk_linux
Member
 
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
try grepping for whole words
Code:
grep -w
HTH
 
Old 08-11-2005, 01:17 AM   #3
hoffmanyew
LQ Newbie
 
Registered: Aug 2004
Posts: 23

Original Poster
Rep: Reputation: 15
thanks for reply. But in this case, it will still capture the other words contain into it i.e

root 2709 1072 0 09:13:16 ? 0:01 bvia
root 1511 1466 0 09:10:40 ? 0:04 asbvi
root 1511 1466 0 09:10:40 ? 0:04 grep -w vi

The idea is that i want to capture service listing with a spawn child which contain 'vi' and not like ivit, vite or anything.
As you can see, it will output the grep and other stuffs. Any better idea how i can capture exact service name 'vi'?

Any suggestion are fully welcome.

thank you
 
Old 08-11-2005, 01:27 AM   #4
hk_linux
Member
 
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
Sorry. I did not fully get what you are saying.

Is it something like,
you want to find a service which is running and send a kill signal to the process.?

In that case you can use "pidof" to find the pid of the process and kill it

Code:
/sbin/pidof PROCESS_NAME
 
  


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
little help with bash scripts sniff Programming 2 10-26-2005 05:17 PM
Need Help With Bash Scripts the_woelf Linux - Software 4 06-30-2004 09:09 AM
Bash Scripts Skute Programming 7 03-12-2004 10:17 AM
$? in Bash scripts clinton Linux - Newbie 4 02-20-2004 11:15 AM
Bash scripts? BajaNick Programming 3 07-05-2003 10:13 PM

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

All times are GMT -5. The time now is 01:45 PM.

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