LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-08-2005, 08:05 PM   #1
moodupani
LQ Newbie
 
Registered: Aug 2005
Posts: 12

Rep: Reputation: 0
Need help for bash script


Hi,
can some ppl test and tell me if this is correct ans? pls..
my linux soft. is giving trouble.

whats wrong with this script?

thanks




Ques. Write a bash script that kills all the processes executing a certain command at a certain moment in time. For example, kill all processes running mail. Unless you have a super user privilege, you can kill only your own processes.

Ans:

#!/bin/sh

kill `ps -ef | grep $1 | awk '{ print $2 }'`
 
Old 09-08-2005, 08:20 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Homework. Again.

Can someone wield the ban-stick on this guy?
 
Old 09-08-2005, 08:28 PM   #3
tassinari
LQ Newbie
 
Registered: Mar 2005
Location: Waltham, MA
Distribution: SUSE 9.1
Posts: 15

Rep: Reputation: 0
Maybe put in a loop to kill each individual process? Otherwise you are sending a list of all the processes to kill at once.

#!/bin/bash
for x in `ps -ef|grep $1|awk '{print $2;}'`
do
kill $x;
done
 
Old 09-08-2005, 08:36 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Grab killall dude. :-P

And do some research.
 
Old 09-08-2005, 09:22 PM   #5
moodupani
LQ Newbie
 
Registered: Aug 2005
Posts: 12

Original Poster
Rep: Reputation: 0
to tassinari

hi
could u pls test ur ans and give let me know pls.

thanks
 
Old 09-08-2005, 09:25 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Test my answer? Look at the killall utility. We're not a service here. Especially when it's obviously just a homework assignment.
 
Old 09-09-2005, 03:59 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
xargs is good for this too.

you have enough clues now to work it out
 
  


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
Bash Script zaicheke Programming 3 11-07-2004 06:32 PM
bash script how to? Lleb_KCir Programming 11 05-21-2004 07:03 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

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

All times are GMT -5. The time now is 12:26 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