Linux Task Automation for Beginners: Using Bash Scripts and Crontab

Abhishek BalajiAbhishek Balaji
4 min read

In this mini project, I'm demonstrating how to automate system tasks on a Linux environment using a Bash script and cron. This is a foundational skill for developers, sysadmins, or anyone looking to streamline repetitive work.

In this project, I will:

  1. Create a new Bash script (cron.bash) containing the task(s) I want to automate.

  2. Assign executable permissions to the script using chmod to ensure it can be run by the system.

  3. Schedule the script using crontab, so it executes automatically at specified intervals.

This simple workflow lays the foundation for powerful task automation on any Linux system.

I'm currently logged into my Ubuntu virtual machine running on VMware Workstation.

First, we need to create a script that contains the task we want to automate. You can use any text editor of your choice — in this demonstration, I’ll use the nano editor.

Run the following command:

nano create-dummy-file.bash

This will open a new file named create-dummy-file.bash in the nano editor. Inside the file, add the automation commands you want to use.

As shown above, the script is created. Now, open the script using any text editor you prefer. Add the commands you want to execute.

Note: Remember to include the shebang header at the beginning of the script.

I have added a few tasks that I want to automate.

Note: Always provide the full path (location) when specifying files or directories in your script.

ctrl + s

To save and exit, enter the command:

ctrl + x

Now, go ahead and give the file executable permissions using the following command:

In my case, it is:

sudo chmod 700 "create-dummy-file.bash"

Enter your user password to confirm the action.

To list the files and folders in the current directory with detailed information, use the command

ls -l

Double-check that the read, write, and execute permissions are given only to the user, not to the group or others.

Schedule the Script with Crontab,

crontab -e

This command opens the crontab file in your default editor. To run your script at desired intervals, add a new line with the cron schedule syntax followed by the full path to your script. For example, to run the script every day at 2:30 AM:

30 2 * * * /full/path/to/script-name.bash

Make sure to replace /full/path/to/script-name.bash with the actual full path to your script.

Save and exit the editor. Your cron job is now scheduled!

Let me proceed with these steps.

I already have another cron job set up in the crontab, so you can ignore it.

Note: Cron Timing Format

A cron schedule consists of five fields followed by the command to run:

* * * * * /path/to/command
│ │ │ │ │
│ │ │ │ └── Day of the week (0 - 7) (Sunday=0 or 7)
│ │ │ └──── Month (1 - 12)
│ │ └───── Day of the month (1 - 31)
│ └────── Hour (0 - 23)
└──────── Minute (0 - 59)

For this demonstration, I will set the time format to a few minutes ahead of the current time when executing.

ctrl + s

to save

ctrl + x

to exit

Go ahead and use the date command to keep track of the time for this demonstration.

date

Once the scheduled time is reached, the cron daemon (crond) will automatically execute the script according to the defined schedule.

As you can see from the image above, test-file.txt has been created. To view the contents of the file, use the command

cat test-file.txt

As you can see, the ping packets have been logged into the file, along with the date and message.

✅ Conclusion

This concludes our hands-on mini project on automating tasks using cron.bash and crontab on a Linux system. Throughout this demonstration, we’ve covered:

  • 🛠️ Creating a custom Bash script to define tasks

  • 🔐 Setting executable permissions with chmod

  • 📅 Scheduling tasks using crontab

  • 🧠 Understanding the cron timing format and structure

  • ⚙️ Letting the cron daemon handle automated execution

This foundational workflow is a powerful introduction to Linux automation. From running regular backups to monitoring services or automating system updates — the possibilities are endless.

Now that you've seen the basics in action, go ahead and experiment with different tasks, schedules, and scripts to see what automation can do for you.

Thank you for reading, and happy scripting! 🖥️📅🔁

0
Subscribe to my newsletter

Read articles from Abhishek Balaji directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhishek Balaji
Abhishek Balaji

I'm a cloud and DevOps upskilling candidate focused on building practical skills through real-world AWS projects. I enjoy getting hands-on with core services like EC2, EBS, S3, and IAM, and documenting my learning journey through blog posts and GitHub repositories. Every project I complete is a step toward mastering cloud fundamentals and developing automation skills that align with DevOps practices. My goal is to grow into a confident, capable engineer who can design and manage scalable infrastructure. GitHub: https://github.com/abhishek-balaji-2025