Shell Daily Script

Source: Internet
Author: User
Tags apache access log

1. Use a command to find the files that have been modified in the last 24 hours in the/etc/directory, and the suffix name is the. log file and delete it.
Find/etc-type f-mtime-1-name "
log* "-exec rm-rf {} \;

2. From the Test.log file, find the row containing "not", "Fail" or "Error", without the "Info" field, and then find the last column field separated by the colon ":".
Cat Test.log |grep-e "not"-e "Fail"-E "Error" |grep-v "Info" |awk-f: ' {print $NF} '

3, directory/test/There are 100 ordinary files, some files have suffix. txt, some do not have a suffix, write a script, the/test/directory of all files without the suffix name of the file is renamed to end in. txt.

#!/bin/bash
cd/test/
For AA infind . - type f ! -name "*.txt"
Do
MV $aa $AA. txt
Done

4, write a scheduled task script, every Monday 01:30 the/opt/directory of all the contents of the package backup to the/data/backup/directory, and the file name is yyyymmdd-opt,yyyy for the year, MM for the month, DD for the day.

Crontab–e
1 1/home/aa.sh >/dev/null 2>&1

#!/bin/bash
#/home/aa.sh
Time=date +%Y%m%d
Tar czvf $time-opt/opt/
MV $time-opt/data/backup/

5. Use a command to count the number of visits per IP address in Apache access log access.log, and list the top 10 by traffic.
Examples of the log grid styles are as follows:
192.168.1.10--[24/jul/2017:23:55:55 +0800] "get/http/1.1" 200 19

More Access_log | awk ' {print '} ' | uniq-c | Sort-rn | Head-10

6, print out the test.conf file does not start with "#", and is not a blank line of content.

Sed-e "/^#/d" test.conf | awk ' {if (length!=0) print $} '

7, write a scheduled task, every 2 hours to perform a/opt/app/test.sh.
Crontab–e

    • /2 /opt/app/test.sh >/dev/null 2>&1

Shell Daily Script

Related Article

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.