This script identifies and removes invalid iSCSI targets from a Proxmox VE (PVE) server. It obtains the IPv4/IPv6 addresses of the iSCSI servers, compares them against the IP addresses of iSCSI targets on the PVE server, and removes any invalid targets.
This script is important for maintaining the efficiency and health of iSCSI links in a PVE environment, thereby ensuring optimum storage performance.
You should have root access to the PVE server to install this script.
Follow the below instructions to install and set up this script:
- Download the cleanup script and make it executable.
# Fetch the script
wget -O /usr/local/sbin/iscsi-cleanup https://gist.githubusercontent.com/troykelly/9e55afc26f6295eb3b4202c0f6fa084e/raw/iscsi-cleanup
# Make the script executable
chmod +x /usr/local/sbin/iscsi-cleanup
- Download and move the cron file to
/etc/cron.d
.
# Fetch the cron file
wget -O /etc/cron.d/iscsicleanup https://gist.githubusercontent.com/troykelly/9e55afc26f6295eb3b4202c0f6fa084e/raw/iscsicleanup
# Set appropriate permissions and ownership
chown root:root /etc/cron.d/iscsicleanup
chmod 644 /etc/cron.d/iscsicleanup
- Restart the cron daemon to apply the changes.
service cron restart
- Verify that everything is in place.
ls -l /usr/local/sbin/iscsi-cleanup
ls -l /etc/cron.d/iscsicleanup
This script will automatically run at every system startup and every hour, thereby regularly cleaning up any invalid iSCSI targets.
You can also manually run the script using the following command:
/usr/local/sbin/iscsi-cleanup
The output of this script will be logged to /var/log/iscsi-cleanup.log
.
You can view the logs with the following command:
tail -f /var/log/iscsi-cleanup.log
This command will display the recent log contents and update the display as new entries are added.