Assigning several variables at once in single ssh session
Hello all,
I currently have a script that does four separate ssh sessions to get variable information from a remote host: Code:
WDvr=`ssh root@$STORE ls -l /usr1/vision/bin/wd | awk '{print $5}'` Thanks, Keith |
Have a look at this:
Code:
#!/bin/bash I do assume in the above example that each separate command produces 1 entry. This doesn't account for anything going wrong with any of the 4 commands...... EDIT: Added the previous missing Tapp part (sorry 'bout that). |
Quote:
I changed my commands to something simple so I can start from scratch (See the various 'pwd' commands below). I found that the first variable is being set on the remote host. But the following three are being set on my local machine: Code:
#!/bin/sh Code:
[techs@ts-01 scripts]$ ./allVars-script.sh The next 3 'pwd' commands comes back with '/home/techs/scripts', which is where I am working on my local box. So after executing the first command correctly, the script is leaving the remote host and executing the latter 3 locally. Is there anything off hand that you can see that might be resulting in this action? Thanks again for getting me this far. I'll keep hammering at it. Keith |
The problems are the semicolon after the pwd commands. If you write
Code:
ssh root@$STORE pwd; pwd; pwd; pwd; Code:
ssh root@$STORE "pwd; pwd; pwd; pwd;" |
Quote:
I'm currently working no another problem with this script, so if anyone has some insight to this please feel free to share. Here it goes: I added my first command to the script (Replacing the 'pwd' test). The good news is it's setting the first variable correctly. The bad news is, it's setting the second variable with part of the first command: Code:
#!/bin/sh Code:
WD - 78740 # Correct |
Again a problem of protecting the remote command from the local shell. This time is the $1 in the awk command that must be escaped, otherwise it results in a null string (if you don't pass arguments to the script) and awk simply prints out the whole string, which is
Code:
78740 /usr1/vision/bin/wd Code:
"du -b /usr1/vision/bin/wd | awk '{print \$1}'; \ |
@keif: I was focusing too much on the array part and completely overlooked the details of the ssh command. As already explained by colucix, you need to take make sure commands aren't interpreted locally.
These 2 links might help with that: - The Bash Parser - (POSIX) Shell Command Line Processing And here's a working version (tested this time...) based on your examples: Code:
#!/bin/bash |
Quote:
Thank you for explaining this. It's working great now. I may have bashed my head against the wall a lot on this one, but I learned a heck of a lot. Thanks for your help. |
Quote:
|
All times are GMT -5. The time now is 05:53 AM. |