Automating & Scheduling Tasks

Introduction to Raspberry Pi 4 Linux Fundamentals for Raspberry Pi
7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.30
List Price:  €93.30
You save:  €27.99
£55.85
List Price:  £79.79
You save:  £23.94
CA$95.55
List Price:  CA$136.51
You save:  CA$40.95
A$106.62
List Price:  A$152.32
You save:  A$45.70
S$95.18
List Price:  S$135.97
You save:  S$40.79
HK$547.80
List Price:  HK$782.61
You save:  HK$234.80
CHF 63.79
List Price:  CHF 91.14
You save:  CHF 27.34
NOK kr769.72
List Price:  NOK kr1,099.65
You save:  NOK kr329.92
DKK kr487.07
List Price:  DKK kr695.84
You save:  DKK kr208.77
NZ$117.16
List Price:  NZ$167.38
You save:  NZ$50.21
د.إ257.06
List Price:  د.إ367.24
You save:  د.إ110.18
৳7,690.80
List Price:  ৳10,987.33
You save:  ৳3,296.53
₹5,841.61
List Price:  ₹8,345.51
You save:  ₹2,503.90
RM333.81
List Price:  RM476.90
You save:  RM143.08
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,508.81
List Price:  ₨27,870.93
You save:  ₨8,362.11
฿2,590.69
List Price:  ฿3,701.15
You save:  ฿1,110.45
₺2,265.11
List Price:  ₺3,236.01
You save:  ₺970.90
B$358.13
List Price:  B$511.64
You save:  B$153.51
R1,311.83
List Price:  R1,874.13
You save:  R562.29
Лв127.74
List Price:  Лв182.50
You save:  Лв54.75
₩96,362.95
List Price:  ₩137,667.26
You save:  ₩41,304.30
₪263.40
List Price:  ₪376.30
You save:  ₪112.90
₱4,038.52
List Price:  ₱5,769.57
You save:  ₱1,731.04
¥10,910.67
List Price:  ¥15,587.34
You save:  ¥4,676.67
MX$1,198.75
List Price:  MX$1,712.57
You save:  MX$513.82
QR255.51
List Price:  QR365.03
You save:  QR109.52
P964.58
List Price:  P1,378.03
You save:  P413.45
KSh9,448.65
List Price:  KSh13,498.65
You save:  KSh4,050
E£3,349.02
List Price:  E£4,784.52
You save:  E£1,435.50
ብር4,021.76
List Price:  ብር5,745.61
You save:  ብር1,723.85
Kz58,375.85
List Price:  Kz83,397.65
You save:  Kz25,021.80
CLP$66,547.19
List Price:  CLP$95,071.49
You save:  CLP$28,524.30
CN¥506.87
List Price:  CN¥724.13
You save:  CN¥217.26
RD$4,108.14
List Price:  RD$5,869.02
You save:  RD$1,760.88
DA9,408.68
List Price:  DA13,441.55
You save:  DA4,032.87
FJ$157.85
List Price:  FJ$225.51
You save:  FJ$67.66
Q545.03
List Price:  Q778.65
You save:  Q233.61
GY$14,660.48
List Price:  GY$20,944.44
You save:  GY$6,283.96
ISK kr9,815.39
List Price:  ISK kr14,022.59
You save:  ISK kr4,207.20
DH707.84
List Price:  DH1,011.24
You save:  DH303.40
L1,238.76
List Price:  L1,769.74
You save:  L530.97
ден4,020.67
List Price:  ден5,744.06
You save:  ден1,723.39
MOP$565.05
List Price:  MOP$807.26
You save:  MOP$242.20
N$1,322.15
List Price:  N$1,888.87
You save:  N$566.71
C$2,578.94
List Price:  C$3,684.35
You save:  C$1,105.41
रु9,342.64
List Price:  रु13,347.21
You save:  रु4,004.56
S/263.24
List Price:  S/376.08
You save:  S/112.83
K270.50
List Price:  K386.44
You save:  K115.94
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,856.98
List Price:  ZK2,652.95
You save:  ZK795.96
L324.92
List Price:  L464.20
You save:  L139.27
Kč1,643.69
List Price:  Kč2,348.23
You save:  Kč704.54
Ft25,598.69
List Price:  Ft36,571.12
You save:  Ft10,972.43
SEK kr764.15
List Price:  SEK kr1,091.69
You save:  SEK kr327.54
ARS$61,224.11
List Price:  ARS$87,466.76
You save:  ARS$26,242.65
Bs485.98
List Price:  Bs694.29
You save:  Bs208.30
COP$277,111.33
List Price:  COP$395,890.30
You save:  COP$118,778.96
₡35,607.40
List Price:  ₡50,869.89
You save:  ₡15,262.49
L1,730.46
List Price:  L2,472.19
You save:  L741.73
₲521,774.38
List Price:  ₲745,423.92
You save:  ₲223,649.54
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł282.40
List Price:  zł403.45
You save:  zł121.04
Already have an account? Log In

