sshpass stops parsing piped input after 70 lines

217 Views Asked by At

I made a bash script to automatically update a object-group on a Cisco ASA with office365 IPs via SSH.

I'm getting the IPs from MS, building the right command-syntax for the ASA, and writing all commands in a file (right now 90 lines, but as this is dynamic it can grow or shrink). Then I want to push the commands in the file to the ASA with:

cat outfile.txt | sshpass -p "Password" ssh -t -oStrictHostKeyChecking=no [email protected]

but sshpass stops sending commands after line 70. so outfile.txt has 90 something lines but no matter on which host I try to "deploy" the commands, it just send's the first 70 lines. After that i just get a

Connection to 1.1.1.1 closed by remote host.

On the firewall I see a TCP reset from the server, but as I said it doesn't matter on which host (tried different Firewalls, Routers and other servers) I try it won't send more than the first 70 lines.

Anyone got a solution for my problem or another way to achieve my problem?

Thanks

1

There are 1 best solutions below

3
DamianK On

Try this, maybe it's not pretty but should work. the last message from server can be also "Connection closed by remote host" but all config should be added properly already.

#!/bin/bash

where="<path to your outfile.txt>";
len=`cat $where | wc -l`;
config=`for (( c=1; c<=$len; c++ )) do line=\`sed -n "$c""p" $where\`; echo $line; done`;

sshpass -p "Password" ssh -t -oStrictHostKeyChecking=no [email protected] $config

Please consider also to use ssh key instead sshpass.