using killall command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using killall command
# 1  
Old 05-18-2006
Question using killall command

hi all...
I investigate if exists some script so that when unix run an application (in this case backup's), so after of that does run killall command to all users connected, or if it is possible to be put in crontab...
I wait for and they help me so I do not have much knowledge in programming....
thank you....
# 2  
Old 05-18-2006
This is a dangerous script and not really recommended. Make sure you know what you are doing.

I will stick my head out, but claim not responsibility for any damage cause.

The following script is not what you want, but will demonstrate the idea. Do NOT run it as is.

ps -ef |grep "$1" | egrep -v "root|daemon|oracle" > tmpfile
A=`cut -c10-14 tmpfile`
for i in $A
do
echo $i
# kill -9 $i
done

It accepts one parameter (could be the user name etc....) and controlled by the grep "$1" command (if you remove it all processes will be considered).

the egrep is just to ensure we do not kill anything important, in our case root, daemon and oracle processes. You should examine your system and see what else needs to be filtered.

Test your script completely before removing # on the kill. Better be safe than sorry.
# 3  
Old 05-19-2006
killall typically kill processes by name, so instead of doing "ps -ef |grep process; kill <process id>", you can "killall process". However, it's called killall because it will kill all that matches the name.

Now, after that, what are you trying to accomplish? It /looks/ like you're trying to run your backup, then terminate all of the shell sessions on the server, but I'm not sure. I would discourage the use of "kill -9" on a shell or process unless you need to. If you want to get rid of users, why not use SIGHUP (kill -1 <pid>) - that's what it was more or less meant to do (oh, the user hung up... let's let the children know)

More information will give you a more accurate reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

2. Fedora

Understanding Killall command , wait option

:wall:killall -wHi i need to understand how the -w option works in terms of processes. If this command is issued does it literally terminate all running processes ..wait for them all to be terminated and then return to standard output ? Thanks in advance (2 Replies)
Discussion started by: MrRobot
2 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

5. Shell Programming and Scripting

Suppressing the terminated message from pkill & killall commands in a bash script

Hi all, I've been pulling my hair out with this problem for 3 days:wall: now without success any help would be massively appreciated. Basically the script is used to shutdown a rails server so a new IP address can be assigned, the shutdown part is taken care of in function_one using the... (2 Replies)
Discussion started by: danmc
2 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. Shell Programming and Scripting

Verifying killall command usage

killall -KILL rdiff-backup Is it a valid command coz i couldn't find a -KILL option for killall in the man page. (1 Reply)
Discussion started by: proactiveaditya
1 Replies

8. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

9. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies

10. Shell Programming and Scripting

Killall script?

I am doing some system tuning and figuring out how to write a script that will kill multiple processes or all processes with the same owner. Can someone help me out? Thanks (5 Replies)
Discussion started by: nmajin
5 Replies
Login or Register to Ask a Question