Results 1 to 8 of 8
I'm pretty new to linux, but I know a bit of programming (Python and C++) and I'm no stranger to the command line.
There is a program that comes with ...
- 02-09-2008 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 3
Monitoring for a remote process
I'm pretty new to linux, but I know a bit of programming (Python and C++) and I'm no stranger to the command line.
There is a program that comes with linux called xeyes. You all know about it, and you know you can run it on another person's machine. Some guys found this program at work... It started getting annoying, so (with a tech guy's help) I wrote a python script that checked for xeyes using xlsclients and displayed the host of the process. However, my coworkers caught on quick and now kill the process seconds after scaring the CRAP out of me.
That said, I'm looking for a way to create an efficient background task that will monitor for xeyes, preferably in Python so I can just extend my current script.
- 02-09-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
- 02-09-2008 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 3
I just have no idea how to create the monitoring process in the first place.
Unfortunately I don't have root access on this network, so that won't work.
However, I can kill the process on my computer using xkill. That's why I use xlsclients, so I can get the correct ID to shut it down. The program still remains "running" on the assailant's machine, but it doesn't display on my machine anymore.Last edited by tbttfox; 02-09-2008 at 04:24 PM. Reason: clarification
- 02-09-2008 #4
Wont this work?
Code:#!/bin/bash while true ; do check=`ps aux | grep -c xeyes` if [ $check -ge 2 ] ; then killall xeyes sleep 1 fi doneCan't tell an OS by it's GUI
- 02-09-2008 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 3
I'm sure that will most definitely work, and it is similar to my initial plan. I just thought it wise to check the hive mind to make sure there wasn't a better way, like checking for some magic OS call that says "I just started a new program" so I didn't have to run an infinite loop over grep, even if it was controlled.
So, if there are any other ways anybody knows off the top of their head, I would love to see them.
Thanks much for the suggestion!
- 09-16-2008 #6
In reference to above code
I want to check whether
specified process is running or not?
So I wrote like this
#!/bin/bash
while true ; do
check=`ps aux | grep -c xeyes`
echo "check = $check\n"
if [ "$check" -lt 2 ]; then
echo "$check isn't running\n"
else
echo "$check is running\n"
fi
sleep 2
done
But it gives value of check
sometimes 1
and sometimes 2
why this happening
where
at commandline
$ ps aux | grep -c xeyes
it gives always two when process in running
can't understand, why it is so?
- 09-16-2008 #7
I dunno??
It works on my machine. It gives a value of 2 when it's running, and 1 if it's not. That 1 is grep finding it's own query of 'grep xeyes', so that is to be expected.
So no I have no idea. When I copy&paste your code in my machine, it just works.Can't tell an OS by it's GUI
- 09-17-2008 #8
after reading manual for ps
"ps aux | grep -c pidgin"
ps displays status information of all active processes
so it displays 2 process are running with provided name (ex. pidgin)
1 is actual process "pidgin" itself
and another is "ps aux | grep -c pidgin"
which contain pidgin as parameter
so what was happening there
grep cuts output of ps aux by two lines
and with -c options line count is 2
when script was running the command "ps aux | grep -c pidgin"
then the count was 2
but sometimes if process (by the command "ps aux | grep -c pidgin")
goes out from memory
after execution completion
it was showing 1 when
it may happening sometimes
process remains in memory
and giving count 2
I tried it at home
my pc is also giving me 2 always
but in company it is varing 1 or 2
I think speed of my pc is less
process still remains in memory always
and showing 2 always
I tried for 'top'
it works more perfect than 'ps'
code is like this now
#!/bin/bash
while true ; do
check=`top -n 1 | grep -c ctpmServer`
echo "check = $check\n"
if [ "$check" -lt 1 ]; then
echo "$check isn't running\n"
else
echo "$check is running\n"
fi
sleep 1
done


Reply With Quote
