Sunday 3 February 2019

Automatic script run on a specific date and time:


Run a script on a specific date and time:
Linux Crontab Format:
MIN HOUR DOM MON DOW CMD

 Crontab Fields and Allowed Ranges:

Field Description        Allowed Value
MIN   Minute field 0 to 59
HOUR        Hour field   0 to 23
DOM  Day of Month      1-31
MON  Month field 1-12
DOW Day Of Week      0-6

Make New Script Command:
sudo nano launcher.sh

Script:

cd /
cd home/pi/data
sudo python3 file.py
cd /

To exit the editor, press
ctrl+x

To save your changes press the letter
 “Y”
then hit
enter

Script File permission Command:
sudo chmod 755 launcher.sh


Command for Script run in particular date and time:
sudo crontab –e

Code for Script run in 10th June 08:30 AM: Due to this command Script by default run in this specific time:

30 08 10 06 */home/pi/data/launcher.sh >/home/pi/logs/cronlog.log 2>&1

To exit the editor, press
ctrl+x

To save your changes press the letter
 “Y”
then hit
enter
sudo reboot

Command for Script run in every 30 min:
sudo crontab –e

Code for Script run in every 30 min: Due to this command Script by default run in every 30 min:

*/30 * * * * /home/pi/data/launcher.sh >/home/pi/logs/cronlog.log 2>&1

To exit the editor, press
ctrl+x

To save your changes press the letter
 “Y”
then hit
enter
sudo reboot


Example: By default captue pic in specific data and time:

Code:
Command for Make new file
sudo nano file.py

import pygame
import pygame.camera
import requests
import os
import sys
pygame.camera.init()
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"image.jpg")

Command for Make New Script file
sudo nano launcher.sh

Script:

cd /
cd home/pi/data
sudo python3 file.py
cd /

To exit the editor, press
ctrl+x

To save your changes press the letter
 “Y”
then hit
enter

Command for open crontab:
sudo crontab –e

Code for Script run in 15th June 10:50 AM:

50 10 15 06 */home/pi/data/launcher.sh >/home/pi/logs/cronlog.log 2>&1

To exit the editor, press
ctrl+x

To save your changes press the letter
 “Y”
then hit
enter

0 comments:

Post a Comment

if you have any doubt please let me know