Introduction to Automation and Shell Scripting in Linux (Part 01)


What is Automation?
Automation refers to the process of reducing or eliminating manual activity by using scripts, tools and programs to perform task.
Examples of Activities You Can Automate on Linux
Generating Large Numbers
Automating mathematical or random number generating task
Creating Large Numbers of Files
Automating the creation and management of files.
File backup and archiving
Automating backing up important files and compressing them. using tools like “tar“ or “zip“
Monitoring System Health
Automating monitoring of system resources like CPU usage, memory, or disk space.
User Account Management
Creating, modifying and deleting user accounts in bulk
Schedule Tasks
Running Specific scripts and commands at predefined intervals.
Log File Management
Archiving or cleaning old log files automatically to save space
Downloading files
Automating downloads using tools like “wget” or “curl”
What is Shell Scripting?
Shell Scripting in linux is the process of writing scripts to automate day-to-day tasks on your Linux machine. It involves writing a series of commands in a file that the shell interpreter can execute.
How to Write a Shell Script?
Basic requirements to write a Shell Script.
Create a file.
Use Touch command to create a file.
Example:
touch <file-name>.sh
touch first-shell-script.sh
Some common commands use frequently in shell script.
To view the file use ls command.
Use ls -ltr command to see file details such as timestamp, who created file and permissions.
Use man command to see manual or documentation of commands e.g man ls, man touch.
Editing a Shell Script.
Open the file using vi or vim.
Note: If file already exist vim will open it. If file does not exist vim will create and open the file.
Example:
vim <file-name>.sh
vim first-shell-script.sh
The vim will open the file. Now you are ready to write your first shell script.
Difference between Touch and Vim:
Touch command create file but cannot open file.
Vim command can open the file as well as create the file if it does not exist.
Conclusion:
Automation in Linux using shell scripting is a powerful way to reduce manual effort, improve efficiency, and streamline repetitive tasks. By writing simple scripts, you can automate file management, system monitoring, user management, backups, and more.
Subscribe to my newsletter
Read articles from Shahana Riaz directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
