I am new in bash scripts. I try to make script who check devices ( tp-link, cisco, lynksys... ) to connect via telnet and get some info.
So the first script work with no problem:
#!/bin/sh
NOW=$(date +"%m-%d-%Y")
HOST='IPADDRES'
USER='USER'
PASSWD='PASSWORD'
CMD='enable'
CMD2='show mac address-table'
CMD3='terminal length 0'
(echo "$HOST - " ; (
echo open "$HOST"
sleep 1
echo "$USER"
sleep 1
echo "$PASSWD"
sleep 1
echo "$CMD"
sleep 1
echo "$CMD3"
sleep 1
echo "$CMD2\n"
sleep 30
echo "exit"
) | telnet ) > name.$NOW.txt
When I make: cat name.date.txt
I get this resulst
hostname1 -
telnet> Trying hostname1...
Connected to hostname1.
Escape character is '^]'.
User Access Verification
Username:
Password:
Welcome to BDCOM P3310C EPON OLT
hostname1>enable
hostname1#terminal length 0
hostname1#show mac address-table
Mac Address Table (Total 311)
------------------------------------------
Vlan Mac Address Type Ports
---- ----------- ---- -----
All 8479.735b.9132 STATIC CPU
300 44d9.e776.d8b7 DYNAMIC g0/3
300 4c5e.0cff.6dea DYNAMIC g0/3
300 d4ca.6d9e.3280 DYNAMIC g0/3
So I need export just this line 1 2 and 4
its like this:
300 44d9.e776.d8b7 DYNAMIC g0/3
300 4c5e.0cff.6dea DYNAMIC g0/3
300 d4ca.6d9e.3280 DYNAMIC g0/3
I don`t need anything before
"Vlan Mac Address Type Ports"
So I make this script:
cat name.date.txt | awk '$1<"ALL"{print $1" ",$2" ",$3" ",$4}'
And I get this result:
hostname1 -
-----------------------------
---- ----------- ---- -----
300 44d9.e776.d8b7 DYNAMIC g0/3
300 0002.9b80.7f28 DYNAMIC g0/3
300 0002.9b65.7b66 DYNAMIC g0/3
300 4c5e.0cff.6dea DYNAMIC g0/3
300 d4ca.6d9e.3280 DYNAMIC g0/3
Who to fix ?
I just export file only this info:
300 44d9.e776.d8b7 DYNAMIC g0/3
300 0002.9b80.7f28 DYNAMIC g0/3
300 0002.9b65.7b66 DYNAMIC g0/3
300 4c5e.0cff.6dea DYNAMIC g0/3
300 d4ca.6d9e.3280 DYNAMIC g0/3
If will be better if I can export to table or csv
Thanks for answers