Results 1 to 3 of 3
Hi
Could someone tell me why the following doesnt work, please, and how to fix it:
Code:
#!/bin/bash
echo "1|2|3|4|5|6" |{ while read id
do
stockid=`echo "$id" | mawk 'BEGIN{FS="\|"} ...
- 04-23-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 3
Variable scope and ssh
Hi
Could someone tell me why the following doesnt work, please, and how to fix it:
If I paste #1 directly to the console, it works fine (ssh then echos 1 2 3). However, when I run the ssh directly in the script, as in #2? it loses the values for $stockid" "$date" "$views and prints an empty line.Code:#!/bin/bash echo "1|2|3|4|5|6" |{ while read id do stockid=`echo "$id" | mawk 'BEGIN{FS="\|"} {gsub("\r",""); print $1}'`; date=`echo "$id" | mawk 'BEGIN{FS="\|"} {gsub("\r",""); print $2}'`; views=`echo "$id" | mawk 'BEGIN{FS="\|"} {gsub("\r",""); print $3}'`; done; echo "ssh nagiosusr@tf9 'echo $stockid $date $views' " #1 ssh nagiosusr@tf9 'echo "$stockid $date $views" '#2 }
- 04-24-2009 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 90
Simply put, the variables don't exist on the ssh'd machine.
- 04-24-2009 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Most everything inside the single quote 'echo "..." ' will be output as interpreted on the remote system. New scope, new values of variables, which are empty in this case, as per the answer from Touchtecservers.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote