A good summary of knowledge can help everyone quickly learn and improve relevant skills.When learning Linux, shell scripting is an indispensable knowledge system. To help everyone quickly get started and enhance their shell programming skills, I have compiled 280 classic shell scripts. It can be said that any qualified Linux engineer has gone through this collection of shell scripts!
Additionally, I have prepared some resources such as shell script writing standards, beginner manuals, and writing guides, which I will share with everyone today.
Due to the large number of script examples, only a portion is displayed here. For the complete version, please see the end of this article.
280 ready-to-use shell scripts!
These 280 shell scripts have clear and copyable code, and the electronic version can be used anytime for practice and improvement. They are essential for learning, enhancing skills, and preparing for interviews.
1. One-click online/offline script for backend servers
#!/bin/bash##********************************************************************#Author: liusenbiao#Date: 2022-07-05#FileName: lnmp.sh#Description: Server online/offline script#********************************************************************. /etc/init.d/functionsHOSTNAME=liu_webservers1rpm -q socat || yum -y -q install socatcase $1 inup)for i in {1..2};doecho "set weight ${HOSTNAME}/$2 1" | socat stdio /var/lib/haproxy/haproxy.sock$i[ $? -eq 0 ] && action "$2 is up"done;;down)for i in {1..2};doecho "set weight ${HOSTNAME}/$2 0" | socat stdio /var/lib/haproxy/haproxy.sock$i[ $? -eq 0 ] && action "$2 is down"done;;*)echo "Usage: `basename $0` up|down IP";;esac
2. Read console input parameters
#!/bin/bashread -t 7 -p "input your name " NAMEecho $NAMEread -t 11 -p "input your age " AGEecho $AGEread -t 15 -p "input your friend " FRIENDecho $FRIENDread -t 16 -p "input your love " LOVEecho $LOVE
3. Backup files and directories
#!/bin/bashBACKUPFILE=backup-$(date +%m-%d-%Y)archive=${1:-$BACKUPFILE}find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."exit 0
4. Roll call script
#!/bin/bash# Write a roll call script# This script requires a user.txt file# The file must contain all names, one name per line, and the script randomly displays one name each timewhile :do# Count how many users are in the user fileline=`cat user.txt |wc -l`num=$[RANDOM%line+1]sed -n "${num}p" user.txtsleep 0.2cleardone
More content displayed
Scroll up and down to see more, only a portion is displayed
Shell scripts are a key component of automated operations. Although they may consist of just a few dozen lines of code, they contain immense power and wisdom, making them worth learning for operations friends.
All materials have been packaged, and those who wish to improve should definitely take them for study!
The materials are compiled from the internet and are for free exchange and sharing. Please delete if infringing.
The method to obtain is as follows:
Scan the QR code above
Add a note "280 shell scripts" when adding
You can receive it 100% for free
Please scan to receive; private messages in the background will not send scripts!