2015-4-8

Source: Internet
Author: User

1, in the shell,-f is to determine whether the file exists,-D is to determine whether the path exists.

2, the shell and programming language, like writing, to take the judgment statement, that is, logic.

3. Write a simple shell script to empty the system log:

1 #!/bin/bash2 3 #Clear Log Script4 5log_dir=/var/Log6 7Log_name=Messages8 9Root_uid=0#The user has the root user permission when the $UID is 0Ten  One #determine if the user is the root user A if[$UID-ne $ROOT _uid] -  Then -Echo"must is root to run this script." theExit 1 - fi -  - #determine if a directory exists +CD $LOG _dir | | { -Echo"cannot change to necessary directory.">&2 +Exit 1 A } at  - #determine if a file exists - if[ ! -F $LOG _name] -  Then -Echo"Log file not exist.">&2 -Exit 1 in fi -  toCat/dev/null > $LOG _name && Echo"Logs cleaned up."                                                                                                  +  -Exit 0
View Code

2015-4-8

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.