Usb virus scanning bash script
Can someone help me out on how to program a bash script to scan a USB upon insert? And in the script I would like to send a notification to user about the progress. Like "Scanning USB for virus". Then "USB Scan Completed?". I would like to be able to open clamtk when the user plugs the USB. Please help?
|
Quote:
The first one is to run a script upon insertion of the usb stick. This can be achieved via udev rules. Showing output to the user can be achieved in many different ways, one of which is the xmessage command. Try experimenting with it on the command line before including it into your script. (Depending on your disto you might have to install it first, on Arch the package name is xorg-xmessage, in Debian-land (so probably also the *buntus) it should be x11-utils Note that when called from within a script that is triggered via udev you won't see anything by default unless you set the DISPLAY environment variable beforehand. Example: Code:
export DISPLAY=:0 You can find out the correct value for DISPLAY by running Code:
echo $DISPLAY Code:
export DISPLAY=:0 |
what is the udev rule to use for usb insert to run the script?????
|
DOES THIS CODE MAKE ANY SENSE::>>>
#!/bin/bash if ! [ -f /etc/udev/rules.d/80-doOnUSBinsert.rules ] then # rule not added cp "$0" /usr/bin/usbscanner chmod u x /usr/bin/usbscanner echo 'SUBSYSTEM=="usb", ACTION=="add", RUN ="/usr/bin/usbscanner & "' | tee /etc/udev/rules.d/80-doOnUSBinsert.rules if [ $? -eq 0 ] then echo 'Rule Successfully added. See file "/usr/bin/doOnUSBinsert" if you wish to edit the command' exit 0 else echo 'ERROR while adding rule' exit 1 fi fi export DISPLAY=:0 xmessage -buttons "Continue" "Scan USB for Virus" clamtk xmessage -buttons "Finish" "USB Scan Complete" |
Look at the link I posted in your other thread
|
Quote:
Your code is hard to read like that, please use code tags and indentation to make the code more readable. Generally speaking I would not mix the installation code with the actual script you want to run upon usb insertion. If this script is run via udev it makes no sense to check whether the rule is installed - it must be, otherwise the script would not be running. You should also not put any of your own scripts into /usr/bin. This is the area where your distro puts its stuff. A better place for your own scripts is /usr/local/bin. That way you can avoid collisions with executables provided by your distro. I have no experience with clamtk, but maybe you can get it to limit its scan to only the content of the USB device? |
i'm a little miffed that op has started another, imo identical, thread, because i posted there and now come here to see that my reply would have been different if i had seen this first.
sound confusing? exactly. i am reporting this as a duplicate thread, but tbh as an admin i wouldn't know what to do with it at this point. |
All times are GMT -5. The time now is 02:54 PM. |