Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Expect and parameters with $

Posted by FullGaz (FullGaz), 3 April 2006
Hi!

I am writing a script that logs on to different remote servers using ssh and then runs a program remotely.

On each server I have set an environment variable such as $MY_PROG_PATH so that I don't have to change my scripts if the program path changes.

I may use this script from the command line or call it from diverse Perl scripts using system().

Say the script is called run_remote.exp. It takes the server name as a parameter and then the command I want to run.

for instance, I might want to write:

run_remote.exp server1.domain.com \$MY_PROG_PATH/my_prog.pl param1 param2

or run_remote.exp server2.domain.com \$MY_PROG_PATH/my_prog.pl param1 param2

(Here the \ prevents the command line from interpreting the environment variable locally) .

The advantage of this approach is that each server knows what is the result of it's own $MY_PROG_PATH.

The problem is that the script sends the following command to the remote server:
{$MY_PROG_PATH/my_prog.pl} param1 param2

which of course doesn't work because of the {}.

I've tried many combinations of backslashes, brackets and other signs, to no avail... Is there a solution?

I'm using very basic expect, using only expect and send with the -- option.

Thanks for your help.

Posted by admin (Graham Ellis), 3 April 2006
The extra curly braces are added in Tcl because the parameters are in a list; you can get rid of them by using join to turn them into a regular string.

Example - this sample code

Code:
puts $argv
puts [join $argv]


runs as follows

Code:
grahamellis$ tclsh tdo www.wellho.net \$MINE/doit.pl 1 p2
www.wellho.net {$MINE/doit.pl} 1 p2
www.wellho.net $MINE/doit.pl 1 p2
grahamellis$


Posted by FullGaz (FullGaz), 3 April 2006
Graham, you're a genius!  
Thanks ever so much, I am so glad to have found this forum.
Of course this worked and solved all my problems  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho