LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > ugjka
User Name
Password

Notices


Rate this Entry

Monitor your laptop with fswebcam

Posted 03-20-2016 at 10:29 AM by ugjka
Updated 03-20-2016 at 10:42 AM by ugjka

This is a little tutorial on how to take a picture from the webcam with systemD timers every 15 minutes.


Install fswebcam a commandline utility for grabbing pics off the webcam

Create a script in /usr/local/bin/ called snap that grabs a pic and put date and time in the filename
Don't forget to chmod +x to make it executable
Code:
#/usr/local/bin/snap 
#!/bin/bash
_now=$(date +"%Y_%m_%d_%H_%M")
/usr/bin/fswebcam ${_now}.jpg
Check man fswebcam for info on how to customize the output. For example you might wanna add --no-banner if you don't need date and time banner on the picture. Also may wanna change the resolution of the pic, by default it is very small

Create a systemd timer that launches the script we created

You can modify these...
OnBootSec=1min Will run the script 1 minute after you boot your machine
OnUnitActiveSec=15min Specifies that we launch the script every 15 minutes afterwards

Code:
#/etc/systemd/system/webcamsnap.timer 
[Unit]
Description=Take a photo every 15 minutes

[Timer]
OnBootSec=1min
OnUnitActiveSec=15min

[Install]
WantedBy=timers.target
This is the accompanying service file that is launched when the timer is reached
Change your User= and Group= to whatever whatever user and group you wanna run this
Specify where to store the pictures with WorkingDirectory= (Your user and group need write rights)

Code:
#/etc/systemd/system/webcamsnap.service 
[Unit]
Description=Take a pic every 15minutes 

[Service]
Type=oneshot
ExecStart=/usr/local/bin/snap
User=ugjka
Group=users
WorkingDirectory=/home/ugjka/Images/WebCamSnap
Now you can enable the timer with systemctl enable webcamsnap.timer
Reboot! And you should have it working!

Check systemctl list-timers to see the timer status
Code:
$ systemctl list-timers 
NEXT                         LEFT      LAST                         PASSED       UNIT                         ACTIVATES
Sv 2016-03-20 17:11:51 EET   7min left Sv 2016-03-20 16:56:51 EET   7min ago     webcamsnap.timer             webcamsnap.service
That's it
Posted in Uncategorized
Views 2374 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    Clever
    And instructive. Now I know how to set up a system service too...
    Thanks
    Melissa
    Posted 03-20-2016 at 04:57 PM by ButterflyMelissa ButterflyMelissa is offline
  2. Old Comment
    You can create a timelapse of your pics with this command
    Code:
    mencoder mf://*.jpg -mf fps=25:type=jpg -ovc x264 -x264encopts bitrate=3200:threads=2 -o outputfile.mp4
    Example output: http://dl.ugjka.net/timelapse.webm
    Posted 03-24-2016 at 03:39 PM by ugjka ugjka is offline
 

  



All times are GMT -5. The time now is 06:31 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration