LibreNMS bulk delete

There is a php script in /opt/librenms/ that lets you delete a host from the command line.

sudo /opt/librenms/delhost.php

Replace with the hostname/ip address of the host you want to delete.

Delete Multiple Hosts

First you’ll need to get a list of devices you want to remove.  You can do this by viewing the devices in the LibreNMS MySQL database;


$ mysql -u librenms -p librenms
MariaDB [librenms]> select hostname from devices;
| hostname |
| |
| |
| |
| |
4 rows in set (0.00 sec)
MariaDB [librenms]> exit

Put all the IP addresses you want to remove into a file and run the following for loop.  Replace “remove_ip.lst” with the name of your ip list file.

for i in `cat ~/remove_ip.lst`; do sudo /opt/librenms/delhost.php $i; done

Upload ssh key to multiple servers automatically

Here is a quick script I created to automate copying a ssh key to multiple remote servers.

Basic command – the command uses sshpass to upload the ssh key to a remote server, this allows you to execute the command and not have to enter in a password to authenticate.

sshpass -p password ssh-copy-id -o StrictHostKeyChecking=no admin@remotehost




for host in `cat ${remotehosts}`
sshpass -p${password} ssh-copy-id -o StrictHostKeyChecking=no ${username}@${host}
echo "Uploaded key to " ${host}

echo "Finished!"


Using the script

  1. Download here.
  2. Make it executable
    chmod +x
  3. Edit the script and change the username and password.
  4. Create a file that contains each host’s IP address or hostname.
  5. Run script (change hostlist.txt to your host list you created in step 3.)
    ./ hostlist.txt
  6. Wait for the script to finish.


chmod +x
sed -i s/admin/bob/g                      <-- Change username - you can just manually edit the file,
sed -i s/MyCoolPassword123/password/g     <-- Change password - it might be easier than using sed
echo "" >> host.txt                     <-- Add to the host list
echo "Bob" >> host.txt                               <-- Add hostname bob to host list
./ host.txt                                <-- Upload ssh key to all host's in the host file i.e. "bob" and ""