Log in

Bekijk de volledige versie : Need some help with scripting (top, ps, grep etc.)



raas
17-10-2007, 21:04
Hi all,

I'm trying to write a (cron-scheduled) script in order to keep my SABnzbd running.
(As people may know, SABnzbd is a newsgroup downloader which runs on the asus, but 'crashes' when more than 1 nzb is entered in the queue..it does not exactly crash, but it fails to unrar the download. As long as only 1 nzb per time is handled everything is fine.)

So far I've drawn some conclusions:
- when SAB's running but not downloading, there are 'lots of' SABnzbd.py processes, but with no cpu-usage
- when SAB's running and downloading, there are 'lots of' SABnzbd.py processes, but 2-3 of them have significant cpu-usage
- when SAB's running and unrar'ing, there are 'lots of' SABnzbd.py processes, but with very little cpu usage.

Now I want to write a script which moves a .nzb file from the 'waiting' -directory to the 'todo'-directory of SABnzbd (the dir where a dirscanner scans for new nzb files and put them into the queue). This way SAB will download and unrar everything.

The script should move a file from one dir to another when:
- SAB's running with no ( < 2% ) cpu-usage and unrar has no cpu-usage.

I know I can get the cpu usage from SABnzbd or unrar with
- top -n 1 | grep 'SABnzbd.py'
- top -n 1 | grep 'unrar'

I also can use ps, but I don't get the cpu-usage.. only the time..

but, I don't know how to put it all together.
I'm an M$-programmer so programming logic is easy, I only don't know the syntax to use on how to make an .sh -script.. (Perl ?)

logic should be something like:



IF <SABnzbd is running> = True Then
IF <SABnzbd's cpu-usage smaller than 5%> Then
IF <unrar's cpu-usage smaller than 5%> Then
mv /mnt/SABnzbd/nzb_waiting/file.nzb /mnt/SABnzbd/nzb_todo/file.nzb
END IF
END IF



ELSE
# SAB's not running. Start SAB
<Start SABnzbd>
END IF



anybody can point me in a direction? example scripts or links on how to do the programming in this language?

Many Thanks.

newbiefan
17-10-2007, 21:19
Well, should not be a big deal.......

http://wl500gp.lima-city.de/wl500gp/scripts/ScriptExamples.txt

to kill anything (example):

http://wl500gp.lima-city.de/wl500gp/scripts/attached.txt

enjoy learning, if you need more let me know or google for scripts

just consider: every script must!! start with:

#!/bin/sh

all other is logical

raas
17-10-2007, 21:30
Hi,

Thanks for your quick reply. :)
I will look into that.

going to make my first script now.
if this one is solved I have all my things running I wanted to do..

newbiefan
17-10-2007, 21:56
Sorry, I forgot: (maybe you know it)

place the script to /opt/sbin (best place, because no flash&& is necessary)

cd to you dir: cd /opt/sbin
make script executeable with : chmod +x yourscript

have fun......