Operations 48 min read

Comprehensive Collection of Linux Bash Scripts for System Administration Tasks

This article provides a extensive set of Bash scripts covering common Linux system administration tasks such as user management, service deployment, monitoring, backup, networking, and automation, offering ready-to-use code snippets and explanations for each operation.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Comprehensive Collection of Linux Bash Scripts for System Administration Tasks

This guide presents a large number of Bash scripts that automate routine Linux system administration tasks. Each script is accompanied by a brief description of its purpose and usage.

1) Hello World Script

#!/bin/bash
# Write hello world script
echo "Hello World!"

2) Create Linux User with Password Using Positional Parameters

#!/bin/bash
# Create Linux user and set password using positional parameters
# $1 is the first argument (username), $2 is the second argument (password)
useradd "$1"
echo "$2" | passwd --stdin "$1"

3) Backup Logs Weekly Using tar

#!/bin/bash
# Weekly backup of /var/log using tar; filename includes date tag
tar -czf log-`date +%Y%m%d`.tar.gz /var/log
# Add to crontab to run every Friday at 03:00
00 03 * * 5 /root/logbak.sh

4) One‑Click LNMP Deployment (RPM Packages)

#!/bin/bash
# Install LNMP stack using yum (CentOS 7.2 / RHEL 7.2)
yum -y install httpd
yum -y install mariadb mariadb-devel mariadb-server
yum -y install php php-mysql
systemctl start httpd mariadb
systemctl enable httpd mariadb

5) Memory and Disk Usage Monitoring with Alert

#!/bin/bash
# Monitor memory and root partition; send email if thresholds are exceeded
disk_size=$(df / | awk '/\//{print $4}')
mem_size=$(free | awk '/Mem/{print $4}')
while :
do
  if [ $disk_size -le 512000 -a $mem_size -le 1024000 ]; then
    mail -s "Warning" root <
6) Number Guessing Game
#!/bin/bash
# Generate a random number between 1 and 100 and let the user guess
num=$[RANDOM%100+1]
echo "$num"
while :
do
  read -p "计算机生成了一个 1‑100 的随机数,你猜: " cai
  if [ $cai -eq $num ]; then
    echo "恭喜,猜对了"
    exit
  elif [ $cai -gt $num ]; then
    echo "Oops,猜大了"
  else
    echo "Oops,猜小了"
  fi
done
Additional scripts cover topics such as checking for root privileges before installing packages, automating firewall rule addition, monitoring HTTP server status, creating logical volumes, managing virtual machines, generating random passwords, and many more. The collection serves as a practical reference for Linux administrators who need ready‑to‑run shell solutions for everyday operational challenges.
automationLinuxSystem Administrationbashshell scripting
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.