Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Good news everyone! The Boards.ie Subscription service is live. See here: https://subscriptions.boards.ie/

seti@home bash scrip question

  • 26-02-2002 08:47PM
    #1
    Closed Accounts Posts: 1,026 ✭✭✭


    i'm writing a bash script to let me download 3 seti@home work units at a time.

    In the script that uploads the results I want to be able to run setiathome and check if it prints the line

    Can't connect to server; will retry in an hour.

    and if it does: restart the program after a minute.

    i think a mixture of grep and if statements might do it but i cant work it out.

    any help appreciated


Comments

  • Closed Accounts Posts: 296 ✭✭moist


    How about...?
    #!/bin/sh
    
    
    OUTPUT=`/path/to/prog 2>&1`
    
    CONTINUE="YES"
    
    while [ "${CONTINUE}" = "YES" ] 
    do
            if [  "${OUTPUT}" = "Can't connect to server; will retry in an hour." ]
            then    
                    echo "Can't connect, sleeping...."
                    sleep 60
                    OUTPUT=`/path/to/prog 2>&1 `
            else    
                    echo "Connected, exiting..."
                    CONTINUE="NO"
            fi      
    done
    


    Depending on weather your program prints that error message on stderr or not
    you may or may not have to use the " 2>&1 " bit (that just redirects stderr to stdout)
    Its probably no harm to just leave it.

    The test looks to see if the strings match _exactly_ so if your program
    prints other messages, obviously the test will always fail.

    In that case you could replace it with...
    OUTPUT=`/path/to/prog 2>&1 | grep "Can't connect to server; will retry in an hour."`
    


Advertisement