In this hands-on lab, we will be looking at scheduling processes to run on a schedule. We will perform some troubleshooting on a user account to ensure the process is working correctly, and then we will create a task as the `root` user to ensure our time is synced correctly on our server.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Verify the `testuser` Can Create Scheduled Tasks
Access the
testuser
‘s account:su - testuser
The password is
Password!
Create a file named
test.sh
that echoes the string "this is a test" into anexamplefile
:vim test.sh ++contents #! /bin/bash echo 'this is a test' >> /home/testuser/examplefile
Save and exit the file with Escape and then Shift+ZZ.
Make the file executable:
chmod +x test.sh
Open
testuser
‘s crontab and add a task:crontab -e
Add this line:
* * * * * /home/testuser/test.sh
Save and exit with Escape and then Shift+ZZ.
Tail the file
examplefile
and ensure a line is appended every minute:tail -F examplefile
Hit Ctrl+C to quit.
Remove the task from the crontab:
crontab -e
On the line with the task, press
d
twice.Save and exit with Escape and then Shift+ZZ.
- Create a Task as `root` that Syncs the System Clock to the Hardware Clock
Open the
root
crontab:sudo -i crontab -e
Add the task to run the backup at 3 AM:
SHELL=/bin/bash PATH=/sbin 00 03 * * * /usr/local/bin/customback /opt/programdata
Save and exit with Escape+X.
Verify the task exists in the
root
crontab:sudo -i crontab -l