0

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 foo@1.1.1.1

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

  • Did you check this config using copy and paste manually ? Try maybe also increase timeout for ssh session in you command "ssh -o ConnectTimeout=seconds". sshpass is only for password , all jobs in your case do "cat" for reading config file and ssh for external connection. – DamianK Mar 04 '20 at 08:40
  • Yes I tried the config by just pasting it, it does work. I also tried with ConnectTimeout but it didn't work and I believe the issue has nothing to do with timeouts as ssh is just closing the connection and not timing out or anything – Jannis Federmair Mar 04 '20 at 09:54

1 Answers1

0

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 foo@1.1.1.1 $config

Please consider also to use ssh key instead sshpass.

DamianK
  • 387
  • 2
  • 6
  • This will just cut every newline in my config and paste the whole config in a single line to the ASA, I really don't know how that should help with my problem, could you elaborate? – Jannis Federmair Mar 05 '20 at 09:33
  • Did you check or not ? I used this second solution in one of my old project. I checked your previous command with config file with more than 150 line inside and I didn't have any problems with that ( but to different device than ASA ). – DamianK Mar 05 '20 at 09:59
  • My only problem in this whole constilation is the ASA, the script itself works fine on any other device. Thanks anyway – Jannis Federmair Mar 06 '20 at 10:36