Hi folks, I'm a newbie in bash scripting. I'm trying to perform ping tests using bash + expect + some files where I have the IPs of the devices I have to connect to and the IPs to ping. It's a dumb performance test in order to learn a little bit about bash and expect. Here's the code, I'll explain it below: #!/bin/bash # Collect the current user's ssh and enable passwords echo "Rentrez votre login TACACS RR3 s'il vous plaît" echo "Normalement real.xxx01" read -s -e -r login_tacacs echo "----------------------------------------------------" echo "Rentrer votre mot de passe TACACS RR3 s'il vous plaît" read -s -e -r password_tacacs echo "----------------------------------------------------" echo "Rentrer votre login perimetre garik (RR2)" echo "Normalement prenom.nom" read -s -e -r logingarik echo "----------------------------------------------------" echo "Rentrer votre mot de passe perimete garik" read -s -e -r passwordgarik echo "----------------------------------------------------" echo -ne '\n' log_file=test-$(date +%F).log touch "$log_file" # Feed the expect script a device list & the collected passwords echo "Connecting to CVPN devices" for device in $(cat cvpn-lo0.txt); do for device_ping in $(cat cvpn-pe-ping.txt); do ./test-ospf.exp $device $login_tacacs $password_tacacs $device_ping >> $log_file; done done echo "----------------------------------------------------" echo "Connecting to LNS devices" echo -ne '\n' for device in $(cat lns-lo0.txt); do for device_ping in $(cat lns-pe-ping.txt); do ./test-ospf.exp $device $login_tacacs $password_tacacs $device_ping >> $log_file; done done echo "----------------------------------------------------" echo "Connecting to XR devices" echo -ne '\n' for device in $(cat xr-lo0.txt); do for device_ping in $(cat xr-pe-ping.txt); do ./test-ospf.exp $device $logingarik $passwordgarik $device_ping >> $log_file; done done echo "----------------------------------------------------" echo "Connecting to RH devices" echo -ne '\n' for device in $(cat rh-lo0.txt); do for device_ping in $(cat rh-pe-ping.txt); do ./test-ospf.exp $device $login_tacacs $password_tacacs $device_ping >> $log_file; done done
So first I ask for 2 credentials that I need in order to login to different devices. I create a log file and then my idea is to loop between two files: one for the ips of the devices that I have to go in with SSH (cvpn-lo0.txt and all lo0.txt files, there's basically and ip per line in those txt files) and another for the lo0 of the devices I have to ping from every specific source (there's an IP per line as well). The ping is done in expect from the script test-ospf.exp Thing is that I keep having an error on line 23 (the first for iteration). I don't know what I'm doing wrong. I'm sending the expect script as well in case you want to take a look. Any help would be appreciated. <https://lh3.googleusercontent.com/-tUIO4yhSpjY/WfGsBfE0QUI/AAAAAAAAG7I/ligD-mRletwAFYf05yncCRYS9yGJDLYNQCLcBGAs/s1600/2017-10-26_11h33_40.png> Expect Script #!/usr/bin/expect -f exp_internal 1 # Set variables set timeout 20 set hostname [lindex $argv 0] set username $env(USER) set password [lindex $argv 1] set lo0_ping [lindex $argv 2] # Announce which device we are working on and at what time send_user "\n" send_user ">>>>> Je travaille sur $hostname @ [exec date] :) <<<<<\n" send_user "\n" # Don't check keys spawn ssh -o StrictHostKeyChecking=no $username\@$hostname # Allow this script to handle ssh connection issues expect { timeout { send_user "\nTimeout Exceeded - Check Host\n"; exit 1 } eof { send_user "\nSSH Connection To $hostname Failed\n"; exit 1 } "*#" {} "*assword:" { send "$password\n" } } # If we're not already in enable mode, get us there expect { default { send_user "\nEnable Mode Failed - Check Password\n"; exit 1 } "*#" {} } # Enter your commands here. Examples listed below send "ping $lo0_ping repeat 1000 source loopback0" expect "*ms" quit exit Thanks in advance folks. Cheers, Luis -- -- You received this message because you are subscribed to the Linux Users Group. To post a message, send email to [email protected] To unsubscribe, send email to [email protected] For more options, visit our group at http://groups.google.com/group/linuxusersgroup References can be found at: http://goo.gl/anqri Please remember to abide by our list rules (http://tinyurl.com/LUG-Rules) --- You received this message because you are subscribed to the Google Groups "Linux Users Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
