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....

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.

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.