Shell script fourth-common small script

Source: Internet
Author: User

Shell Script Fourth-common small script

1, the system process according to the size of memory consumption display out

# PS-E-o "%c:%p:%z:%a"|sort-k5-nr

2. The system process is displayed by CPU size

# PS-E-o "%c:%p:%z:%a"|sort-nr or # PS aux--sort-rss

3, find the current directory occupies 0 bytes of files and delete

# Find/-type f-size 0-exec rm-rf {}\; # This command does not work with 0 -byte files on the root directory

4. Match a line in a file and replace it with content

#sed-I '/root/s/no/yes'/etc/ssh/sshd_config # matches first to Root, Then replace the line no with Yes

5.TCP Packet capture tool analysis Port data stream

# tcpdump-c 10000-i eth0-n DST Port 80

6. Delete all empty directories

# Find/data-type d-empty-exec rm-rf {}; # It is best not to execute this command in/directory

7. Forward the requestfrom the port to the 8080 Port

#iptables-A prerouting-p tcp-m TCP –dport80-j DNAT –to-destination 127.0.0.1:8080

8. The Apache access log access.log count the number of IPs and their accesses, listed by traffic name

    # Cat Access.log | awk ' {print $} ' |sort| uniq-c |sort-rn |head-10

9. Lock key files to prevent malicious tampering | | Unlock to chattr-i

# chattr +I/ETC/PASSWD chattr +i/etc/inittab

Change the file descriptor size to the maximum 65535 The next login takes effect, View File descriptor value size

# echo ' *-nofile 65535 ' >>/etc/security/limits.conf ; Ulimit-n

11. Synchronize the hosts in 1.105/etc via SSH Channel File into the native /data directory

# rsync-avz-e ' ssh-p ' [email protected]:/etc/hosts/data/

kill Port-related processes

# Lsof-i: 80|grep-v "PID" |awk ' {print ' kill-9 ', $ $} ' |sh

takeout the number of times the Shell appears in the /etc/passwd file , Shell refers to the back/bin/bash,/sbin/nologin

# cat/etc/passwd|awk-f: ' {print $7} ' |sort|uniq-c

14. found in directory /TMP 100 a start the file and then save the first line of these files to the file file in

# Find/tmp-type F-name "A *" | Head-n 100 | Xargs head-q-N 1 >> file

15, anti-attack script, Enterprise utility small script http://blog.csdn.net/linuxlsq/article/details/52606408


Shell script fourth-common small 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.