DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2010-12-15 23:34:23

bound4h
Member
Registered: 2010-04-12
Posts: 209

Script to see if Transmission is running

I have a script that moves completed torrents to a completed folder running every 30 minutes.  But, I don't want this to run if Transmission Daemon is not running.  Can anyone just post a simple if then script to check to see if it's running and I will encase my current script in the if,then sript?

I was thinking the command being like this, but I'm unsure of the syntax:

$running = `ps | grep transmission | wc -l`

if $running gt 1; then
{my script here}
fi

Will that work?  I am assuming when I run the grep command it will create a process called "grep transmission" so I will need the wc -l to be greater than 1.

Thanks in advance

Offline

 

#2 2010-12-16 02:46:08

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: Script to see if Transmission is running

Although that may work, another option is simply to call the transmission start script with a "status" parameter.

On the flip side, what's the big deal about whether it is running or not? I have a script that checks every hour to see if there are any completed torrents, it then removes the torrent (keeping the data). If there is nothing to do, it runs quick smile

You may be able to modify this perl script to do what you want.

Code:

#!/ffp/bin/perl

#
# trans_cleanup.pl perl script that removes completed torrents

# tr_port is the port that transmission admin is running on
$tr_port = 9090;

# tr_bin is the path and name of transmission-remote executable
$tr_bin="/ffp/bin/transmission-remote";

$tdate = `/ffp/bin/date`;
chomp($tdate);
# Strip the timezone to match the Transmission date entry
# This is EDT and EST in my case
$tdate =~ s/E.T //ig;
#print $tdate." Running $0\n";

# query for any completed torrents
@trn_items=`$tr_bin $tr_port -l|grep "Finished"`;

foreach $item(@trn_items) {
  $item =~ s/^\s+//;
  while ( $item =~ m/  / ) { $item =~ s/  / /ig; }
  @b = split(/\s/,$item);
  $tname = $b[9];
  for ($i=10; $i<=($#b+1); $i++) { $tname .= " ".$b[$i]; }
  print $tdate." Removal of torrent [".$b[0]."] ".$tname;
  # delete the finished torrent entry
  $result = `$tr_bin $tr_port -t $b[0] -r`;
  chomp($result);
  print ( $result =~ m/success/i ? "succeeded\n" : "FAILED ".$result."\n" );
}

# eof

Last edited by FunFiler (2010-12-16 02:47:48)


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#3 2010-12-16 07:53:42

bound4h
Member
Registered: 2010-04-12
Posts: 209

Re: Script to see if Transmission is running

I was just trying trying to eliminate the need to spin up the disks.  But then again, running ANY script from /ffp and down requires a disk to spin up, right?  So I guess I'm not accomplishing much if this "new" script is located in /ffp too...

Offline

 

#4 2010-12-16 18:54:56

karlrado
Member
Registered: 2009-12-07
Posts: 229

Re: Script to see if Transmission is running

bound4h wrote:

I was just trying trying to eliminate the need to spin up the disks.  But then again, running ANY script from /ffp and down requires a disk to spin up, right?  So I guess I'm not accomplishing much if this "new" script is located in /ffp too...

I'm not super-clear on that myself.

If you have a real simple script that runs in a loop and sleeps for a period of time to do something every 30 mins or whatever, it may not need the disk once it is loaded and running.  Of course a lot depends on what the work part of the script actually does.  If it accesses the disk to look at a file or something, then the disk will start.

If you have something like a perl script (#!/ffp/bin/perl in first line), like in this thread, the disk will probably spin up whenever it runs.  This is because the perl interpreter is in /ffp and so are a lot of libraries that the script may need which may get loaded dynamically as the script runs.

Note that if you use cron to launch a script periodically from /ffp then the disk will probably start for that as well.  But I think you can use cron to launch a simple script that is itself stored on the ramdisk and does not touch the disks without spinning up the disk.

I know some people here were working on a Dynamic DNS script that could run from cron without starting the disk.  A script like this needs to run every 10 mins or so.  One problem with one of the "standard" DNS update scripts is that it is written in perl and so causes a disk access every time it starts.   I think that there is a thread in this forum someplace where people were working on a non-perl script that would not start the disks.


DNS-323 FW 1.07 : 2 1TB WD Caviar Green SATA : fun_plug: utelnet + optware (no ffp)

Offline

 

#5 2010-12-16 21:18:51

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: Script to see if Transmission is running

You can do it easier:

Code:

if ps | grep -v grep | grep transmission ; then
# Your code here
fi

The first grep will filter out grep, the result of the second grep will be evaluted by 'if'

About spinning up the disk, when you didn't install coreutils, all commands used are actually busybox, which is already loaded in memory (The shell running your script is also busybox). The same instance of busybox will be reused, so nothing has to be loaded from disk.
You could also run your script with firmware commands. These are in rom. 
shan't

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB