I want a script that dumps the log and starts logging on it as soon as a usb mass storage is plugged (with the file 'OKdump' on it).And if anything abnormal(Like a error that is visually present) is detected i want it to take a screenshot and save it on the same drive.
Use Udev. Udev is a device manager daemon. Amongst other things it is responsible for naming your devices. You can define udev-rules by putting files with a certain syntax in the rules directory. The rules can do many things - in particular they can run scripts, when a certain device is connected.
How to solve your problem:
First you need to gather information on your device. Let's say you connected it, and know it goes under the name
The command will output information about your device. It's a rather lengthy. You need to find something that identifies the device uniquely. That could be a serial like
Once you have found a unique identifier create a file in
This is an actual udev file I am using. It has three rules in it. Every line is a rule of it's own. The first line runs a script to create a decrypted device whenever an encrypted disk is connected. The second line invokes the same script with different options in the event the decrypted device is removed. The third line sets permissions for another related device.
Most likely you will only need the first line. Delete the rest and insert the right serial (or compination of parameters you picked to identify your device).
Explanation of my file:
I will not give more detail, as there are excellent tutorials on udev rules. What you read here should be enough to get stared though.