Linux Log All SCSI Events To Syslog

In Linux, you can use the udev subsystem to log all SCSI events to the system log using syslog. Here are the steps to set up logging of SCSI events to syslog:

  1. Create a new file called /etc/udev/rules.d/99-scsi-log.rules with the following contents:
ACTION=="add|remove", SUBSYSTEM=="scsi", RUN+="/bin/logger -t udev -p user.info 'SCSI $env{ACTION} for $env{DEVTYPE} $env{ID_MODEL_FROM_DATABASE} ($env{DEVNAME})'"

This udev rule logs all add and remove actions for SCSI devices, and includes the device type, model, and name in the log message. The log message is sent to the udev tag in the syslog with the user.info priority.

  1. Reload the udev rules using the following command:
sudo udevadm control --reload-rules

This command reloads the udev rules and applies any changes made to the rules.

  1. Test the logging by plugging in a SCSI device and checking the system log. You can use the dmesg command to view the system log:
dmesg | grep udev

This command filters the system log for messages with the udev tag.

With these steps, you have successfully set up logging of SCSI events to syslog in Linux. This can be useful for troubleshooting SCSI device issues and monitoring the addition and removal of SCSI devices.

Leave a Comment