Need script to check if rtorrent is running or not

jith45

Member
May 25, 2018
960
0
16
Dear All
I need to write a script which checks every hour if rtorrent is running or not. and if not, run "/etc/init.d/autodl_username start" to start rtorrent. could you please tell me what should this script look like?
Thanks in advance
 

dsouvik215

Member
May 25, 2018
896
0
16
a simple solution would be to attempt to run rtorrent via cron every hour. it won't allow multiple instances to start, so you wouldn't have to worry about extra instances hogging up space.

but something like,

if [ ! `ps aux | grep `whoami` | grep -v 'SCREEN\|grep' | grep rtorrent` ]; then
screen rtorrent
fi

would work too.
 

jith45

Member
May 25, 2018
960
0
16
Thank you very much
but how to run this code every hour?
is it possible to use schedule option in .rtorrent.rc?
 

shwetha17

Member
May 24, 2018
785
0
16
i fixed it up a little bit. the other way wouldn't work as the inner back ticks wouldn't have expanded.

Code:
me=`whoami`
if [[ ! `ps aux | grep '$me\|rtorrent' | grep -v 'SCREEN\|grep'` ]]; then
<screen command here>
fi
just put that into a shell command, i'd put it in /bin and set the proper permissions on it, then edit your cronjobs using crontab -e (preferably as the user you want to check on)

for every hour you'd enter
Code:
0 * 0 0 0 /bin/<scriptname>
 

somus1735

Member
May 25, 2018
833
0
16
This is why nowadays you use $() which is nestable, backticks are for old geezers unable to learn new stuff.

BTW, if you use Unix domain sockets...

RT_SOCKET=/var/torrent/.scgi_local
# rTorrent
* * * * * test -S $RT_SOCKET && lsof $RT_SOCKET >/dev/null 2>&1 && some_cmd_that_needs_rt_running