1.2 What is shell script and 1.2 is shellscript

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.