3

Using sshpass in bash script. I am connecting to the server, send the command df -h and save the output in a txt file.

It works fine with about 10 servers. I found it doesn't work with some other servers and I don't understand why. Servers are same. So same OS, same hardware etc.

#!/bin/bash
timeout 60 /usr/bin/sshpass -p 'mypassword.' ssh -o StrictHostKeyChecking=no [email protected] /usr/sbin/vtysh > /var/www/output/11-22-33-44.txt << EOF
df -h
EOF

sleep 5;

timeout 60 /usr/bin/sshpass -p 'mypassword.' ssh -o StrictHostKeyChecking=no [email protected] /usr/sbin/vtysh > /var/www/output/55-66-77-88.txt << EOF
df -h
EOF

etc.

In some servers I see only:

/bin/login: invalid option -- q
Tinylogin v1.4 (2018.03.23-08:44+0000) multi-call binary

Usage: login [OPTION]... [username] [ENV=VAR ...]

Options:
    -f      Do not perform authentication (user already authenticated
    -h      Name of the remote host for this login.
    -p      Preserve environment.

Bash script is absolutely same, no changes there (only IP address). Will be very thankful for help.

sover
  • 31
  • 3
  • Often ssh will issue a login command to get a command prompt. On next the syntax seems to be slightly different. `sshpass` is essentially a wrapper around the ssh client that will "type" the password as if you typed it yourself. It works very similarly to an `expect` script. As login issued an error it were unable to log into the system. Have you tried the -v option to see if there is additional output that could help? – Zip Dec 23 '19 at 21:36
  • Even if it is the same OS, the version of the sshd or its config can vary. – Bernhard M. Dec 24 '19 at 04:26
  • 1
    what's the result of `grep -i 'MaxSession' /etc/ssh/sshd_config`? it that 10? – αғsнιη Dec 30 '19 at 19:28

0 Answers0