Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

is it possible to log USB connect and disconnect in ubuntu 13.x? Also it will be excellent if it could log the connect/disconnect and email to some email address. Is there any program for that?

Is it possible with some scripting ? If yes please let me have an idea of doing it.

share|improve this question

1 Answer 1

Yes, it is possible to log, in fact is it already logged by the kernel as standard. And you can access it from both the dmesg and the system log. dmesg and cat /var/log/syslog. Be aware this will also send you email on reboot and startup of the system.

Wish you good luck and have fun tweaking it to perfectly suit your needs.

#/etc/udev/rules.d/98-usb-udev.rules
#
# Home crafted udev usb mail rule
#
ACTION=="add", SUBSYSTEMS=="usb", RUN+="/home/yourusername/sendudev.sh"
ACTION=="remove", SUBSYSTEMS=="usb", RUN+="/home/yourusername/sendudev.sh"

-

#/home/yourusername/sendudev.sh
#!/bin/bash
text="$(/bin/dmesg | /bin/grep -i 'usb' | tac)"
/bin/echo -e "Date:$(date)\n\nudev env and reversed log is embed.\n\n$(env)\n\n$text" | /usr/bin/mail -s 'Mail from udev.' -t root@localhost

-

sudo chmod +x /home/yourusername/sendudev.sh
share|improve this answer
    
Thanks for your time. let me try and i will post any difficulties. i am a Linux starter. –  Nikhil M Jan 20 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.