Backup configuration of TP-Link switches

I wrote a script for backup configuration of TP-Link switches.
The script runs on Linux where the TFTP server is running, it is connected via telnet to the switch and the configuration command is sent to the specified TFTP, when the telnet connection is closed, the file is moved to the desired directory, and the last command deletes files longer than 30 days, as more of them I do not need to store.
You can also make a copy of all the files in the cloud every month.
As you can see, before entering a password in the script, you can not pause.

#!/bin/bash
{
echo "PASSWORD";
echo "enable";
echo "PASSWORD";
echo "copy startup-config tftp ip-address 192.168.0.5 filename tplink";
sleep 2;
echo "exit";
sleep 1;
echo "exit";
} | telnet 192.168.0.110

mv /srv/tftp/tplink.cfg /backups/devices/tplink/`date +%Y-%m-%d`_tplink.cfg
find /backups/devices/tplink/ -type f -mtime +30 -exec rm {} \;

Join the Conversation

1 Comment

Leave a Reply

  1. Hello,

    is there any chance you could help me a bit with your script? I have it like this

    #!/bin/bash
    {
    echo “user”;
    echo “12345678”;
    echo “enable”;
    sleep 4;
    echo “copy startup-config tftp ip-address 192.168.200.9 filename tplink-test2”;
    sleep 2;
    echo “exit”;
    sleep 1;
    echo “exit”;
    } | telnet 192.168.200.2

    ls -la /volume2/Backups_all/Switch/tmp/

    and I am running it like this

    root@Sami_NAS:/volume2/Backups_all/Backup_scripts# bash -x ./switch_test.sh
    + cmd=’copy startup-config tftp ip-address 192.168.200.9 filename tplink-test2′
    + echo copy startup-config tftp ip-address 192.168.200.9 filename tplink-test2
    copy startup-config tftp ip-address 192.168.200.9 filename tplink-test2
    + echo user
    + echo 12345678
    + echo enable
    + telnet 192.168.200.2
    + sleep 4
    Trying 192.168.200.2…
    Connected to 192.168.200.2.
    Escape character is ‘^]’.

    ***************** User Access Login ********************

    User:user
    Password:

    T2600G-28TS>enable

    T2600G-28TS#+ echo copy
    + sleep 2
    copy+ echo copy startup-config tftp ip-address 192.168.200.9 filename tplink-test2
    + sleep 2
    $startup-config tftp ip-address 192.168.200.9 filename tplink-test2+ echo exit
    + sleep 1
    $tup-config tftp ip-address 192.168.200.9 filename tplink-test2exit+ echo exit
    Connection closed by foreign host.
    + ls -la /volume2/Backups_all/Switch/tmp/
    total 8
    d———+ 1 root root 34 May 29 19:45 .
    drwx——+ 1 samuellazea users 16 May 29 18:31 ..
    -rwx——+ 1 admin users 3717 May 29 19:27 tplink
    -rwx——+ 1 admin users 3717 May 29 19:45 tplink-test

    As you can see he seems to miss the copy word in $startup-config tftp ip-address 192.168.200.9 filename tplink-test2+ echo exit
    I don’t know what could be the problem here and can’t seem to manage to work around it. Could you please help a bit?
    Thank you in advance