Results 1 to 4 of 4

Thread: Need some help with scripting (top, ps, grep etc.)

  1. #1

    Need some help with scripting (top, ps, grep etc.)

    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.

  2. #2
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336
    Well, should not be a big deal.......

    http://wl500gp.lima-city.de/wl500gp/...ptExamples.txt

    to kill anything (example):

    http://wl500gp.lima-city.de/wl500gp/...s/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

  3. #3

    Thumbs up

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

  4. #4
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336
    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......

Similar Threads

  1. My custom script running on top of Oleg's firmware
    By harakiri576 in forum WL-500g Custom Development
    Replies: 0
    Last Post: 29-04-2007, 11:43
  2. Problem mit NAS, wl, und vor allem Grep
    By Winne2Koslowski in forum German Discussion - Deutsch (DE)
    Replies: 1
    Last Post: 11-01-2007, 12:30
  3. Scripting or automatic disable Radio
    By airone in forum WL-500g Q&A
    Replies: 2
    Last Post: 15-12-2005, 15:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •