Results 1 to 8 of 8
I am trying to run a simple script to let me know if rtorrent is running under a user.
Code:
#!/bin/sh
SERVICE='rtorrent'
USER='0001'
if pgrep -u $USER $SERVICE > /dev/null
...
- 10-23-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 6
Simple Service Check Script
I am trying to run a simple script to let me know if rtorrent is running under a user.
The script always returns rtorrent is not active even though it clearly is.Code:#!/bin/sh SERVICE='rtorrent' USER='0001' if pgrep -u $USER $SERVICE > /dev/null then echo "$SERVICE service is active" else echo "$SERVICE is not active" fi
Any help is welcome.
- 10-23-2011 #2Linux Newbie
- Join Date
- Dec 2009
- Posts
- 241
You may wannt change it into something like that:
Or (Ain't sure of that one)Code:#!/bin/sh SERVICE='rtorrent' USER='0001' if [ -z $(pgrep -u $USER $SERVICE) ] then echo "$SERVICE service is active" else echo "$SERVICE is not active" fi
But if I remember right $? is the exit code of the last command.
I don't know if "pgrep" will exit with an error if no process is found.
Code:#!/bin/sh SERVICE='rtorrent' USER='0001' pgrep -u $USER $SERVICE > /dev/null if $? then echo "$SERVICE service is active" else echo "$SERVICE is not active" fi
- 10-24-2011 #3Just Joined!
- Join Date
- Dec 2010
- Posts
- 10
Hi,
You can try this code.
#!/bin/bash
SERVICE='rtorrent'
USER='0001'
srvchk=`pgrep -u $USER $SERVICE`
if [ $? -eq 0 ]
then
echo "$SERVICE service is active"
else
echo "$SERVICE is not active"
fi
- 10-24-2011 #4
Or you check if there's the .pid file created by rtorrent at startup, if so in that pid file should be the process id of rtorrent. Then you can check if a process with that id exists. Only then the rtorrent service is running.
Note: on a power loss rtorrent does not remove the .pid file and this leaves the pid file with a invalid process id that should be cleaned by the startup script.
Cheers
- 10-24-2011 #5
Does it need to be a script?
I may be over-simplifying this, but how about just using top?
Code:top | grep rtorrent
Jay
New users, read this first.
New Member FAQ
Registered Linux User #463940
I do not respond to Private Messages asking for Linux help. Please, keep it on the public boards.
- 10-24-2011 #6
This is normally not enough. Thinking of the setup I have at home there's one instance of rtorrent that is started and run as a service with a dedicated session directory. Still each user could possibly start his own rtorrent instance on another free port and a different session directory. And even if this was not possible, I would not do:
butCode:top | grep rtorrent
cheersCode:ps -A | grep rtorrent
- 10-24-2011 #7
Gotcha. And I see what you mean.
Guess I was thinking to simplistic.
Jay
New users, read this first.
New Member FAQ
Registered Linux User #463940
I do not respond to Private Messages asking for Linux help. Please, keep it on the public boards.
- 10-24-2011 #8Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
And to OP, if you are not worried just about the 'rtorrent' client, then I'd be a bit less specific about what I'm looking for.
For example, something like this would look for any instance that has 'torrent' somewhere in it, and return the name of the user responsible:
Also, keep an eye on open TCP ports:Code:ps -eo user,cmd|awk '/torrent/{print $1}'
or with lsof:Code:netstat -tna
Code:lsof -i


Reply With Quote