#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    13
    Rep Power
    0

    ssh from shell script


    i m trying to write a script which works as follow.
    machine A , where my script is
    machine B , the machine where i m trying to ssh

    while in A, i'm trying to ssh B, and check if file test.c exist.
    if exist, error msg will be displayed.

    ---------------------------------------------
    ssh b.example.com
    if [ -f /home/test.c ]; then
    echo "file existing! " 1>&2
    echo "Program terminating!" 1>&2
    exit 1
    fi
    ---------------------------------------------

    but this alone is not working.
    once i ssh, i'm considering entering machine B.
    i would like the code below to work background in machine B, while i'm waiting for the result at machine A terminal.

    may i know how i should code this?
  2. #2
  3. Perl Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    May 2003
    Location
    the far end of town where the Grickle-grass grows
    Posts
    1,860
    Rep Power
    108
    can you put the code you want to run on machine B in a script and just call it with the -c switch to ssh? otherwise there's tools that can send info (Expect, maybe?) that you can look up and use
    Andrew - Perl (and VB.NET) Monkey

    Never underestimate the bandwidth of a hatchback full of tapes.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    13
    Rep Power
    0

    Wink


    Originally Posted by icrf
    can you put the code you want to run on machine B in a script and just call it with the -c switch to ssh? otherwise there's tools that can send info (Expect, maybe?) that you can look up and use
    that is an idea too.
    thanks.
    i will try it out, but if the command i want to run in machine B is just one line or two, i hope that i do not need to script it.

    by the way, i got the solutions as follow.
    if ssh b.com ' [ -f file.c ] ' ; then
    echo "error"

    quote the command i want it to do with single quotations.


    thanks for the idea
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    1
    Rep Power
    0
    Originally Posted by rei
    that is an idea too.
    thanks.
    i will try it out, but if the command i want to run in machine B is just one line or two, i hope that i do not need to script it.

    by the way, i got the solutions as follow.
    if ssh b.com ' [ -f file.c ] ' ; then
    echo "error"

    quote the command i want it to do with single quotations.


    thanks for the idea


    Thanks for the code, this can be used for more more command with more condition.

IMN logo majestic logo threadwatch logo seochat tools logo