Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-10-2002, 01:18 PM   #1
LQ Newbie
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Rep: Reputation: 0
Question BASH script inform user and kill process

I am attempting to write a shell script which will find all instances of netscape running on the system and then send a message to every user who is running a netscape session and then kill all the netscape sessions.

I can do the kill easily, and can get all the users of netscape, currently this is pulled into a file through the use of grep and awk. I have been trying to do something with write or wall but can't figure out how to get the loop to pull the user out of the file and send the message to them.

Any help would be most appreciated,
Old 02-10-2002, 10:36 PM   #2
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Here is what you asked for:
for i in `cat filename`; do
   echo "hello dude" | write $i
Here is a bit more:


USER_PID_LIST=`ps -ef | grep $PROCESS \
                                       | grep -v "grep"  \
                             | awk ' { printf( "%s=%s:", $1, $2 ); }' `

   USER_NAME=`echo $SLACK_USER_PID | cut -d'=' -f1`
   USER_PID=`echo $SLACK_USER_PID | cut -d'=' -f2`
   echo "You should be working and not surfing the Internet!" \
         | write $USER_NAME
#   kill -9 $USER_PID
   echo "Lazy ass user [$USER_NAME] was using netscape at [`date`]" >> $LOG_FILE

Last edited by crabboy; 02-10-2002 at 10:38 PM.
Old 02-11-2002, 12:49 PM   #3
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
If you are only trying to dump Netscape users, try this instead:

netscape -display x.x.x.x:0.0 -remote 'openURL(file://evilmsg.html)'.

You can get the display using "ps aew <pid>" (the w adds another display line to the ps; more than one w may be needed - ps aewwww - to get to the DISPLAY env variable). Put a little web page in evilmsg.html. This command will find the first netscape running on that display and execute that the "openURL" command and display the evilmsg. Then you can delay a few seconds and then kill'em.

See this web page for more info on what can be done.
Old 02-11-2002, 05:57 PM   #4
LQ Newbie
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Original Poster
Rep: Reputation: 0

Cheers for the help. Very useful.



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
why my script die itself when I try to kill a process?? jaimese Linux - Newbie 4 10-27-2005 06:50 AM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 09:51 AM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 10:28 PM
Kill a process launched by a shell script gsbarry Programming 7 01-06-2004 03:09 PM
script at xwin start to kill old process(es) butthead Programming 3 02-01-2002 09:39 AM

All times are GMT -5. The time now is 03:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration