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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

shell script (again)

  • 04-10-2001 4:10pm
    #1
    Registered Users, Registered Users 2 Posts: 10,339 ✭✭✭✭


    right, this what I've got of a shell script so far:
    host=%1
    da='date +%y%m%d'
    cc=0
    
    until $cc=5
    do
    if (ping -c 1 xxx.xxx.xxx.xxx > /dev/null ) 
    then
    sleep 120
    else
    break
    
    cc=(($cc)+1)
    echo attempt $cc
    
    echo
    echo connecting to [$host]
    ssh [$host]
    

    that's the first section of it. the rest is still in the works. now, I keep getting an error that "cc=" in line 13 is unexpected... I've tried every variation I can think of. I know it's probably soemthing very basic but I can't think what it could be.

    any help?

    ps. it's bourne shell (sh) by the way... I know someone said use Cshell but I don't know any C at all and this is what I was asked to do it in.


Comments

  • Closed Accounts Posts: 219 ✭✭Bosco


    Heya LoLth,

    I may be wrong but shouldn't the bit after the equals (=) sign be inside quotes? (like line 2)

    Bosco


  • Closed Accounts Posts: 219 ✭✭Bosco


    Me again,

    ...not just ordinary quotes mind you but upquotes (top-left on the keyboard).

    Bosco


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    What type of c compiler (if any) does the system have? I know gcc is the gnu c compiler, but I have seen some Unix systems where cc is the c compiler (non-gnu, of cource). I have a VMS system here beside me, and sure enough cc is the c compiler.

    Have you tried another variable name?

    Of course I could be completely way off here...

    TD.
    :D


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    Please completely disregard my ranting in the previous post. I missed the '1' in 13 and thought the problem was in line 3 (cc=0). I have now read LoLth's post properly and see that my attempt to help has made me look a complete spanner. :eek:

    Having said that, I did have a similar problem when writing a shell script before.

    Too much VMS, not enough sleep....

    TD.


  • Closed Accounts Posts: 296 ✭✭moist


    Originally posted by LoLth

    cc=(($cc)+1)

    That should be cc=$(($cc+1)) I believe.
    You could also use somting like cc=`expr $cc + 1` using backquotes, the quote beside the number 1.
    Although I prefer the $(( )) way.
    Also you have to close your if statement with a fi .

    The syntax is...
    if (something)
    then
    	blah blah
    else
    	yadda yadda
    fi
    

    ps. it's bourne shell (sh) by the way... I know someone said use Cshell but I don't know any C at all and this is what I was asked to do it in.

    There is not a whole lot of difference with shall scripts in sh and csh, all they are are strings
    of different commands stuck together in a file.
    csh is syntacticly like C, hence the name :)
    but you are still using if/test/echo/ping/whatever
    commands in there.


  • Advertisement
  • Closed Accounts Posts: 219 ✭✭Bosco


    Moist,

    Ahhhh... apologies, I was mistaken. So 'back quotes' are only used when you want to store the output of a command in a variable?? (Or am I wrong again? :) )

    Bosco


  • Closed Accounts Posts: 296 ✭✭moist


    Originally posted by Bosco

    Ahhhh... apologies, I was mistaken. So 'back quotes' are only used when you want to store the output of a command in a variable?? (Or am I wrong again? :) )

    Eh, kinda, you use them when ever you want to use the output from a particular command(s).
    Like, say you want to delete all gif's in a directory but want to keep one,
    you could go around rm'ing them one by one, or...
    rm `ls *.gif | grep -v file_i_want_to_keep.gif`

    and things and stuff....


  • Closed Accounts Posts: 219 ✭✭Bosco


    You learn something new every day I suppose :)

    Thanks moist


Advertisement