Transcript

Video, automating and scheduling tasks. In this video, we will cover basic shell scripting to automate tasks and scheduling of tasks using crontab. It is essential to know about shell scripting to automate tasks in Raspberry Pi four. A shell is a special user program that provides an interface to the user to use operating system services. Shell accepts human readable commands from the user and convert them into something which the kernel can understand. It is a command Language Interpreter that executes commands from input devices, such as keywords or from files.

The shell gets started when the user logs in or starts the terminal. A shell is kind of like a spell that you come up with on the spot to solve some problem. Then scripts are a lot like the pages of a spell book, where you keep the incantations That you found really useful. To speak with a shell, a special programming language, called bash was invented. shell scripts allow you to automate pretty much anything you can do on the Linux command line. A shell script is simply a text file containing a series of shell commands that are executed one by one, as if they were input directly on the command line.

They can save time if you need to execute lots of commands at once. Or if you want to execute commands automatically, like when the pipe boots up. The shell language is a high level programming language. It's more removed from system and memory than lower level languages like assembly or C. This basically means that it has commands and functions to perform tasks that would otherwise take a lot of code to execute. So what can a shell script do? shell scripts are great if you need to enter long sequences of commands into the command line to do something.

Most operations can be accomplished with a single command. If you know how to write a shell script for read. For example, they can be used to control what happens when the computer boots up. Start applications. When an event occurs, use the output of one command as the input for another command, batch, rename and move files. batch convert file formats.

One handy feature of a shell script is the ability to create pipes. A pipe allows the output of one command to be forwarded to the input of the next command. Pipes can be used with as many commands as you want. shell scripts are simply an executable txt file with extension.sh. In this example, we'll write a simple Hello World. script to demonstrate how to create and run them.

To begin, log into your Raspberry Pi and navigate to the directory where you want to save the script. Then open the nano text editor and create a new file named Hello hyphen world.sh. By entering this the command prompt sudo nano Hello hyphen world.sh. Now enter this code into the text editor. The first line of this program slash exclamatory forward slash bin forward slash sh is called a shebang. This test the bash shell to execute the commands in the script.

Every script shell you create will need this on the first line of the script. Exit and save the file in nano by pressing Ctrl X to save and exit. Next we will need to make the helloworld.sh file executable to do that To this at the command prompt sudo ch mod plus x Hello hyphen world.sh. Now that the shell script has been made executable, we can run it. Navigate to the directory where the file is saved and enter either of this, the words hello world will be printed to the line below the command prompt. This hello world script isn't particularly useful, but it will show you the basics of how to create and run a shell script.

Next, shall we look at how to schedule a task? Well, you will have to use a tool called crontab that allows you to launch tasks with a user you want when starting the raspberry or whenever you want. cron is a service automatically started at each boat of the Raspberry Pi, which allows the user to execute shell commands. What we are going to see today is how to tell cron to enter execute our command or script when needed. A cron tab is a tool that will allow us to list what we want to start in a format understandable by the cron service. A cron tab will contain two things, the list of commands to run, when to run them.

Crontab is also a command. Here's the syntax to open the crontab crontab hyphen E. First thing, you have to choose an editor, I advise you to stay on nano. So keep the default choice and hit enter. That's it. You're now in the editor of crontab and can be a little intimidating if it's the first time you access it. I'll explain what to do.

First of all, all the lines starting with a hash arguments, they do nothing and we can ignore them. Our changes will be made at the end of the file. You are probably wondering what the five stars mean? The syntax of an entry in the crontab is as follows. Now that you understand the theory, let's look at a simple example. To be sure it's clear.

Imagine that you want to run the Hello World script. Every wetness day at midnight. You must add a line like this 00 asterisk asterisk, three forward slash home, forward slash pi forward slash desktop, forward slash Hello world.sh. There are a lot of flexibility with shadowing in crontab like launch script at fixed hours. Start a script during a fixed interval. Schedule a script only during the weekdays.

You can also start something on boot. Example scripts for all the above cases are given in the resources. Now I will give you an activity you have to create a shell script to do apt hyphen, update, and apt hyphen upgrade Use crontab to make it start every time on board. This will make sure that your Raspberry Pi will stay updated without manual intervention. Summary In this video we have covered the following topics, basic shell scripting to automate tasks, scheduling tasks using crontab section summary. In the section we have covered the following topics, basics of Linux, basic Linux commands, advanced Linux commands, automating and scheduling tasks.

In the next section, we will learn basic python programming

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.