1. File backup script
Function: Use this script to backup files, directories in the system, the backed up files are compressed in gzip, and date to mark the date of backup, the name of the backup file or directory is written down to the log file for viewing.
The script content is as follows
#!/bin/sh#description: this shell script backup point file to target by date. #Author: jason#time: 2015-2-26#version: 1.0#processname: backupfile.sh# Synopsis# sh script source-file target-directory#example#sh backupfile.sh /etc /backup means backup/etc this directory into/backup # declares some variables date=$ (/bin/date +%y%m%d) source=$1 #备份目录TARGET = $2 #数据的备份目标BASENAME =$ (basename "$") dirname=$ (dirname "$") #检查备份目录是否存在, does not exist then creates/usr/bin/test -d $2 | | /bin/mkdir -pv $2cd $DIRNAME # Start Backup operation echo -n "Backing up $ ..." /bin/tar -cppf /$2/$BASENAME. $DATE .tar $BASENAME 1> /dev/null 2>> /$2/$BASENAME. back.log/bin/gzip /$2/$BASENAME. $DATE. Tarif [ $? -eq 0 ];then echo "Backup directory or file is $1 " >> /$2/$BASENAME .back.log #声明备份的数据是什么 echo "$1 $DATE backup successfully" >> /$2/$BASENAME .back.log echo -e "\e[1;32m\t\t\t\t\t[success]\e[0m" else echo "error:failure $1 $DATE backup!" >> /$2/$BASENAME .back.log echo -e "\ e[1;31m\t\t\t\t\t[failure]\e[0m "fi
2, the system of a service monitoring script
Function: If a server on a service due to unknown reasons, or because of excessive stress, or other reasons, and at this time can not stop service too long, then write a script to monitor this service, when the discovery of this server stopped working, it automatically started.
The script reads as follows:
#!/bin/sh#description:this shell Script monitoring A specify service,if it does not work,then start it. #Author: jason#time:2015-2-26#processname:monitor.sh#version:1.0servicename=vsftpdservicepid=$ (/usr/bin/pgrep VSFTPD) If ["$Servicepid"! = ""];then echo "the $Servicename is running." else echo "The $Servicename is not running." /etc/rc.d/init.d/vsftpd start fi
Summary: The script is good, but the combination of crontab to reflect its automation.
This article is from the "knowledge needs summary and records" blog, please be sure to keep this source http://zhaochj.blog.51cto.com/368705/1615443
A file backup script