Run local Perl script on remote server through expect -
i have perl script on local machine, , want run on remote server. following command works fine:
ssh user@ipaddress "perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl
the thing prompt shows ask me password, , don't want that.
i looked around net, , found 3 solutions:
- using public/private key authentication -> not ok in case
- using sshpass -> not in company's 'official' repo cannot install it
- using expect
i followed page create expect script (i'm new expect): how use bash/expect check if ssh login works, took script correct answer, , replaced 3 first lines #!/usr/bin/expect -f
have expect script.
then ran
./ssh.exp user password ipaddress "perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl
and have timeout error. if ran ./ssh.exp user password ipaddress "perl"
i tried putting quotes like
./ssh.exp user password ipaddress '"perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl'
but have /path/to/local/script.pl not found
error.
so can me figure out how run script through expect ? lot.
ok, found myself.
still using answer how use bash/expect check if ssh login works replaced 6th line with
set pid [ spawn -noecho sh -c "ssh $1@$3 $4 < /path/to/local/script.pl" ]
and works charm.
Comments
Post a Comment