Here we will dive into part 7 in the shell scripting series. Today we will be looking at two scripts in order to check whether a particular service is running.
Shell scripting is essential in production environments for automating repetitive tasks, ensuring consistency, and minimising human error. It enables engineers to streamline deployments, manage system configurations, monitor processes, and orchestrate complex workflows with precision. In a high-availability environment, shell scripts act as reliable, lightweight tools that reduce manual intervention and improve operational efficiency.
1st Script:
Create the script in VIM.
Write the script in VIM and save it.
✅ What it does:
• ls "$logfile": Tries to list the file whose path is in the variable logfile.
• 2>/dev/null: Suppresses error messages by redirecting stderr (file descriptor 2) to /dev/null.
💡 In Plain English:
“Try to list this file. If it doesn’t exist, don’t show any error message.”
🧠 Common use in scripts:
This is often used to check if a file exists without showing errors.
Apply the necessary permissions to the script so it can be executed.
If we do a ls –ltrh we see that the script has been created and also it is in green colour – meaning the permissions have been applied to the script and therefore it is now executable.
Execute the script with ./
Output of the script once it has been executed.
The script confirms that the SSHD service is running, however there are no logs , so therefore none are displayed.
2nd Script:
Create the script with VIM.
Write the script in VIM and save it.
The --quiet option in systemctl is-active --quiet means:
Suppress all output — the command returns only an exit status, with no text output.
Here's how it works:
• Exit status 0 → The service is active/running.
• Exit status 1 or other non-zero → The service is inactive, failed, or not found.
Apply the necessary permissions to the script so it can be executed.
If we do a ls –ltrh we see that the script has been created and also it is in green colour – meaning the permissions have been applied to the script and therefore it is now executable.
Execute the script with ./
Output of the script once executed.
Stay tuned, part 8 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