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 admin@10.1.1.1
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
admin@10.1.1.1'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 $user@10.1.1.1
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
0

Use SSHPASS combined with SSH. Syntax:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.