如何写一个逼格高的shell脚本

it2025-01-13  4

1. 日志格式

write_log() { LOG_FILE=$LOGDIR/cckiller_$(date +%Y-%m-%d).log logout="" for((i=2;i<=$#;i++)); do j=${!i} logout="${logout} $j " done if [[ $LOG_LEVEL == "INFO" ]] && [[ "$1" == "INFO" ]];then echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}" | tee -ai $LOG_FILE elif [[ $LOG_LEVEL == "DEBUG" ]];then echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}" | tee -ai $LOG_FILE else echo "[`date "+%Y-%m-%d %H:%M:%S"`][$1]: ${logout}" fi }

2. 帮助查看

showhelp() { header echo echo 'Usage: cckiller [OPTIONS] [N]' echo 'N : number of tcp/udp connections (default 100)' echo echo 'OPTIONS:' echo "-h | --help: Show this help screen" echo "-k | --kill: Block the offending ip making more than N connections" echo '-s | --show: Show The TOP "N" Connections of System Current' echo "-b | --banip: Ban The IP or IP subnet like cckiller -b 192.168.1.1" echo "-u | --unban: Unban The IP or IP subnet which is in the BlackList of iptables" echo }
最新回复(0)