LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-10-2002, 12:18 PM   #1
mounters
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,
Cheers
Chris
 
Old 02-10-2002, 09:36 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Here is what you asked for:
Code:
for i in `cat filename`; do
   echo "hello dude" | write $i
done
Here is a bit more:
Code:
#!/bin/sh

PROCESS="netscape"
LOG_FILE="/tmp/slackusers"

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

IFS=":"
for SLACK_USER_PID in $USER_PID_LIST; do
   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
done

Last edited by crabboy; 02-10-2002 at 09:38 PM.
 
Old 02-11-2002, 11:49 AM   #3
Malicious
Member
 
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.
http://home.netscape.com/newsref/std/x-remote.html
 
Old 02-11-2002, 04:57 PM   #4
mounters
LQ Newbie
 
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Original Poster
Rep: Reputation: 0
Talking

Cheers for the help. Very useful.

Chris
 
  


Reply


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

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

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