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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: 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