Back to Resources
Level
Script
Security
Unauthorized or unaccounted-for USB drives can pose significant security threats, from data theft to malware injection. Monitoring for USB drive insertions is essential for organizations that want to safeguard their systems and maintain compliance with data protection policies.
This script quickly checks whether any USB storage devices are currently connected to the system. If it detects a USB drive, it returns a simple "ALERT" message, which you can capture with a script-based monitor in Level to trigger a real-time notification and log the event.
You can also build an Automation in Level with a schedule trigger to regularly check for USB drives and act on any findings—this can include disabling the port or generating a security ticket for further investigation.
1#!/bin/bash
2
3# This resource is provided as a convenience for Level users. We cannot
4# guarantee it will work in all environments. Please test before deploying
5# to your production environment. We welcome contributions to our community
6# library
7
8# Level Library
9# https://level.io/library/script-linux-monitor-usb-drive
10
11# Look for USB Drives
12USBDrivePresent=$(lsblk -o NAME,TRAN | grep "usb" | awk '{print $1}')
13
14if [ -n "$USBDrivePresent" ]; then
15 # If USB drive is present, send console message for Level to alert on
16 echo "ALERT"
17fi
Linux Monitor - USB Drive
This script checks for the presence of USB drives on a Linux system by scanning for devices identified as USB. If any USB drive is detected, it outputs an "ALERT" message, designed for integration with monitoring systems to notify administrators of potential unauthorized device connections.
Bash
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.