0

I am writing a small script using expect command to supply the password; the aim is to login to a switch and fetch a command. OS : RHEL 7. There is a small app proxychains which is used to login to client network. So I would need to open it first and then run my commands (ssh etc).

For example:

[ram@abcde scripts]$ /usr/bin/proxychains ssh [email protected]
ProxyChains-3.1 (http://proxychains.sf.net)
|S-chain|-<>-129.39.159.150:1080-<>-138.222.124.15:1080-<><>-10.49.99.49:22-<><>-OK
[email protected]'s password: 

I want to automate the above using expect, so I have below script and getting errors.

set user "admin"
set password "sample123"
/usr/bin/proxychains ssh [email protected]
expect "ssword: "
send "$password\r"
expect ">\r"
send "switchshow\r"
expect eof

I am getting below error;

[ram@abcde scripts]$ sh br1.sh 
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port]
           [-Q cipher | cipher-auth | mac | kex | key]
           [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] [user@]hostname [command]
br1.sh: line 3: ProxyChains-3.1: command not found
couldn't read file "ssword: ": no such file or directory
br1.sh: line 5: send: command not found
couldn't read file ">\r": no such file or directory
br1.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory
1

1 Answer 1

0

Use SSHPASS combined with SSH. Syntax:

sshpass -p 'password' ssh user@domain/ip "command"
2
  • sshpass does not work in redhat Linux Dec 22, 2017 at 17:22
  • It works, yes, I use it in my scripts. Dec 27, 2017 at 17:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .