🔧 Introduction to Linux Scripting: Automate Like a Pro
Ever wish your computer could handle repetitive tasks for you-like cleaning up files, backing up data, or monitoring systems? That’s where Linux scripting comes in! With just a few lines of shell script, you can turn manual chores into automated magic.
Linux scripting uses the Bash shell (or similar) to create simple programs-called shell scripts-that can execute commands, control logic, and interact with files. It’s like giving your terminal a brain and a to-do list!
Whether you're a system admin, developer, or just someone who wants to save time, Linux scripting is your entryway to working smarter, not harder.
When making a script – the extension has be .sh for shell. So the system recognises that the script contains shell commands that will be executed.
The .sh extension in a script stands for "shell script." It's a convention commonly used for scripts written for Unix-like operating systems (like Linux and macOS) that are intended to be executed by a shell (such as Bash or Zsh). The extension indicates that the file contains shell commands, but it's not mandatory for the script to work. It's mainly used for organization and clarity.
Basic While Loop Script
Create the script in Vim.
If we do a ls –ltrh we see the script has been created.
If we do not give the right permissions to execute the script, then we will get denied.
In Linux, we give execute permissions to users in order to run a script.
There are three categories of users who can be given permissions:
Owner (user) – The person who created the file or owns it.
Group – A group of users that share the same permissions.
Others – Everyone else who is not the owner or in the group.
Output:
To execute the script we have to use ./ then the name of the script
To run a script on Linux, you typically need to give it execute permissions. This can be done using the chmod command.
Here’s how you can do it:
- Open your terminal.
- Navigate to the directory where the script is located.
- Run the following command to give the script execute permissions: chmod +x script_name.sh
OR
chmod 755 (name of the script)
You can also use chmod +x to grant execute permissions without specifying numeric values like 755. The command chmod +x simply adds execute permission to the script for the user.
However, if you want to give the script read, write, and execute permissions to the owner and only execute permissions to others, then chmod 755 would be appropriate. But since you're asking to avoid that, chmod +x is the simpler and more common choice.
Stay tuned, part 2 in the series coming tomorrow!
Connect with me on LinkedIn
#30DaysLinuxChallenge #RedHatEnterpriseLinux
#CloudWhistler #CloudEngineer #Linux
#DevOps #RedHat #OpenSource
#CloudComputing #Automation
#CloudEngineer #SysAdmin #ITSecurity #TechTips #BusinessIT #Leadership