CSC8512 Assignment 2: Linux Task Schedulers (Cron, Anacron, Systemd)

Verified

Added on  2025/05/01

|13
|2940
|328
AI Summary
Desklib provides solved assignments and past papers to help students understand complex topics.
Document Page
CSC8512 - ASSIGNMENT 2
Student name:
Student ID:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Answer 1
Cron, Anacron & Systemd
Cron, anacron & Systemd are some task schedulers offered by Linux. The comparison among
the three schedulers is described below:
These task schedulers help to execute the tasks in an organized manner. Linux framework's
Cron scheduler allows system administrator to perform time-bound scheduling. Cron service
cannot use seconds as a unit of time for its scheduling activity and uses minutes to give the
minimum time that will be required to finish a job. The schedule for the jobs can be
programmed in a text file which saves the commands, it is generally stored by the name
“schedule.txt” and the command “crontabschedule.txt” can be executed to let the cron
scheduler know that it has to use the text file for all programmed tasks. Cron is instructed to
provide the required results to the final user who is responsible for scheduling the job
activities using the MAIL variable. It also provides the admin information about the probable
occurrence for fizzled tasks or undertaking. /etc/crontab is the default system crontab file and
the users are also provided with options to create their own crontab files.
With anacron, commands can be executed periodically with frequency set for each time it
runs. It functions a little bit different as compared to cron, assuming that the system wouldn’t
be running 24x7. Anacron is not a daemon service and suits to both desktops and laptops as it
assumes what is stated above. When the system is turned OFF, all current executing tasks are
stopped & run out of schedule and executed afterwards when the system is turned back ON.
Anacron has the greatest disadvantage as the activities involved in anacron are planned to be
performed daily. However, still if it is used, we can be sure that when the system is turned on,
the backup script starts getting executed.
Systemd is viewed as a more successful tool in executing scheduled tasks compared to
anacron and cron. Ken Thompson developed Cron in the late 1970s and created systemd as a
substitute in 2010. System timers are highly accurate when compared to crontab. Task
planning differs in cron, systemd & anacron in terms of format. Systemd utilizes one such
service to fulfil both the timer & the job. Systemd is also responsible for turning this service
ON.
Let’s look at how system is better in comparison to other scheduler services available with
Linux-
1. The greatest advantage is uniformity in the context of execution. One major problem
with using "Cron" & "anacron" is how tasks would be executed in an environment
that isn't exactly similar to the shell, meaning that is a major probability of things not
going as planned due to a variety of factors like, different variables, paths, etc., but
error handling a major problem as you couldn't separate or test the scripts in the same
sense in which they would be running.
2. Systemd provides a better job status. “systemctl status your-service” can be used for
checking the status of previously run services.
Document Page
3. The administrator can use “systemctl list-timers” to fetch a brief summary about
timers with details about when were they executed last and when they will be run
next.
4. The execution of jobs with systemd is a lot easier as compared to cron & anacron.
5. The jobs of other units can be triggered with systemd.
Some cons of using systemd are as follows-
1. Systemd does not work very well along other init managers & won’t run ever on
BSD.
2. All the daemons are grouped and deeply integrated, making it tough or haphazard
to use alternatives. Systemd developers do not appear to be interested in
developing a system that includes autonomous components that can be replaced.
3. The sytemd scheduled jobs are difficult to configure.
4. Understanding the system units, working and its parameters is quite difficult and
time consuming.
Configuring schedulers to Run Date Command Daily, Weekly & Monthly
Configuring cron
For cron jobs, “crontab -e” is used if edits are to be made.
<<screenshot here>>
<<commands>>
Below is a representation of insertion of lines into the file:
0 0 * * * date >> home/student1/time-result.txt
# the date output is stored in format time-result.txt everyday
0 0 * * 0 date >> home/student1/time-result.txt
# Output command is stored to time-result.txt each week.
0 0 1 * * date >> home/student1/time-result.txt
# date output is stored to the file monthly.
The knowledge of these five numerical is necessary while the last part contains the command
which is executed. The data output for this file is stored in: /home/student1/time-result.txt.
The command can be understood if divided further.
Description Values
MIN 0-59
Hour 0-23
Day 1-31
Month 1-12
Document Page
Day of week 0-7
command Executable command
Example: The output shows the scheduled backup. The backup is programmed for all user
accounts for the allocated time of 5 am each week.
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
In order to tabulate the scheduled events in Linux “crontab -l” is used.
<<screenshot>>
Final result will be produced as:
<<screenshot>>
Configuring Anacron To Run Date Command Daily, Weekly & Monthly
“/etc/anacrontab” is edited with a text editor. The follwing lines will be added to the file then-
1 15 daily_date date >> /home/student1/time-result.txt
#executing the job everyday with a delay of fifteen minutes.
7 15 weekly_date date >> /home/student1/time-result.txt
# executing anacron task weekly with a delay of fifteen minutes
@monthly 15 monthly_date date >> /home/student1/time-result.txt
# executing anacron task monthly with a delay of fifteen minutes
The main (first) field of Anacron represents repeating time. The everyday (1), every week
(7) and monthly (30) value can also be set.
The second field in the layout of anacron denotes a delay in jtask execution once the
machine has started working. Value 15's importance is to direct the system to hold for 15
minutes before starting the execution process.
The third sector represents the timeline file of the job. Total task execution details are
tracked in the /var / spool / anacron file.
/etc/anacron tab is depicted here:
<<screenshot>>
Configuring Systemd To Run Date Command Daily, Weekly And Monthly
Step 1- Timedata.service formation
The file /etc/systemd/system/timedata.service will be altered and the following lines will be
added to it:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
[Unit]
Description= Prints date into /home/student1/time-result.txt
[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c '/usr/bin/date >>/home/student1/time-result.txt’
The screenshot below shows how it is done:
<<screenshot>>
Step 2- Timedata.timer formation
The file /etc/systemd/system/timedata.timer will be altered by adding these commands to it
[Unit]
Description= Runs timedata.service daily
[Timer]
OnCalendar=*-*-* 00:00:00
(For OnCalendar notes ‘*-*-* 00:00:00’ represents daily)
The image below depicts it-
<<screenshot>>
Step 3- Start of timer with the command systemctl start timedata.timer
<<screenshot>>
Step 4- For the weekly timer setting, OnCalendar value is altered. Below screenshot shows the
same-
<<screenshot>>
(OnCalendar=Mon *-*-* 00:00:00 is the value which shows once in a week i.e Monday)
Step 5- In order to set the timer to run the service in monthly order, the explanation and
Oncalendar value should be set in the appended screenshot.
<<screenshot>>
(the first day of month is depicted by the value OnCalendar=*-*-01 00:00:00)
Document Page
Answer 2
I. The file title should be displayed in the format specified i.e. YYYYMMDHM.tgz.
The date command can be used to give the file the exact name. Use the command
"date" in Linux systems to print the current system date and time. More useful options
are outlined below:
%Y- YYYY
%m- MM
%d – DD
%H- HH
%M –MM
filename=$(date +"%Y%m%d%H%M" is a variable which is defined to fetch the
required file-name.
After the variable is declared, “touch $ filename” is used to create the file.
<<screenshot>>
ls -l is used to view the file that has been created
<<screenshot>>
II. In order to destroy the files which are older than thirty days, the following command
is used: find -mtime +30 -exec rm {} \;
To search a file which is older than thirty days, –mtime + 30 is used and exec rm{} is
used when the file is needed to be removed.
In order to close the command ‘\’ is used.
To print the list of all files older than thirty days, -print is used. –mtime +30 –print
command’s output is depicted with the screenshot below:
<<Screenshot>>
All the files stored in the boot directory are shown with the command and it is shown
in the above screenshot.
sudofind . –type f –iname “*.txt” –mtime +30 –print can be used to print a list of all
files which are older than thirty days and ending with the extension .txt
The screenshot shows the execution of this command:
<<screenshot>>
III. “rsync -avh --delete ~ $filename ” is the command used to take an incremental
directory backup & rysnc can be used with it.
-a is used for archive mode
-v for showing verbose O/P
-h for displaying numerical values which can be interpreted by humans
--delete for deleting the files present into the source directory
Document Page
filename=$(date +"%Y%m%d%H%M")
<<screenshot>>
The above screenshot shows the output when a successful backup of home directory is
performed.
<<screenshot>>
new_file.txt file generation in the home directory of the current user.
<<screenshot>>
The whole backup was not taken & rsync was executed again after updating the incremental
file.
<<screenshot>>
IV. To keep the backup of the home directory, the script shown below is run
#!/bin/bash
filename=$(date +"%Y%m%d%H%M")
# Current date & time are assigned in the required format which is
YYYYMMDDHHMM
rsync –avh –delete ~$filename
# rsync is used to take a backup of the home directory of the current user and stored to the
specified folder in the same format YYYYMMDDHHMM
tar –zcvf $filename.tgz $filename
# Folder must be compressed in order to make a YYYYMMDDHHMM.tgz file
rm –R $filename
# When the .tgz file is generated, there is no longer a need of the folder thus it must be
deleted.
find . –type f –iname “*tgz” -mtime +30 -exec rm {} \;
# Remove the .tgz file older than thirty days after searching for it.
The backup of the contents of homebackup.sh script is shown below
<<Screenshot>>
Script can be seen here
<<Screenshot>>
Following is the screenshot of the execution:
<<Screenshot>>
Finally, the backup file filename.tgz is created
<<Screenshot>>
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Answer 3
Telnet is used to communicate remotely as an unsecure terminal access protocol. Telnet does
not require the use of encrypted passwords & user-names but may be open to attack by
malicious users. The authentication split could provide the attacker with illegal access to the
system. This is why SSH (safe shell) is used, because before it is transferred through the wire,
it encrypts both the user-name & password information.
Key authentication:
Both the client & its server constitute public key authentication. Every customer is intended
to have a private & public key pair. Either with RSA or DSA this key pair is generated. There
is a correct listing of clients ' public key for all permitted keys on the server. For the
encryption reason that is further deciphered by the client with the use of public client key,
Clients use their private key (secret key).
Password authentication:
There is a need to enter SSH user-name and pass for the SSH client who wants to
connect with the server.
The user will now be provided access to the server.
On the basis of above provided username and password SSH client is verified.
Host based authentication:
The server must maintain a list of legitimate hosts including the public key of each host to
connect with the SSH server. With SSH, the possibility of an attack called a "Man-in-Middle"
is minimized. Situation of MITM where sufficient cooperation exists between two servers,
and the hacker intercepts entire connectivity among them. If the attacker is still allowed to
use this file in some scenario, the file's privacy stays as hashings are used in these files for
saving hosts information. The file contains: names of the hosts, markers (optional), type of
key, key-encryption in 64base format. These fields are separated by spaces.
SSH Configuration with No Passwords – Public Key Authentication
Instructions to use public keys in SSH-
Step 1- The ssh-keygen command used for the generation of rsa keypair (Private Public Key
Pair) is the one used by the server controlled SSH client. The Public Key was saved in the
/home / student1/.ssh / id rsa.pub file as shown in the attached screenshot below.
<<Screenshot>>
Step 2- The generated public keys are displayed with cat ~/.ssh/id_rsa.pub command.
<<Screenshot>>
Step 3- SSH client keys will now be copied which can be performed in two methods.
Document Page
Manually copying the public key to server’s ~/.ssh/authorized_keys.
Or by using the sudossh-copy-id <user@hostname> command
<<Screenshot>>
Step 4- Only after copy of the keys will the SSH server be accessed by the
"sshstudent1@192.168.1.31" command. The following figure shows that without a password
requesting window, we can log into a SSH server.
<<Screenshot>>
Step 5- To access the SSH server the IP address 192.168.1.31 is deployed and after it we will
modify /etc / ssh / sshd config for the disabled authentication of passwords, as the
authentication of public keys has now been activated.
<<Screenshot>>
Step 6- Password authentication option in /etc/ssh/sshd_config should be set to NO.
<<Screenshot>>
Document Page
Answer 4
Encrypted file systems are mounted and unmounted using Cryptmount. Using cryptmount,
mounting & unmounting of encrypted file systems is performed. At least once, any simple
user can also mount and unmount encrypted file system configuration. Cryptmount utility
could be utilized on a single disk in order to set up many encrypted file systems.
For mounting a drive following command can be used “cryptmount –m <filesystem name>
For unmounting, –u <filesystem name> can be used.
Device mapper system & cryptoloop hardware driver in Linux operating systems can be used
to model encoded filesystems. The main target of the cryptoloop is dm-crypt which exists
in2.6 kernel series. Cryptmount uses a device mapper, dm-crypt, to map encrypted file
systems.
To encrypt a 5 gigabyte file system which was created in a flash-drive, the following
commands need to be executed-
Step 1- The command dd is used for the creation of the file because the user needs 5 GB of
encrypted file system, the file is generated with a block size of 1 MB and 5120 MB (5 GB) &
the command that is used in the creation of the file system is displayed in the preceeding
screenshot.
Step 2- /etc/cryptmount/cmtab is edited with a Nano editor and that is depicted in the
following screenshot:
<<screenshot>>
Step 3- All configurations are stored in the "cmtab" file. The key creation { 255 bit(32 MB) }
is done with the command in the accompanying screenshot following these configurations.
The following command. After using this command, users may create a new password:
Step 4- Before the file system is generated, the command can be executed to prepare the
image
<<screenshot>>
Step 5- In order to create the file system, mke2fs command is used.
<<screenshot>>
Step 6- Mapper device is set free using the command shown in the following Figure
according to the instructions given to Cryptmount. cryptmount –l is a file system that lists all
the current files that can be viewed in the following image:
<<screenshot>>
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Step 7- File system mounting takes place using the "cryptmount –m USBFlash" command.
Mounted drive display is performed using cryptmount command –m USBFlash. The below
screenshot shows USBFlash with a 5 giga-byte capacity:
<<screenshot>>
Step 8- cryptmount –u USBFlash” command is used to unmount, when it has been used as a
drive.
<<screenshot>>
UUID used in mountpoint so that it has a identifiable different name
The same mountpoint is also available for each drive, that is- work & home, in every
machine.
/home/crypt mountpoint of flash-USB is represented below
<<screenshot>>
Crypt isn't a name like that, too. UUID is a Universal Unique identification which
provides a single mountpoint for each one and all systems, as each UUID drive is
worldwide unique. The command used for displaying UUID is blurred in Linux.
Drive mountpoint is set /mnt/<UUID of flash drive>
Key file
The coded file system's key file should be kept safe from unauthorized user access. Key
file must be permitted to an encoded file system so that the standby file is kept safe in a
possible manner by using the built-in key format to create the USBFlash key. This key
file is considered very safe from all unprocessed & unencrypted files. In addition, all
necessary installations shall be considered suitable.
User instructions-
The key file allows access to the encoded file system. If this isn't the desired dev
value, the dev value should be the memory stick position and the disks (flash drives)
cannot be used on any other system.
“blkid” is used to view the UUID of the physical drive.
<<screenshot>>
USB drive is connected to the home system.
Cryptmount -l is the command used for mounting the file-systems which are capable
of being mounted.
<<Screenshot>>
In order to mount the USB flash drive, –m <file system name > is used.
<<screenshot>>
“cryptmount –u <filesytem name>” should be used to unmount the flash drive.
Document Page
<<screenshot>>
lsblk is used to make sure that the flash drive is unmounted. And after it is done, the
drive will no more be displayed.
The usb drive can safely be ejected from the system now.
chevron_up_icon
1 out of 13
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]