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:
Code:
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.