0% found this document useful (0 votes)
104 views3 pages

### Linux Administration Practical Manual

rgbb w wrg wgbgw dgb db
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views3 pages

### Linux Administration Practical Manual

rgbb w wrg wgbgw dgb db
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Objective:

To understand and configure the job scheduling utilities in Linux: cron, anacron, at, and
batch. These tools help automate the execution of scripts and commands at specified
times.

1. Cron Jobs

Cron is a time-based job scheduler in Unix-like operating systems that allows users to
schedule scripts or commands to run at specific intervals.

Steps to Configure Cron Jobs:

1. Access the Crontab File: Open the terminal and type:


2. bash
3. Copy code
4. crontab -e
5. This command opens the user's crontab file in the default text editor.
6. Define the Cron Job: The syntax for a cron job is:
7. javascript
8. code

* * * * * /path/to/script.sh

1. Each asterisk represents:


Minute (0-59)
Hour (0-23)
Day of Month (1-31)
Month (1-12)
Day of Week (0-7) (Sunday is both 0 and 7)
2. Example: To run a script every day at 3 AM:
3. javascript
4. Copy code
5. 0 3 * * * /home/user/myscript.sh
6. Save and Exit: After adding the desired cron jobs, save the file and exit the editor.
7. View Scheduled Cron Jobs: To list your current cron jobs, type:
8. bash

code

crontab -l

2. Anacron

Anacron is used for running commands periodically, similar to cron, but it does not
require the system to be running continuously. This is useful for laptops or systems that
may not be powered on 24/7.

Steps to Configure Anacron:

1. Edit the Anacrontab File: The configuration file is typically located at /etc/anacrontab.
Open it with:
2. bash
3. Copy code
4. sudo nano /etc/anacrontab
5. Define Anacron Jobs: The syntax is:
6. sql

code

`````PERIOD DELAY JOB-ID COMMAND

PERIOD: Frequency (daily, weekly, monthly)


DELAY: Delay time in minutes
JOB-ID: A unique identifier for the job
COMMAND: The command to execute
1. Example: To run a daily job:

`````bash

dailyjob /path/to/daily_script.sh

1. Save and Exit.

3. At Command

At allows you to schedule commands to run once at a specified time in the future.

Steps to Use At:

1. Schedule a Command: Use the command:


2. bash
3. Copy code
4. echo "command_to_run" | at time
5. Example: To run a script at 2:00 PM:
6. bash

code

echo "/home/user/myscript.sh" | at 14:00

List Scheduled At Jobs:

bash
1. Remove a Scheduled Job

code

1. atrm job_number

4. Batch Utility

Batch schedules jobs to run when the system load levels permit. It is useful for running
jobs that can wait for a period of low system activity.

Steps to Use Batch:

1. Schedule a Command: Use the command:


2. bash

code

1. echo "command_to_run" | batch


2. Example:
3. bash

code

echo "/home/user/myscript.sh" | batch

Check Scheduled Batch Jobs: Use the same atq command to see batch jobs.

Output Verification

To verify the successful configuration of cron, anacron, at, and batch, check their logs
and outputs:

1. Cron Logs: Check logs in /var/log/syslog or /var/log/cron.log (location may vary based on
distribution).
2. Anacron Logs: Check logs for anacron jobs in /var/log/syslog.
3. At and Batch Jobs: Check outputs of at and batch commands in the user's mail or the
log files.

You might also like