| |||||||||||
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:
runs as follows Code:
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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |