LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   "watch" command (https://www.linuxquestions.org/questions/linux-server-73/watch-command-626124/)

GiotisSL 03-06-2008 07:16 AM

"watch" command
 
hello Guys,
Can anyone help me with the "watch" command in Linux CentOS ?
I want to watch a user in my server.
I have full root access.

In FreeBSD the command is "watch -W pid#"

example:
ps aux
(the user's pid number is 1234)
# watch -W 1234


Is there a similar command in linux ?

BrianK 03-06-2008 02:22 PM

Not so similar on the command side, but similar on the result side:

watch "ps aux | grep <pid> | grep -v grep"

GiotisSL 03-07-2008 07:00 AM

I see nothing.

<<<
# ps aux
(pid# is 8558 and 8560)
# watch ps aux | grep 8558 | grep -v grep
#
[1]+ Stopped watch ps aux | grep 8558 | grep -v grep
# watch ps aux | grep 8560 | grep -v grep
#


Every 2.0s: ps aux | grep 8558 | grep -v grep Fri Mar 7 13:58:39 2008

root 8558 0.0 0.0 9008 2636 ? Ss 13:52 0:00 sshd: admin [priv]
>>>

Is there any command which I can see what a user is doing in real time ?
I mean when the user type "hello", my shell show me that the user type "hello".

BrianK 03-07-2008 04:04 PM

Quote:

Originally Posted by GiotisSL (Post 3081018)
I see nothing.

<<<
# ps aux
(pid# is 8558 and 8560)
# watch ps aux | grep 8558 | grep -v grep
#
[1]+ Stopped watch ps aux | grep 8558 | grep -v grep
# watch ps aux | grep 8560 | grep -v grep
#


Every 2.0s: ps aux | grep 8558 | grep -v grep Fri Mar 7 13:58:39 2008

root 8558 0.0 0.0 9008 2636 ? Ss 13:52 0:00 sshd: admin [priv]
>>>

quotes are important.

watch ps aux | grep 8560 | grep -v grep

is not the same as

watch "ps aux | grep 8560 | grep -v grep"

... in the former, you're grepping the watch output. In the latter, you're grepping the ps output. So your example will do nothing. With quotes, you will see what you're looking for.

Quote:

Is there any command which I can see what a user is doing in real time ?
I mean when the user type "hello", my shell show me that the user type "hello".
This I don't know about, it doesn't seem reasonable (in that - what are you looking for? keystrokes? completed commands?, running programs?), but there's probably a way of doing something similar. :shrug:

anomie 03-07-2008 09:37 PM

Quote:

Originally Posted by GiotisSL
Can anyone help me with the "watch" command in Linux CentOS ?
...
In FreeBSD the command is "watch -W pid#"

FreeBSD watch is very different than CentOS watch. AFAIK, they are not related and the naming is a coincidence.
  • FBSD: watch -- snoop on another tty line
  • CentOS: watch -- execute a program periodically, showing output fullscreen

The latter is akin to running an arbitrary command in a while loop. (And I don't know an analogous command for FBSD's watch in CentOS.)

GiotisSL 03-09-2008 06:51 AM

Is there any similar/same command ?

gbellini 04-10-2008 04:15 AM

HI all,

digging around I found ttysnoop (www linuxhelp net guides ttysnoop)
I've not tried it yet, but I think it's worth a try

Cheers

amrahd 04-11-2008 01:16 PM

Yeah, here's a page describing how to get ttysnoop working on linux:

(add the http: / / bit before the following URL - this lame board wouldn't let me have a URL in my first post.)

sysadmingear.blogspot.com/2007/10/how-to-install-ttysnoop-on-linux.html

..and I was busy looking for a way to get the linux 'watch' command for freebsd - looks like someone else already took care of that: 'cmdwatch' tho I supose not many people on this board will care.

take care,
amrahd

Quote:

Originally Posted by gbellini (Post 3116604)
HI all,

digging around I found ttysnoop (www linuxhelp net guides ttysnoop)
I've not tried it yet, but I think it's worth a try

Cheers



All times are GMT -5. The time now is 07:01 PM.