Member-only story

Useful Shell Scripts (2)

Beck Moulton
4 min readApr 5, 2023

--

#1. See how many remote IPs are connecting to the machine

See how many remote IPs are connecting to the local machine (whether through ssh or web or ftp ) Use netstat — atn to view the status of all connections on the machine, — a to view all, -T Display only tcp connection information, ≤ n Display in numeric format Local Address (the fourth column is the IP and port information of the machine) Foreign Address (the fifth column is the IP and port information of the remote host) Use the awk command to display only the data in column 5, and then display the information of the IP address in column 1 Sort can be sorted by number size, and finally use uniq to delete the redundant duplicates and count the number of duplicates


netstat -atn | awk '{print $5}' | awk '{print $1}' | sort -nr | uniq -c

#2. Detect file consistency in specified directories of two servers

Detect the consistency of files in specified directories on two servers, by comparing the md5 values of files on two servers to detect consistency

#!/bin/bash
dir=/data/web
b_ip=xxx.xxx.xxx.xxx
#Iterate through all the files in the specified directory and use them as arguments to the md5sum command to get the md5 values of all the files and write them to…

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet