Re: expect + last few arguments as one



On 2008-05-23, Nichu <nichu@xxxxxxxxxxxxx> wrote:


Hello
I'm trying to execute some commands on remote machines using expect ...

my script looks like that:

#!/usr/bin/expect -f
set password [lrange $argv 0 0]
set ipaddr [lrange $argv 1 1]
set scriptname [lrange $argv 2 20]
set timeout -1

spawn ssh $ipaddr $scriptname
expect "*?assword:*"
send -- "$password\r"
expect eof

I execute this script like:
./ssh_login.sh PASSWD IP COMMAND

and generally it works great
BUT
i would like to execute script on remote machine and result of it direct
to different text file (on remote machine as well) AND here i have problem
because I can't use:
./ssh_login.sh PASSWD IP script > /tmp/result.txt
because of course it will direct result to local file

and when I try
./ssh_login.sh PASSWD IP "script > /tmp/result.txt"
it doesn't work:

./ssh_login.sh PASSWD IP "who > /tmp/result.txt"
spawn ssh debian {who > /tmp/xinetd.txt}
nichu@debian's password:
bash: {who: command not found

I tried with different characters and still doesn't work...

any ideas?

Set up authorized_keys on the remote machine so you don't have to send a
password or use expect.
Use ssh-keygen to generate a key pair on the local machine. Press enter
when it asks for a passphrase. Then use ssh-copy-id to copy the public
key to the remote machine.
.



Relevant Pages

  • CGIscript.net - csMailto.cgi - Remote Command Execution
    ... CGIscript.net - csMailto.cgi - Remote Command ... csMailto is a perl cgi formmail script developed by ... execute command on server and mail output to anyone ...
    (Bugtraq)
  • Re: shell scripting
    ... and am assuming an sh-compatible shell here.... ... command 1 options arguments ... To run the script, do: ... then you need to use the full path to execute it: ...
    (comp.unix.questions)
  • Re: shell scripting
    ... and am assuming an sh-compatible shell here.... ... command 1 options arguments ... To run the script, do: ... then you need to use the full path to execute it: ...
    (comp.unix.shell)
  • =?iso-8859-1?Q?Re:_Jcl?=
    ... I can send you a program that you execute as a step in your job and it ... I have a command and job scheduler that is available in a free version ... demand script processor with the full scripting ability so that your job ...
    (bit.listserv.ibm-main)
  • Re: sms installer- automate installing local printer
    ... Thanks Terry- Here is the script that I used that seemed to work- I just had ... > However since you are asking about getting the command line to work we can ... execute program this is where you are making the most mistakes. ...
    (microsoft.public.sms.installer)