![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| csh failing to call an 2 embedded csh script | pollsizer | Shell Programming and Scripting | 1 | 06-07-2008 01:22 PM |
| Shell script - If---fi condition | yog_chavan | Shell Programming and Scripting | 4 | 05-07-2008 09:46 AM |
| need help with test condition in shell script | pieman8080 | Shell Programming and Scripting | 9 | 09-11-2006 05:20 PM |
| UNIX script failing .... | khan1978 | UNIX for Advanced & Expert Users | 1 | 12-05-2005 01:28 PM |
| OR'ing condition in script | vino | Shell Programming and Scripting | 9 | 04-21-2005 08:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
IF condition failing in a SSH script
Hi,
I'm ssh-in to a remote machine (ubuntu) and trying to execute a little script in there.The script looks like this: Code:
ssh user@ubuntu <<EOF cd ~/test ls -l echo "Continue counting files starting with a`s ?" read answer if [ "$answer" = y ] then ls -l a* else exit fi EOF In other words every simple script that I built with a test condition in a SSH script seems to fail. Anybody any ideas ? And in general, is there a rule that I should keep in mind when executing a test condition in a remote machine thru a SSH script ? Last edited by rubionis; 04-15-2008 at 05:42 PM.. Reason: added code tags |
|
||||
|
Yes, I forgot to say I have #!/bin/bash at the head of the script.
And I actually don't have back tick in the script, ( Yes I'm aware of special characters conflicts in a script), I just put a`s as an example. Say I avoid all special characters in the ssh script, does the script look OK ? So my question is, if there is any known conflict when using test condition in a SSH script,.which I'm not aware of, or put it in other words what is a general format of test condition in a SSH script. Or am I missing something in my script? Thanks for your quick reply. |
|
||||
|
Indeed, you have an open-ended single-quote which should be closed.
But...you have bigger problems than that, because this is a *remote* script. So, statements like this: Code:
ssh HOST <<EOF
echo $HOSTNAME
EOF
Code:
ssh HOST <<\EOF
# the backslash above will prevent the Variables below from being evaluated
echo $HOSTNAME
EOF
Code:
cat <<EOF > /tmp/test.script
# this is a temporary location
echo $VALUE1 \$VALUE1
EOF
|
|
||||
|
Thanks gus2000,
The separator \EOF did the trick regarding all the variables in the SSH script. Another useful info to keep in mind ! ( I know, I have to be careful with the variables, BTW I'm using a longer awk command in the script and I escaped all the $ with \$ . ) But unfortunately the IF test fails again: Quote:
So my MAIN question remains the IF test. In other how would I write an IF test (or a TEST cmd in general ) in ssh script without failing ? Last edited by rubionis; 04-15-2008 at 05:58 PM.. Reason: code tags |
|
||||
|
Do You even get a prompt for answer to Your read statement? I think that since ssh is non-interactive (not a controlling terminal) You can't have a terminal like session, either You must work with something like expect or keep the script locally and just "collect" whatever info You need from the remote host and process it locally.
Make a local script and run it locally: Quote:
/Lakris |
|
||||
|
Quote:
I've had this bite me before with some programs that want a terminal to send data too... Root get's email garbage then. Quote:
Like this: ssh user@ubuntu "ls -l /test" echo "Continue counting files starting with a`s ?" read answer if [ "$answer" = y ] then ssh user@ubuntu "ls -l a*" fi It's not as efficient with multple sign-ons, but the logic is all local. The only exception is if there is large amounts of data to filter out (with a grep or something) - I'll try and be nice to the network. |
![]() |
| Bookmarks |
| Tags |
| grep or, linux, ubuntu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|