Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a string to another script 2

Status
Not open for further replies.

grepper

Technical User
Jun 4, 2003
49
0
0
US
I have written an Expect script to go out and run a command on another host which works great. From the command line I call it by

./myExpect <hostname> <myuid> <mypass> <command>

<command> has to be in double quotes if it is more than one word i.e. &quot;touch junk&quot; for Expect to work

The problem is I am writting a ksh script to call myExpect so I can loop the hostname to run a command on many servers.
The script looks like this pior to me adding the while loop:

#!/usr/bin/ksh

hostid=$1
userid=$2
passwd=$3
command=$4
./myExpect $hostid $userid $passwd $command

and is called by

./myScript <hostname> <myuid> <mypass> <command>
where <command> is in double quotes i.e. &quot;touch junk&quot;

When myScript passes $command to myExpect it only passes the first command. So instead on passing &quot;touch junk&quot; it only passes &quot;touch.&quot;

Do you guys know what can fix this? Many thanks........



 
Hi grepper,

Do an echo $5 and you should find the rest of your touch command. Try the following in your script

./myExpect $hostid $userid $passwd &quot;$command&quot;

I don't think ksh 'remembers' that the contents of $command was passed as a quoted string. So if you subsequently use it in your script it will be treated as multiple parameters.


Ade
 
Korn shell does 'remember' actually. You should be able to just use:

[tt]#!/usr/bin/ksh

./myExpect &quot;$@&quot;[/tt]

Annihilannic.
 
Thanks, &quot;$command&quot; passes the entire command. Everything is working great....Thanks for you help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top