1.2 What is shell script and 1.2 is shellscript
When a command or statement is executed through a program file instead of a command line, it is called a shell script or shell program. The shell script file can be used to compile a series of commands and command statements, variables, and flow control statements to form a powerful shell script.
The shell program is similar to the batch processing program (*. bat) in the DOS system)
Backup website and database scripts developed by bat in Windwos
@echo offset date=%date:~0,4%-%date: ~5,2%-%date:~8,2%mysqldump -uroot -ppassword -A -B > D:\back\"%date%".sqlrar.exe a -k -r -s -ml D:\bak\"%date%".sql.rar D:\bak\"%date%".sqldel D:\bak\*.sqlrar.exe a -k -r -s -ml D:\bak\"%date%"htdocs.rar D:\work\PHPnow\htdocs
Clear/var/log/message System log File Command Script
# Run this script as root # clear the log version. Version: v1cd/var/logcat/dev/null> messagesecho "Logs cleaned up ."
Problem:
1. The execution permission is not root and cannot be executed
2. There is no process control to determine whether a file exists
LOG_DIR =/var/log # When $ UID is 0, root User Permissions: ROOT_UID = 0 # Use root user to run if ["$ UID"-ne "$ ROOT_UID"] then echo "Must be root to run this script. "exit 1 ficd $ LOG_dir | {echo" Can't change to necesary directory. "> & 2 exit 1} cat/dev/null> messagesecho" Logs cleaned up. "exit 0
# If 0 is returned before the release, the result is successful. If 1 is returned, the result is failed.
Three methods for clearing logs:
# Echo ""> test. log
#> A. log
# Cat/dev/null> test. log
Application scenarios: Used to retain files and clear content