I'd like to take and save a picture from the webcam, every time someone tries to login into the system and fails. I know I can do that with:
mplayer -vo png -frames 1 tv://
The question is: How can I trigger this command when someone fails to login w/ LightDM?
Best Answer
Explanation
One way is to make use of the Authorization Log.
On a failed login attempt, a record will be appended to the
/var/log/auth.log
file and the last line will contain something like:If you constantly monitor the file for modification and check if the last line contains the keyword failure with for example
grep failure
then you know a failed login attempt has just occurred and you can run whatever command you want based on this action.Solution
You can monitor the last line of the
/var/log/auth.log
file with a script like this:Or even better, you can install
inotify-tools
and useinotifywait
to monitor the file instead of thesleep 1
and the script will be like this:inotify-tools
can be installed with the following command:Implementation
To run this solution as a system service, please follow these steps:
Copy and paste the script code above ( without
echo "failed login"
as I added this line for debugging purposes only ) into a file in your home directory and name itTakePicture.sh
and save the file.Make the shell script file executable by running the following command in the terminal:
USERNAME
with your username and save it by pressing Ctrl + X then press Y then press Enter :Notice:
The authorization Log will contain all sorts of failed logins or authentications ( ie. GDM, SSH, terminal user authentication, sudo, ... etc. ).
If your aim is just to activate the script when an actual physical login happens ( ie. someone is sitting infront of your computer, using your keyboard and looking at your screen ), then you need to change the above if statement to be like this:
if GDM is your login manager. This way the script will only be triggered if an actual failed physical login happens.
Best of luck