Search code examples
linuxbashshellseq

How to have 2 variables with 2 different seq - Bash Linux


I have this command that I want to use to pull information out of a Motorola Chassis. I will use SNMP V2 and Bash script to pull the information.

2 Variables

IP = last octet of Chassis IP (1...10)
Port#= Chassis port ID (10 10 240)

The command that I have is:

for ip in `seq 1 10`;
    do echo Chassis .$ip ; 
    snmpwalk -v2c -c ComunityName 172.27.253.$ip IF-MIB::ifAdminStatus.$port; 
    echo -e "\n";  
done

This command won't work because I have not declared yet the $port variable, but how can I integrate this variable in to the same line of commands in order for it to perform the seq 10 20 30 40 .... 240?


Solution

  • With an inner loop for the $port values. As you're under Bash, you can use Bash sequence {1..10} instead of seq:

    for ip in {1..10}; do 
      echo Chassis .$ip;
      for port in {10..240..10}; do
        echo snmpwalk -v2c -c ComunityName 172.27.253.$ip IF-MIB::ifAdminStatus.$port; echo -e "\n"; 
      done
    done