Last active
May 16, 2022 08:22
-
-
Save thewh1teagle/331d0cf0e0ca7253fb748f2c440740e5 to your computer and use it in GitHub Desktop.
watch changes under /dev directory in linux.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# will be ls /dev | |
# 2 files to compare before and | |
# after plug in/out the device | |
before="/tmp/before.txt" | |
after="/tmp/after.txt" | |
ls --color /dev > $before && clear | |
echo "############################" | |
echo "# Welcome to udev watcher! #" | |
echo "############################" | |
echo "1. Insert/remove device" | |
echo "2. Press any key to continue" | |
read -n 1 -r -s | |
clear && echo "Scanning..." && sleep 2 | |
ls --color /dev > $after | |
result=$(diff $before $after) | |
clear && echo "" | |
if [ "$result" = "" ]; then | |
echo "Not found any device changes" | |
else | |
if [[ $result == *">"* ]]; then | |
echo "New devices added:" | |
else | |
echo "Devices removed:" | |
fi | |
echo $result | |
fi | |
# CLEAN | |
rm -f $before $after |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment