Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have code to take a picture in a script. I don't understand how to run this script at the time of login. I would like to modify the login process so that:

  • The user gets 3 login attempts.
  • After 3 failures, my script runs to take a picture with the webcam.

Where can I configure what happens when a user tries to log in?

share|improve this question
    
The first part of your question is very vague. What do you mean by "take image from terminal'? The 2nd part largely depends on the OS you're using, so, again, clarification needed. –  tink Feb 20 '13 at 17:58
    
Sir what i want , if the unauthorized user try to login in your system..in response system has to do the things are ...1) provide 3 login attempts 2) capture login person image by webcam and 3) system should turn off –  SachiN Feb 20 '13 at 18:35
    
You still haven't mentioned the OS you're using. –  tink Feb 20 '13 at 19:25
    
Can't you add a line running your code to every user's .login file? –  Lenz Feb 20 '13 at 19:27
    
@Lenz, if he's using Linux & bash that won't make a difference. Again, the answer to the question what OS he's using is essential in answering his question(s). –  tink Feb 20 '13 at 19:40

2 Answers 2

Yep, we need the OS version (Linux? BSD?...) the distribution (Fedora, Debian, OpenSuSE?) the version of the distro... etc.

Without that information is really hard to tell...

Anyway, assuming that you are using some flavor of Linux and that the distribution has GStreamer framework installed or can be installed you could use GStreamer command line tools to do what you want. You actually don't need to be running an X (graphical) session AFAIK:

Single frame capture with gstreamer

Once you try the above command and it works it should be easy to create a script that reads /var/log/faillog and look for failed login attempts and then you can do whatever you need.

Just some notes:

  • You'll need to have v4l (Video For Linux) support compiled in your kernel
  • Make sure your webcam is supported by v4l first. Check your distro docs.
  • Most probably you'll need root permission execution on your script so that you can turn off the computer
  • You may need to make the script a service so that it is executed at startup and runs in background no matter what...
share|improve this answer
1  
The question isn't about this part, SachiN has it already. The question is how to fit this into PAM (no, it can't be in a startup script: it needs to be triggered on a login attempt). –  Gilles Feb 21 '13 at 1:43
    
.My system is single desktop machine using OS Ubuntu 12.04... #!/bin/bash ts=date +%s ffmpeg -f video4linux2 -s vga -i /dev/video0 -vframes 3 /home/sachin/Desktop/vid-$ts.%01d.jpg shutdown -f exit 0 This is my script its executable at terminal.it working takes image and shutdown properly, now what i want it should run on login failures after 3 attempts,supposing that no other user on system. –  SachiN Feb 22 '13 at 5:26

On most (but not all) unix systems, PAM handles authentication, so you would need to plug your script into the PAM infrastructure. You'll need to read some parts of the PAM administrators' guide.

The PAM configuration is in /etc/pam.conf or /etc/pam.d/*. You'll want to run your script in the auth stack. Jump over it when authentication succeeds (something like [success 1] on the last required component) and make it a requisite entry.

You don't specify what you want to base your number of login attempts on. Per user? Per unit of time? Depending on the answer, you may need to include additional PAM configuration or do more work in your script.

Turning off the machine is rather silly. What if it was doing something useful, like a background computation or a remote user? The rate of login attempts at the console isn't worrying anyway, unless someone has brought hardware to automate them, in which case they can grab your hard disk and run.

share|improve this answer
    
Sir i can understand stealing of hard disk.My system is single desktop machine using OS Ubuntu 12.04...#!/bin/bash ts=date +%s ffmpeg -f video4linux2 -s vga -i /dev/video0 -vframes 3 /home/sachin/Desktop/vid-$ts.%01d.jpg reboot -f exit 0 –  SachiN Feb 22 '13 at 5:15

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.