LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-17-2005, 07:59 PM   #1
moodupani
LQ Newbie
 
Registered: Aug 2005
Posts: 12

Rep: Reputation: 0
Bash script help


Hi people,

I am practicing bash script.
I couldn't do this my book question.

How to do this?
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.

I would really appreciate, if someone help me.

Thanks.
 
Old 08-17-2005, 08:03 PM   #2
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
Sounds like Homework... Shame on you....!!!

KC
 
Old 08-17-2005, 10:13 PM   #3
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
You just need to think about what you need to do and write the code:

+ Somehow get a list of the processes you want (is there a command that does this?).
+ kill each of those processes.

FYI, there are actually commands on several GNU/Linux distributions that already do this. Your prof just wants to see you learning your lessons. This should be pretty simple for you. Try it, you might learn something!
 
Old 09-02-2005, 07:36 PM   #4
moodupani
LQ Newbie
 
Registered: Aug 2005
Posts: 12

Original Poster
Rep: Reputation: 0
shell script

Hi ,
I am having problem running this script.
can u fix it to correct format pls?

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.

#!/bin/sh

kill `ps -ef | grep $1 | awk '{ print $2 }'`
 
Old 09-02-2005, 10:25 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
You sure are a slow learner, eh?

Please stop asking homework questions. If you have an
approach to a solution feel free to come back and ask
for an explanation as to what you're doing wrong.

WE WON'T BE DOING YOUR WORK FOR YOU.



Cheers,
Tink
 
Old 09-02-2005, 11:43 PM   #6
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
moodupani,

I've merged your two identical homework posts. Do not repost identicial questions in separate threads in an attempt to get someone to do your homework for you.
 
Old 09-03-2005, 04:39 PM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Re: shell script

Quote:
Originally posted by moodupani
Hi ,
I am having problem running this script.
can u fix it to correct format pls?

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.

#!/bin/sh

kill `ps -ef | grep $1 | awk '{ print $2 }'`
Hint: if you're having trouble figuring out what your script is (or isn't!) doing, split it into temporary files which you can examine at your leisure to see what each part of the pipeline is doing.
Code:
ps -ef >tmp1
grep $1 <tmp1 >tmp2
awk '{print $2}' <tmp2 | tee tmp3
Now you can run your script and see exactly what each stage is producing. That should give you a clue about what you need to fix.
 
  


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 08:15 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