Common Shell scripts for Linux O & M (with annotations) in Linux daily O & M, shell scripts are essential tools for every it o & M personnel. They are proficient in compiling shell scripts in the production environment, it can help us complete daily O & M work more easily, better, and faster. Let's look at a few simple scripts. Thank you for correcting and learning from each other! Www.2cto.com I. Automatic Mysql backup script: The following script is an automatic mysql backup script for your reference only and can be modified as needed. #! /Bin/sh # auto backup mysql # wugk 2012-12-12 # Define PATH defines the variable BAKDIR =/data/backup/mysql/'date + % Y-% m-% d' MYSQLDB = webapp MYSQLPW = backup MYSQLUSR = backup # must use root user run scripts must run with the root user, $ UID is the system variable if [$ UID-ne 0]; then echo This script must use the root user!!! Sleep 2 exit 0 fi # Define DIR and mkdir DIR determine whether the directory exists. if it does not exist, create if [! -D $ BAKDIR]; then mkdir-p $ BAKDIR else echo This is $ BAKDIR exists .... fi # Use mysqldump backup mysql back up database/usr/bin/mysqldump-u $ MYSQLUSR-p $ MYSQLPW-d $ MYSQLDB> $ BAKDIR/webapp_db. SQL cd $ BAKDIR; tar-czf webapp_mysql_db.tar.gz *. SQL # Find the Backup Directory. delete the file at the end of SQL and find. -type f-name "*. SQL "| xargs rm-rf # how to print the database backup success and delete the directory 30 days ago from the backup directory [$? -Eq 0] & echo "This 'date + % Y-% m-% d' MySQL BACKUP is SUCCESS" cd/data/backup/mysql/; find. -type d-mtime + 30 | xargs rm-rf echo "The mysql backup successfully" II. Nginx case installation script: www.2cto.com: The following script is The Nginx automatic installation script, which is for your reference only, it can be modified according to the actual situation. Here we use the case method. The actual environment installation can remove the case mode and be fully automated. #! /Bin/sh ### nginx install shell ### wugk 2012-12-12 ### Define PATH definition variable SOFT_PATH =/data/soft/nginx_file1_nginx-1.2.4.tar.gz DOWN_PATH = http://nginx.org/download/ # Define DIR and mkdir soft DIR create a Software Directory if [! -D $ SOFT_PATH]; then mkdir-p $ SOFT_PATH fi # Define download function defines the download function download () {cd $ SOFT_PATH; wget $ DOWN_PATH/$ NGINX_FILE} # Define install function defines install function install () {yum install pcre-devel-y cd $ SOFT_PATH; tar xzf $ NGINX_FILE cd nginx-1.2.4 /&&. /configure -- prefix =/usr/local/nginx/-- with-http_stub_status_module -- with-http_ssl_module [$? -Eq 0] & make install} # Start Nginx Server Define start function defines start function () {lsof-I: 80 [$? -Ne 0] & amp;/usr/local/nginx/sbin/nginx} # Stop Nginx Server Define stop function defines the stop function stop () {ps-ef | grep nginx | grep-v grep | awk '{print $2}' | xargs kill-9} # Config Case menu install configure case installation menu case $1 in download) download; install) install; start) start; stop) stop; *) echo "USAGE: $0 {download or install or start or stop}" exit $? Esac 3. automatically decompress the TAR and ZIP scripts: The following scripts are www.2cto.com: automatically decompress the tar package and zip package scripts. They are for your reference only and can be modified according to your actual situation, apply to other applications. # Decompress the zip package script as follows :#! /Bin/sh # auto tar package # wugk 2012-12-12 # Define Path PATH1 =/tmp/images PATH2 =/usr/www/images # Print welcome info cat <EOF ++ combine + ++ --------- welcome to use auto tar scripts ------- ++ keys ++ EOF # find Dir all TAR packages find all tar packages in the/tmp/images directory for I in 'Find $ PATH1-name "*. tar "'Do tar-xvf $ I-C $ PATH2 done # decompress the TAR package script as follows :#! /Bin/sh PATH1 =/tmp/images PATH2 =/usr/www/images #! /Bin/sh PATH1 =/tmp/images PATH2 =/usr/www/images # Find Dir all ZIP packages Find all tar packages in the/tmp/images directory, and create the decompressed directory cd $ PATH1 for I in 'Find. -name "*. zip "| awk-F. {print $2} 'do mkdir-p PATH2 $ I unzip-o .polici.zip-d PATH2 $ I done and above are basic scripts, for more advanced scripts, you are welcome to give more comments. If you work together, you can read more about the script. If you practice more, you will naturally become proficient. The most important thing is to practice more, practice!