<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shell Tools (工具) &#8211; Eternal Center</title>
	<atom:link href="https://eternalcenter-sep-2022.github.io/category/language/shell/shell-tools/feed/" rel="self" type="application/rss+xml" />
	<link>https://eternalcenter-sep-2022.github.io/</link>
	<description></description>
	<lastBuildDate>Tue, 13 Sep 2022 12:45:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>[工具] Shell 批量实现多个远程服务器执行命令 （多条命令版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-command-multiple-commands/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 06 Jul 2022 08:52:35 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Others (其它)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=26271</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量实现多个远程服务器执行命令 （多条命令版）作用：批量实现多个远程服务器执行命令 （多条命令版） 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. myuser=&#8221;zhumingyu&#8221; #用户名2. myserver=&#8221;eternalcenter.com eternalcentre.com&#8221; #服务器名，每个服务器名以空格间隔3. mycommand=&#8221;ls ip a s&#8221; #命令，每个命令以空格间隔4. mysudo=&#8221;yes&#8221; #是否使用 sudo，可以选择 yes 或者 no 注意 执行脚本的用户要在远程服务器中有同名用户，此用户拥有免密钥 sudo su 权限，且能被本服务器免密钥 ssh 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量实现多个远程服务器执行命令 （多条命令版）<br>作用：批量实现多个远程服务器执行命令 （多条命令版）</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. myuser=&#8221;zhumingyu&#8221; #用户名<br>2. myserver=&#8221;eternalcenter.com eternalcentre.com&#8221; #服务器名，每个服务器名以空格间隔<br>3. mycommand=&#8221;ls ip a s&#8221; #命令，每个命令以空格间隔<br>4. mysudo=&#8221;yes&#8221; #是否使用 sudo，可以选择 yes 或者 no</p>



<h3>注意</h3>



<p>执行脚本的用户要在远程服务器中有同名用户，此用户拥有免密钥 sudo su 权限，且能被本服务器免密钥 ssh</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

myuser="zhumingyu"
myserver="eternalcenter.com eternalcentre.com" #each server is separated by a space
mycommand="ls ip a s" #each command is separated by a space
mysudo="yes" #please choose "yes" or "no"

####################### Separator ########################

mynow=`date +%Y-%m-%d-%H-%s`

if &#91; $mysudo == 'yes' ];then
        executecommand(){
                ssh -t $1@$2 "sudo -u root su - root -c \"$command\""
        }
        echo "use sudo"
fi

if &#91; $mysudo == 'no' ];then
        executecommand(){
                ssh -t $1@$2 "$command"
        }
        echo "don't use sudo"
fi

for commands in `echo $mycommand`
do

        for servers in `echo $myserver`
        do
                echo $servers
                echo $commands
        executecommand $myuser $servers $commands
        done

done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 显示可以无密码登录系统的用户 （以 1 行的形式显示）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-login-check/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 11 Jun 2022 13:33:07 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23846</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：显示可以登录系统的用户 （以 1 行到形式显示）作用：显示可以登录系统的用户 （以 1 行到形式显示） 使用方法 1. 给此脚本添加执行权限2. 执行此脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：显示可以登录系统的用户 （以 1 行到形式显示）<br>作用：显示可以登录系统的用户 （以 1 行到形式显示）</p>



<h3>使用方法</h3>



<p>1. 给此脚本添加执行权限<br>2. 执行此脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

userlist=
n=`cat /etc/passwd | wc -l`
i=1

while &#91; $i -le $n ]
do
	line=`sed -n "$&#91;i]p" /etc/passwd`
	echo $line | egrep "nologin$|false$" &amp;&gt; /dev/null
	if &#91; $? -ne 0 ];then
                userlist="$userlist `echo $line | awk -F: '{print $1}'`"
	fi
	let i++
done

echo $userlist</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量检测指定用户是否可以登录本地服务器</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-user-login-check/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 05 Jun 2022 16:21:49 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23696</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量检测指定用户是否可以登录本地服务器作用：批量检测指定用户是否可以登录本地服务器 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 directorylist=&#8221;daemon bin sys adm uucp guest nobody lpd lp&#8221; #要被检测的用户 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量检测指定用户是否可以登录本地服务器<br>作用：批量检测指定用户是否可以登录本地服务器</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>directorylist=&#8221;daemon bin sys adm uucp guest nobody lpd lp&#8221; #要被检测的用户</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

directorylist="daemon bin sys adm uucp guest nobody lpd lp"

####################### Separator ########################

directorycheck=

for i in `echo $directorylist`
do
        directorycheck="$directorycheck `cat /etc/passwd | egrep "^$i:" | egrep -v '/sbin/nologin|false|/bin/false' | awk -F: '{print $1}'`"
done

echo $directorycheck</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 测试 SFTP 服务</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-sftp-test/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 14 May 2022 14:11:28 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[SFTP]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Storage Service (存储服务)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23553</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：测试 SFTP 服务作用：测试 SFTP 服务 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 IP=10.0.0.8 #要测试 SFTP 的服务器 IP 地址 注意 此脚本执行前必须要先保证执行脚本的主机能无秘钥远程需要测试 SFTP 服务的服务器 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：测试 SFTP 服务<br>作用：测试 SFTP 服务</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>IP=10.0.0.8 #要测试 SFTP 的服务器 IP 地址 </p>



<h3>注意</h3>



<p>此脚本执行前必须要先保证执行脚本的主机能无秘钥远程需要测试 SFTP 服务的服务器</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################
IP=10.0.0.8
####################### Separator ########################

set timeout 3

rpm -q expect &amp;&gt; /dev/null
if &#91; $? -ne 0 ];then
        echo "Expect needs to be installed first"
fi

expect &lt;&lt; EOF
spawn sftp $IP
expect "sftp&gt;"                                   {send "cd /tmp\r" } 
expect "sftp&gt;"                                   {send "ls -l\r"}
expect "sftp&gt;"                                   {send "quit\r"}
expect "&gt;"                                       {send "\r"}
EOF</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 显示系统常用信息</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-display-system-common-information/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 26 Apr 2022 16:14:48 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System Hardware (系统硬件)]]></category>
		<category><![CDATA[System Network (系统网络)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Performance (系统性能)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Process & System Performance (系统进程 & 系统性能)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Software (系统软件)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=23311</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：显示系统常用信息作用：显示系统常用信息 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. times=5 #显示系统常用信息的次数2. sleeptime=0.3 #大部分行与行之间显示的间隔时间 注意 1. 需要安装 sysstat 软件2. 执行此脚本的用户能够使用 sudo ip a s 命令3. 执行此脚本的用户能够使用 sudo ss -ntulap 命令4. 搭建了 KVM 虚拟化平台后执行此脚本的用户能够使用 sudo virsh list 命令后才能实现 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：显示系统常用信息<br>作用：显示系统常用信息</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. times=5 #显示系统常用信息的次数<br>2. sleeptime=0.3 #大部分行与行之间显示的间隔时间</p>



<h3>注意</h3>



<p>1. 需要安装 sysstat 软件<br>2. 执行此脚本的用户能够使用 sudo  ip a s 命令<br>3. 执行此脚本的用户能够使用 sudo ss -ntulap 命令<br>4. 搭建了 KVM 虚拟化平台后执行此脚本的用户能够使用 sudo virsh list 命令后才能实现</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################
times=5
sleeptime=0.3
####################### Separator ########################

nowtime=1

while (( nowtime &lt;= times))
do
        echo -e "Start Monitoring: \c"
	for i in {1..94}
	do
	        echo -e "#\c"
		sleep 0.01
        done
	echo

	sleep $sleeptime
        host=`hostname`
        echo -e "Name:\t\t\t\t\t\t\t \033&#91;1m$host\033&#91;0m"

        ip=`sudo ip a s | awk '/&#91;1-2]?&#91;0-9]{0,2}\.&#91;1-2]?&#91;0-9]{0,2}/&amp;&amp;!/127.0.0.1/{print $2}' | awk -F/ '{print $1}'`
	for iip in $(echo $ip)
        do
		sleep $sleeptime
                echo -e "IP Address:\t\t\t\t\t\t \033&#91;1m$iip\033&#91;0m"
        done

        sleep $sleeptime

        cpu=`top -bn 1 | awk -F',' '/^%Cpu/{print $4 }' | awk '{print $1}' | awk '{print 100-$1}'`
        echo -e "CPU Usage (Total):\t\t\t\t\t \033&#91;1m$cpu%\033&#91;0m"

        sleep $sleeptime

        mem=`free | grep Mem | awk '{print $3/$2 * 100.0}' | egrep -o "&#91;1]?&#91;0-9]{0,2}\.&#91;0-9]"`
        echo -e "Memory Usage (Total):\t\t\t\t\t \033&#91;1m$mem%\033&#91;0m"

	directory=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print $6}'`
        for idirectory in `echo $directory`
        do
                sleep $sleeptime
                directoryusage=`df -h | grep -v run | grep -v boot | awk '$1~/\/dev/{print}' | grep $idirectory$ | awk '{print $5}'`
		if &#91; $idirectory == / -o $idirectory == /sda -o $idirectory == /sdb  ];then
                        echo -e "Directory Usage ($idirectory):\t\t\t\t\t \033&#91;1m$directoryusage\033&#91;0m"
	        else
                        echo -e "Directory Usage ($idirectory):\t\t\t\t \033&#91;1m$directoryusage\033&#91;0m"
		fi
        done

	sudo -l | grep 'virsh list' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
	        sleep $sleeptime
	        virtual=`sudo virsh list | egrep &#91;0-9] | wc -l`
	        echo -e "Number of Virtual Machines (Total):\t\t\t \033&#91;1m$virtual\033&#91;0m"
        fi

        sleep $sleeptime

        user=`who | wc -l`
        echo -e "Number of User Logins (Total):\t\t\t\t \033&#91;1m$user\033&#91;0m"

        soft=`rpm -qa | wc -l`
        echo -e "Number of Softwares (Total):\t\t\t\t \033&#91;1m$soft\033&#91;0m"

        sleep $sleeptime

        port=`sudo ss -ntulap | wc -l`
        echo -e "Number of Open Ports (Total):\t\t\t\t \033&#91;1m$port\033&#91;0m"

        which sar &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                networkcard=`ifconfig | awk -F: '/flags/&amp;&amp;!/lo/{print $1}'`
                for inetworkcard in `echo $networkcard`
                do
                        networkread="`sar -n DEV 1 1 | grep $inetworkcard | awk '/&#91;0-9]&#91;0-9]:&#91;0-9]&#91;0-9]/{print $3/1000}'` m/s"
                        networkwrite="`sar -n DEV 1 1 | grep $inetworkcard | awk '/&#91;0-9]&#91;0-9]:&#91;0-9]&#91;0-9]/{print $4/1000}'` m/s"
			echo $inetworkcard | grep eth &amp;&gt; /dev/null
			if &#91; $?  -ne 0 ];then
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t \033&#91;1m$networkread\033&#91;0m (Read)\t\033&#91;1m$networkwrite\033&#91;0m (Write)"
		        else
	                echo -e "Network Card IO ($inetworkcard):\t\t\t\t\t \033&#91;1m$networkread\033&#91;0m (Read)\t\033&#91;1m$networkwrite\033&#91;0m (Write)"
			fi
                done
        fi

        which iostat &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
	        disk=`iostat -d -k 1 1 | awk '!/^$/&amp;&amp;!/Device/&amp;&amp;!/Linux/{print $1}'`
                for idisk in `echo $disk`
	        do
			sleep $sleeptime
		        diskread="`iostat -d -k 1 1 | grep $idisk |  awk '{print $3/1000}'` m/s"
		        diskwrite="`iostat -d -k 1 1 | grep $idisk |  awk '{print $4/1000}'` m/s"
			echo $idisk | grep 'nvme' &amp;&gt; /dev/null
			if &#91; $? -eq 0 ];then
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033&#91;1m$diskread\033&#91;0m (Read)\t\033&#91;1m$diskwrite\033&#91;0m (Write)"
		        else
		                echo -e "Disk IO (/dev/$idisk):\t\t\t\t\t \033&#91;1m$diskread\033&#91;0m (Read)\t\033&#91;1m$diskwrite\033&#91;0m (Write)"
			fi
	        done

        fi

        echo -e "Complete Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done
        echo
        sleep $sleeptime

        let nowtime++
done

        echo -e "Terminal Monitoring: \c"
        for i in {1..91}
        do
                echo -e "#\c"
                sleep 0.01
        done

exit</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 监控普通登录记录 （排除 SFTP 登录记录只监控普通登录记录）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-login-log-exclude-sftp/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 14:52:50 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Other Service (其它服务)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[SFTP]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Storage Service (存储服务)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System General Log (系统普通日志)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=21977</guid>

					<description><![CDATA[注意： 在排除 SFTP 登录记录只监控普通登录记录前要先开启 SFTP 日志： 正文： 介绍 基本信息 作者：朱明宇名称：监控普通登录记录 （排除 SFTP 登录记录只监控普通登录记录）作用：监控普通登录记录 （排除 SFTP 登录记录只监控普通登录记录） 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本4. 普通登录记录会同时记录在系统日志和 $logfile 里 脚本分割线里的变量 1. logfile=logfile.txt #用户保存记录的文件2. prompt=&#8221;and no sftp info&#8221; #记录里普通登录记录的文件 脚本]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在排除 SFTP 登录记录只监控普通登录记录前要先开启 SFTP 日志：</p>



<div class="wp-container-1 wp-block-buttons">
<div class="wp-block-button aligncenter is-style-outline"><a class="wp-block-button__link" href="https://eternalcenter-sep-2022.github.io/sftp-log/" style="border-radius:0px">SFTP 日志的开启</a></div>
</div>



<h1>正文：</h1>



<h2 id="介绍">介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：监控普通登录记录 （排除 SFTP 登录记录只监控普通登录记录）<br>作用：监控普通登录记录 （排除 SFTP 登录记录只监控普通登录记录）</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本<br>4. 普通登录记录会同时记录在系统日志和 $logfile 里</p>



<h3>脚本分割线里的变量</h3>



<p>1. logfile=logfile.txt #用户保存记录的文件<br>2. prompt=&#8221;and no sftp info&#8221; #记录里普通登录记录的文件</p>



<h2 id="脚本">脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

logfile=logfile.txt
prompt="and no sftp info"

####################### Separator ########################

checktime=`date +%Y-%m-%dT%H -d "-1 day"`

for i in `cat -n /var/log/messages | grep $check_time | grep 'Started Session' | grep -v 'root' | awk '{print $1}'`

do
   line=`sed -n $&#91;i]p /var/log/messages`
   time=`echo $line | awk '{print $1}'`
   session=`echo $line | awk '{print $6}'`
   user=`echo $line | awk '{print $9}'`
   user=${user%.}

   message="ACCESS CHECK LOG: Time:$time Session:$session $user has accessed `hostname`, $prompt"

   let sftpline=i+3

   sed -n $&#91;sftpline]p /var/log/messages | grep sftp-server &amp;&gt; /dev/null
   if &#91; $? -ne 0 ];then
           echo $message
           echo $message &gt;&gt; $logfile.txt
           logger $message
   fi
   echo
done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量比较服务器所有正在运行进程的变化</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-process-compare/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 20 Jan 2022 13:38:56 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Process (系统进程)]]></category>
		<category><![CDATA[System Process & System Performance (系统进程 & 系统性能)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=21341</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量比较服务器所有正在运行进程的变化作用：批量比较服务器所有正在运行进程的变化 使用方法 1. 服务器清单 $server_list 每台服务器占用 1 行2. 在此脚本的分割线内写入相应的内容，并和此脚本放在同一目录下3. 给此脚本添加执行权限4. 执行此脚本5. 此脚本执行完成后，会将运行结果写入当前目录下的 $compare_file 里 脚本分割线里的变量 server_list=server_list.txt #服务器清单first_time=first_time #存储第一次检结果的目录second_time=second_time #存储第二次检查结果的目录compare_file=comparison_results.txt #存储比较结果的文件 注意 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器 脚本]]></description>
										<content:encoded><![CDATA[
<h2 id="介绍">介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量比较服务器所有正在运行进程的变化<br>作用：批量比较服务器所有正在运行进程的变化</p>



<h3>使用方法</h3>



<p>1. 服务器清单 $server_list 每台服务器占用 1 行<br>2. 在此脚本的分割线内写入相应的内容，并和此脚本放在同一目录下<br>3. 给此脚本添加执行权限<br>4. 执行此脚本<br>5. 此脚本执行完成后，会将运行结果写入当前目录下的 $compare_file 里</p>



<h3>脚本分割线里的变量</h3>



<p>server_list=server_list.txt #服务器清单<br>first_time=first_time #存储第一次检结果的目录<br>second_time=second_time #存储第二次检查结果的目录<br>compare_file=comparison_results.txt #存储比较结果的文件</p>



<h3>注意</h3>



<p>此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器</p>



<h2 id="脚本">脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

server_list=server_list.txt
first_time=first_time
second_time=second_time
compare_file=comparison_results.txt

####################### Separator ########################

mkdir $first_time &amp;&gt; /dev/null
mkdir $second_time &amp;&gt; /dev/null
echo &gt; $compare_file

read -p "Please input first second or compare now: " choice

check(){
        for server_name in `cat $1`
        do
                ssh -t $server_name "ps -A" | awk '{print $4}' &gt; $2/$server_name
        done
}

compare(){
        for server_name in `cat $1`
        do
                echo $server_name &gt;&gt; $4
                for process in `cat $2/$server_name`
                        do
                        grep $process $3/$server_name &amp;&gt; /dev/null
                        if &#91; $? -ne 0 ];then
                                echo $process &gt;&gt; $4
                        fi
                done
                echo &gt;&gt; $4
        done
}

if &#91; $choice == first ];then
        check $server_list $first_time
fi

if &#91; $choice == second ];then
        check $server_list $second_time
fi

if &#91; $choice == compare ];then
        compare $server_list $first_time $second_time $compare_file
fi</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 博客 WordPress 数据去隐私化</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-blog-wordpress-de-privacy/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 18 Dec 2021 16:12:50 +0000</pubDate>
				<category><![CDATA[Automation Maintenance (自动化运维)]]></category>
		<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Management (管理)]]></category>
		<category><![CDATA[Personal Website Building (个人网站建设)]]></category>
		<category><![CDATA[Project (项目)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Backup (备份)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19868</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：Shell 博客 WordPress 数据去隐私化作用：修改 WordPress 备份中某个用户的密码并再次进行备份 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. path=/home/zhumingyu/EternalCenter #本地备份目录2. filename=eternalcenter-backup #本地备份文件3. cpath=&#8221;/srv/www/htdocs&#8221; #网站程序目录4. sqlfile=eternalcenter/eternalcenter.sql #网站数据库数据备份5. tarfile=eternalcenter/eternalcenter.tar.gz #网站网页数据备份6. newfilename=clone-eternalcenter-backup #新备份的文件名7. user=&#8217;Mingyu Zhu&#8217; #要修改密码的用户8. newpw=eternalcenter #新的用户密码9. dbuser=ec #用于连接数据库的用户10. dbuserpw=eternalcenter #用于连接数据库的密码11. db=ec #网站数据库数据在数据库中的库 注意 1. 本地需要已经搭建好 LNMP 平台2. 执行此脚本的用户需要有远程服务器的 sudo tar 和 sudo rm 权限3. 脚本 ”mysql -uroot -p&#8217;eternalcenter&#8217; -e &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-blog-wordpress-de-privacy/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 博客 WordPress 数据去隐私化"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：Shell 博客 WordPress 数据去隐私化<br>作用：修改 WordPress 备份中某个用户的密码并再次进行备份</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. path=/home/zhumingyu/EternalCenter #本地备份目录<br>2. filename=eternalcenter-backup #本地备份文件<br>3. cpath=&#8221;/srv/www/htdocs&#8221; #网站程序目录<br>4. sqlfile=eternalcenter/eternalcenter.sql #网站数据库数据备份<br>5. tarfile=eternalcenter/eternalcenter.tar.gz #网站网页数据备份<br>6. newfilename=clone-eternalcenter-backup #新备份的文件名<br>7. user=&#8217;Mingyu Zhu&#8217; #要修改密码的用户<br>8. newpw=eternalcenter #新的用户密码<br>9. dbuser=ec #用于连接数据库的用户<br>10. dbuserpw=eternalcenter #用于连接数据库的密码<br>11. db=ec #网站数据库数据在数据库中的库</p>



<h3>注意</h3>



<p>1. 本地需要已经搭建好 LNMP 平台<br>2. 执行此脚本的用户需要有远程服务器的 sudo tar 和 sudo rm 权限<br>3. 脚本 ”mysql -uroot -p&#8217;eternalcenter&#8217; -e &#8220;drop database $db;&#8221;“ 中 “eternalcenter“ 是指远程 MariaDB 数据库 root 用户的密码，需要修改成远程 MariaDB 数据库的 root 用户密码</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

path=/home/zhumingyu/EternalCenter
filename=eternalcenter-backup
cpath="/srv/www/htdocs"
sqlfile=eternalcenter/eternalcenter.sql
tarfile=eternalcenter/eternalcenter.tar.gz
newfilename=clone-eternalcenter-backup
user='Mingyu Zhu'
newpw=eternalcenter
dbuser=ec
dbuserpw=eternalcenter
db=ec

####################### Separator ########################

date=$(date +%Y-%m-%d-%H)
dir=`pwd`

sudo systemctl stop nginx
sudo systemctl stop php-fpm

mkdir -p $path/$newfilename-$date &amp;&gt; /dev/null

mysql -uroot -p'eternalcenter' -e "drop database $db;"
mysql -uroot -p'eternalcenter' -e "create database $db;"
mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
mysql -uroot -p'eternalcenter' -e "grant all privileges on $db.* to \"$dbuser\"@'localhost';"
mysql -uroot -p'eternalcenter' ec &lt; $sqlfile
mysql -uroot -p'eternalcenter' -e "update $db.ec_users set user_pass = md5(\'$newpw\') where user_login = \'$user\';"
sudo rm -rf $cpath/*
sudo tar -zxvf $tarfile -C $cpath &amp;&gt; /dev/null
cd $cpath
sudo sed -i "s/define('DB_PASSWORD', .*);/define('DB_PASSWORD', \'$dbuserpw\');/" wp-config.php

mysqldump -uroot -p'eternalcenter' $db &gt; $path/$newfilename-$date/$newfilename-$date.sql
sudo tar -zcvf $path/$newfilename-$date/$newfilename-$date.tar.gz .&#91;!.]* * &amp;&gt; /dev/null
cd $dir

sudo systemctl start nginx
sudo systemctl start php-fpm

cd $dir</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 将远程 LNMP 的网站数据库备份到本地</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-backup/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 18 Dec 2021 14:48:32 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Management (管理)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Backup (备份)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19861</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：将远程 LNMP 的网站数据库备份到本地作用：将远程 LNMP 的网站数据库备份到本地 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. path=/home/zhumingyu/EternalCenter #本地备份目录2. filename=eternalcenter-backup #本地备份文件3. key=&#8221;~/.ssh/eternalcenter&#8221; #本地备份本地私钥4. whost=&#8221;eternalcenter.com&#8221; #远程服务器5. wpath=&#8221;/usr/share/nginx/html&#8221; #远程服务器网站程序目录7. wcache=&#8221;/cache&#8221; #远程服务器临时备份目录 注意 1. 远程需要已经搭建好 LNMP 平台2. 用于远程服务器的用户，需要能免密钥 ssh 远程服务器，且对于本地用于本地数据的备份目录和远程服务器的目录拥有读和执行的权限3. 执行此脚本的用户需要有远程服务器的 sudo tar 权限4. 脚本 ”mysqldump -uroot -p&#8217;eternalcenter&#8217; ec > $wcache/$filename-$date.sql“ 中 “eternalcenter“ 是指远程 MariaDB 数据库 root 用户的密码，需要修改成远程 MariaDB 数据库的 root &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-lnmp-backup/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 将远程 LNMP 的网站数据库备份到本地"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：将远程 LNMP 的网站数据库备份到本地<br>作用：将远程 LNMP 的网站数据库备份到本地</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. path=/home/zhumingyu/EternalCenter #本地备份目录<br>2. filename=eternalcenter-backup #本地备份文件<br>3. key=&#8221;~/.ssh/eternalcenter&#8221; #本地备份本地私钥<br>4. whost=&#8221;eternalcenter.com&#8221; #远程服务器<br>5. wpath=&#8221;/usr/share/nginx/html&#8221; #远程服务器网站程序目录<br>7. wcache=&#8221;/cache&#8221; #远程服务器临时备份目录</p>



<h3>注意</h3>



<p>1. 远程需要已经搭建好 LNMP 平台<br>2. 用于远程服务器的用户，需要能免密钥 ssh 远程服务器，且对于本地用于本地数据的备份目录和远程服务器的目录拥有读和执行的权限<br>3. 执行此脚本的用户需要有远程服务器的 sudo tar 权限<br>4. 脚本 ”mysqldump -uroot -p&#8217;eternalcenter&#8217; ec > $wcache/$filename-$date.sql“ 中 “eternalcenter“ 是指远程 MariaDB 数据库 root 用户的密码，需要修改成远程 MariaDB 数据库的 root 用户密码</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

path=/home/zhumingyu/EternalCenter
filename=eternalcenter-backup
key="~/.ssh/eternalcenter"

whost="eternalcenter.com"
wpath="/usr/share/nginx/html"
wcache="/cache"

####################### Separator ########################

date=$(date +%Y-%m-%d-%H)

echo "copy eternalcenter data from website to local server"
ping -c3 -i0.4 $whost &gt; /dev/null
if &#91; $? -eq 0 ];then

        ssh -i $key $whost "
        mkdir $wcache &amp;&gt; /dev/null
        rm -rf $wcache/* &amp;&gt; /dev/null
        mysqldump -uroot -p'eternalcenter' ec &gt; $wcache/$filename-$date.sql
        cd $wpath
        sudo tar -zcvf $wcache/$filename-$date.tar.gz .&#91;!.]* * &amp;&gt; /dev/null
        "

        mkdir -p $path/$date &amp;&gt; /dev/null
        scp -i $key $whost:$wcache/$filename-$date* $path/$date

fi
echo</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 将同目录下最新的某个目录里的所有文件替换到 GitHub 库里 （Git LFS 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-github-replace-git-lfs/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 18 Dec 2021 13:44:56 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Other Service (其它服务)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Backup (备份)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19851</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里作用：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. directory=download-eternalcenter #本地的缓冲目录2. gituser=mingyuzhu #GitHub 用户3. gitemail=mingyu.zhu@eternalcenter.com #GitHub 邮箱4. gitrepository=download-eternalcenter #GitHub 库5. gitbranch=’master’ #GitHub 库的分支6. backupfile=all #备份后的文件7. keyword=clone #同目录下要备份目录名称的关键字 注意 需要提前安装 git 和 git-lfs，注册 GitHub，创建相应的 GitHub 库，并且创建和设置了对应的 ssh 密钥 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里<br>作用：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. directory=download-eternalcenter #本地的缓冲目录<br>2. gituser=mingyuzhu #GitHub 用户<br>3. gitemail=mingyu.zhu@eternalcenter.com #GitHub 邮箱<br>4. gitrepository=download-eternalcenter #GitHub 库<br>5. gitbranch=’master’ #GitHub 库的分支<br>6. backupfile=all #备份后的文件<br>7. keyword=clone #同目录下要备份目录名称的关键字</p>



<h3>注意</h3>



<p>需要提前安装 git 和 git-lfs，注册 GitHub，创建相应的 GitHub 库，并且创建和设置了对应的 ssh 密钥</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

directory=download-eternalcenter
gituser=mingyuzhu
gitemail=mingyu.zhu@eternalcenter.com
gitrepository=download-eternalcenter
gitbranch='master'
backupfile=all
keyword=clone

####################### Separator ########################

backupdirectory=`ls -rtlh | grep $keyword | awk '{print $NF}' | tail -1`

sqlfile=`ls $backupdirectory | grep sql`
tarfile=`ls $backupdirectory | grep tar`

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null

echo $gituser
git config --global user.email "$gitemail"
git config --global user.name "$gituser"

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null
cd $directory
git init
git lfs install
git remote add origin git@github.com:$gituser/$gitrepository
git pull --rebase origin $gitbranch -f
git lfs track *
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *' --prune-empty --tag-name-filter cat -- --all
git commit -m 'cleapup'
git push -u origin $gitbranch -f
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

cd ..

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null
cd $directory
git init
git lfs install
git remote add origin git@github.com:$gituser/$gitrepository
git pull --rebase origin $gitbranch -f
git lfs track *
git rm *
git commit -m 'cleapup'

cd ../$backupdirectory/
tar -zcvf ../$directory/$backupfile.tar.gz *
cd ../$directory

git lfs track *
git add *
git status
git commit -m 'upload'
git push -u origin $gitbranch -f
cd ..</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 自动化部署 LNMP + SSL 平台 （Fedora 35 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-install-fedora-35/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 18 Dec 2021 13:29:31 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Installation (安装)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Shell Website (网站)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19844</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：自动化部署 LNMP + SSL 平台作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS 使用方法 1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下3. 在此脚本的分割线内写入相应的内容4. 服务器都要开启 SELinux5. 给此脚本添加执行权限6. 执行此脚本：./&#60;此脚本&#62; 脚本分割线里的变量 1. webdomain=”eternalcenter.com” #网站的域名，注意不要在前面加任何前缀2. webtar=”eternalcenter-backup-*.tar.gz”网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序3. webcrt=”eternalcenter.com.crt” #网站 SSL 的公钥，可以自己创建也可以在 FreeSSL 上申请4. webkey=”eternalcenter.com.key” #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请5. sqlbackup=”eternalcenter-backup-*.sql” #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空6. db=”ec” #网站在数据库中库7. dbuser=”ec” &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-lnmp-install-fedora-35/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 自动化部署 LNMP + SSL 平台 （Fedora 35 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2 id="介绍">介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：自动化部署 LNMP + SSL 平台<br>作用：自动化安装 LNMP + SSL，即通过 Linux、Nginx、MariaDB、PHP、php-fpm、SSL，实现 HTTPS</p>



<h3>使用方法</h3>



<p>1. 将网站的网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥、网站的数据库备份和本脚本，5 个文件放在同一目录下<br>2. 如果没有网站的数据库备份则将网页数据备份、网站的 SSL 公钥、网站的 SSL 私钥和本脚本，4 个文件放在同一目录下<br>3. 在此脚本的分割线内写入相应的内容<br>4. 服务器都要开启 SELinux<br>5. 给此脚本添加执行权限<br>6. 执行此脚本：./&lt;此脚本&gt;</p>



<h3>脚本分割线里的变量</h3>



<p>1. webdomain=”eternalcenter.com” #网站的域名，注意不要在前面加任何前缀<br>2. webtar=”eternalcenter-backup-*.tar.gz”网站的网页数据备份，如果没有这个备份，可以下载一个开源的 WordPress 网页程序<br>3. webcrt=”eternalcenter.com.crt” #网站 SSL 的公钥，可以自己创建也可以在 FreeSSL 上申请<br>4. webkey=”eternalcenter.com.key” #网站 SSL 的私钥，可以自己创建也可以在 FreeSSL 上申请<br>5. sqlbackup=”eternalcenter-backup-*.sql” #网站数据库数据备份，如果没有这个备份（数据库是全量备份），则这里可以为空<br>6. db=”ec” #网站在数据库中库<br>7. dbuser=”ec” #网站在数据库中的用户<br>8. dbuserpw=”eternalcenter” #网站在数据库中的用户密码<br>9. dbrootpw=”eternalcenter” #数据库的 root 密码</p>



<h3>注意</h3>



<p>1. 服务器的系统需要是 Fedora 35 版本<br>2. 服务器系统要配置好可用的软件源<br>3. 服务器要能够连接外网</p>



<h2 id="脚本">脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################
webdomain="eternalcenter.com"
webtar="eternalcenter-backup-*.tar.gz"
webcrt="eternalcenter.com.crt"
webkey="eternalcenter.com.key"
sqlbackup="eternalcenter-backup-*.sql"
db="ec"
dbuser="ec"
dbuserpw="eternalcenter"
dbrootpw="eternalcenter"
####################### Separator ########################

#Determine whether SELinux is on
getenforce | grep Enforcing
if &#91; $? -ne 0 ];then
	echo "SELinux is not set to enforcing mode and cannot continue"
	exit 2
fi

#Determine whether the required file exists
ls $webtar
if &#91; $? -ne 0 ];then
	echo "No web page data backup, unable to continue"
	exit 2
fi

ls $webcrt
if &#91; $? -ne 0 ];then
	echo "Cannot continue without site public key"
	exit 2
fi

ls $webkey
if &#91; $? -ne 0 ];then
	echo "Unable to continue without site private key"
	exit 2
fi

#Update system
yum clean all
yum repolist
yum makecache
yum -y update

#Make sure the required software is installed
yum -y install tar
yum -y install firewalld

#Deploying Nginx
yum -y install nginx

echo 'worker_processes  1;

events {
    worker_connections  1024;
}

http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  60;
    client_body_timeout 20s;
    client_header_timeout 10s;
    send_timeout 30s;

    server {
        listen       80;
        limit_req zone=one burst=5;
        server_name www.eternalcenter.com eternalcenter.com;

        rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/$1 permanent;
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        }

    server {
        listen       443 ssl;
        server_name www.eternalcenter.com eternalcenter.com;

        if ($request_method !~ ^(GET|POST)$){
        return 444;
        }

        ssl_certificate      /etc/nginx/ssl/eternalcenter.com.crt;
        ssl_certificate_key  /etc/nginx/ssl/eternalcenter.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
            include fastcgi_params;
        } 

        location / {
        root html;
        index index.php index.html index.htm;

        if (-f $request_filename/index.html){rewrite (.) $1/index.html break;}
        if (-f $request_filename/index.php){rewrite (.) $1/index.php;}
        if (!-f $request_filename){rewrite (.) /index.php;}
        
        }

        location ~ ^/\.user\.ini {
        deny all;
        }
    
        location ~*\.(jpd|jpeg|gif|png|css|js|ico|xml)$ {
        expires 30d;
        }

        error_page  404              /404.html;

        }

        gzip on;
	gzip_min_length 1000;
	gzip_comp_level 4;
	gzip_types text/plain test/css application/json application/x-javascript text/xml application/xml
	application/xml+rss text/javascripts;

	client_header_buffer_size 1k;
	large_client_header_buffers 4 4k;

	open_file_cache max=2000 inactive=20s;
	open_file_cache_valid  60s;
	open_file_cache_min_uses 5;
	open_file_cache_errors off;

}' > /etc/nginx/nginx.conf

sed -i "s/server_name www.eternalcenter.com eternalcenter.com;/server_name www.$webdomain $webdomain;/" /etc/nginx/nginx.conf
sed -i "s@rewrite ^/(.*)$ https://eternalcenter-sep-2022.github.io/\$1 permanent@rewrite ^/(.*)$ https://$webdomain/\$1 permanent@" /etc/nginx/nginx.conf;
sed -i "s/eternalcenter.com.crt/$webcrt/" /etc/nginx/nginx.conf
sed -i "s/eternalcenter.com.key/$webkey/" /etc/nginx/nginx.conf

mkdir /etc/nginx/ssl
mv $webcrt /etc/nginx/ssl
mv $webkey /etc/nginx/ssl
chcon -t httpd_config_t /etc/nginx/ssl/$webcrt
chcon -t httpd_config_t /etc/nginx/ssl/$webkey
chcon -t httpd_config_t /etc/nginx/ssl/

rm -rf /usr/share/nginx/html/*
tar -xvf $webtar -C /usr/share/nginx/html/ &amp;&amp; rm -rf $webtar
chcon -t httpd_sys_content_t -R /usr/share/nginx/html/*

yum -y install sendmail
yum -y install policycoreutils
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_connect_db 1
setsebool -P httpd_can_sendmail 1
setsebool -P httpd_can_connect_ftp 1
setsebool -P httpd_unified 1
setsebool -P httpd_enable_cgi 1
setsebool -P httpd_builtin_scripting 1
setsebool -P mysql_connect_http 1

systemctl start nginx
systemctl enable nginx

#Deploy MariaDB
yum -y install mariadb mariadb-server

grep "^log_bin=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a log_bin=ec' /etc/my.cnf.d/mariadb-server.cnf
fi

grep "^binlog_format=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a binlog_format=\"mixed\"' /etc/my.cnf.d/mariadb-server.cnf
fi

grep "^server_id=" /etc/my.cnf.d/mariadb-server.cnf
if &#91; $? -ne 0 ];then
	sed -i '/^datadir/a server_id=51' /etc/my.cnf.d/mariadb-server.cnf
fi

sed -i 's/^plugin-load-add=auth_gssapi.so/#plugin-load-add=auth_gssapi.so/' /etc/my.cnf.d/auth_gssapi.cnf

sed -i '/^user=.*/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i "/\&#91;mysqld\]/a user=mysql" /etc/my.cnf.d/mariadb-server.cnf

sed -i '/^bind-address=.*/d' /etc/my.cnf.d/mariadb-server.cnf
sed -i "/\&#91;mysqld\]/a bind-address=127.0.0.1" /etc/my.cnf.d/mariadb-server.cnf

chown -R mysql /var/lib/mysql

systemctl start mariadb
systemctl enable mariadb

ls $sqlbackup
if &#91; $? -ne 0 ];then
        mysql -uroot -e "create database $db;"
        mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
        mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
else
        mysql -uroot -e "create database $db;"
        mysql -uroot $db &lt; $sqlbackup
	mysql -uroot -e "create user \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
	mysql -uroot -e "grant all privileges on $db.* to \"$dbuser\"@\"localhost\" identified by \"$dbuserpw\";"
	mysql -uroot -e "set password for 'root'@'localhost'=password(\"$dbrootpw\")"
	rm -rf $sqlbackup
fi
	
systemctl restart mariadb

#Deploy PHP
yum -y install php php-fpm php-mysqlnd php-gd php-mbstring php-opcache php-json php-xml php-xmlrpc php-pecl-zip php-pecl-imagick php-intl php-bcmath
useradd php-fpm -s /sbin/nologin
chown -R php-fpm:php-fpm /usr/share/nginx/html

sed -i /"^user =.*"/d /etc/php-fpm.conf
sed -i /"^group =.*"/d /etc/php-fpm.conf
sed -i /"^listen =.*"/d /etc/php-fpm.conf
sed -i /"^&#91;www]"/d /etc/php-fpm.conf
sed -i /"^pm = .*"/d /etc/php-fpm.conf
sed -i /"^pm.start_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.min_spare_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_spare_servers = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_children = .*"/d /etc/php-fpm.conf
sed -i /"^pm.max_requests = .*"/d /etc/php-fpm.conf
sed -i /"^request_terminate_timeout = .*"/d /etc/php-fpm.conf

echo '&#91;www]' >> /etc/php-fpm.conf
echo 'user = php-fpm' >> /etc/php-fpm.conf
echo 'group = php-fpm' >> /etc/php-fpm.conf
echo 'listen = 127.0.0.1:9000' >> /etc/php-fpm.conf
echo 'pm = dynamic' >> /etc/php-fpm.conf
echo 'pm.start_servers = 2' >> /etc/php-fpm.conf
echo 'pm.min_spare_servers = 2' >> /etc/php-fpm.conf
echo 'pm.max_spare_servers = 4' >> /etc/php-fpm.conf
echo 'pm.max_children = 4' >> /etc/php-fpm.conf
echo 'pm.max_requests = 1024' >> /etc/php-fpm.conf
echo 'request_terminate_timeout = 300' >> /etc/php-fpm.conf

systemctl start php-fpm
systemctl enable php-fpm

#Improve system performance
grep "^* soft nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* soft nofile 1024' >> /etc/security/limits.conf
fi

grep "^* hard nofile" /etc/security/limits.conf
if &#91; $? -ne 0 ];then
	echo '* hard nofile 1024' >> /etc/security/limits.conf
fi

#Open firewall
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload

#Limit log space
yum -y install rsyslog
systemctl enable --now rsyslog

echo "/var/log/mariadb/mariadb.log {
        create 600 mysql mysql
        notifempty
	daily
        rotate 3
        missingok
        compress
    postrotate
	# just if mysqld is really running
        if &#91; -e /run/mariadb/mariadb.pid ]
        then
           kill -1 $(&lt;/run/mariadb/mariadb.pid)
        fi
    endscript
}" > /etc/logrotate.d/mariadb

echo "/var/log/nginx/*log {
    create 0664 nginx root
    size 1024M
    rotate 1
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/nginx

echo "/var/log/php-fpm/*log {
    size 100M
    rotate 1
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /bin/kill -SIGUSR1 `cat /run/php-fpm/php-fpm.pid 2>/dev/null` 2>/dev/null || true
    endscript
}" > /etc/logrotate.d/php-fpm

echo "/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    size 100M
    rotate 1
    missingok
    sharedscripts
    postrotate
        /usr/bin/systemctl kill -s HUP rsyslog.service >/dev/null 2>&amp;1 || true
    endscript
}" > /etc/logrotate.d/rsyslog

#Delete this script
scriptwhere=`readlink -f "$0"`
rm -rf $scriptwhere

#Restart the system
reboot</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 将同目录下最新的某个目录里的所有文件替换到 GitHub 库里</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-github-replace/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 18 Dec 2021 13:11:35 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Other Service (其它服务)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Backup (备份)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19836</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里作用：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. directory=download-eternalcenter #本地的缓冲目录2. gituser=mingyuzhu #GitHub 用户3. gitemail=mingyu.zhu@eternalcenter.com #GitHub 邮箱4. gitrepository=download-eternalcenter #GitHub 库5. gitbranch=’master’ #GitHub 库的分支6. backupfile=all #备份后的文件7. keyword=clone #同目录下要备份目录名称的关键字 注意 需要提前安装 git，注册 GitHub，创建相应的 GitHub 库，并且创建和设置了对应的 ssh 密钥 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里<br>作用：将同目录下最新的某个目录里的所有文件替换到 GitHub 库里</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. directory=download-eternalcenter #本地的缓冲目录<br>2. gituser=mingyuzhu #GitHub 用户<br>3. gitemail=mingyu.zhu@eternalcenter.com #GitHub 邮箱<br>4. gitrepository=download-eternalcenter #GitHub 库<br>5. gitbranch=’master’ #GitHub 库的分支<br>6. backupfile=all #备份后的文件<br>7. keyword=clone #同目录下要备份目录名称的关键字</p>



<h3>注意</h3>



<p>需要提前安装 git，注册 GitHub，创建相应的 GitHub 库，并且创建和设置了对应的 ssh 密钥</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

directory=download-eternalcenter
gituser=mingyuzhu
gitemail=mingyu.zhu@eternalcenter.com
gitrepository=download-eternalcenter
gitbranch='master'
backupfile=all
keyword=clone

####################### Separator ########################

backupdirectory=`ls -rtlh | grep $keyword | awk '{print $NF}' | tail -1`

sqlfile=`ls $backupdirectory | grep sql`
tarfile=`ls $backupdirectory | grep tar`

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null

echo $gituser
git config --global user.email "$gitemail"
git config --global user.name "$gituser"

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null
cd $directory
git init
git remote add origin git@github.com:$gituser/$gitrepository
git pull --rebase origin $gitbranch -f
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *' --prune-empty --tag-name-filter cat -- --all
git commit -m 'cleapup'
git push -u origin $gitbranch -f
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now

cd ..

rm -rf $directory
mkdir -p $directory &amp;&gt; /dev/null
cd $directory
git init
git remote add origin git@github.com:$gituser/$gitrepository
git pull --rebase origin $gitbranch -f
git rm *
git commit -m 'cleapup'

cd ../$backupdirectory/
tar -zcvf ../$directory/$backupfile.tar.gz *
cd ../$directory

git add *
git status
git commit -m 'upload'
git push -u origin $gitbranch -f
cd ..</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 将远程服务器的 LNMP 备份在本地复原</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-remote-lnmp-restore/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 10 Dec 2021 15:05:51 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Management (管理)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Backup (备份)]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Shell Website (网站)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19609</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：将远程服务器的 LNMP 备份还原到本地作用：将远程服务器的 LNMP 备份还原到本地 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. tmppath=/cache #本地用于备份数据的目录2. webpath=/usr/share/nginx/html #本地用于存放网站文件的目录3. key=”~/.ssh/eternalcenter” #本地私钥4. tmpfile=tmpfile.txt #用于存储记录的文件5. dbuser=ec #网站在数据库中的用户6. ruser=eternalcenter #用于远程服务器的用户7. rhost=eternalcenter.com #远程服务器8. rcache=”/cache” #远程服务器用于备份数据的目录 注意 1. 本地需要已经搭建好 LNMP 平台2. 用于远程服务器的用户，需要能免密钥 ssh 远程服务器，且对于本地用于备份数据的目录和远程服务器用于备份数据的目录拥有读和执行的权限3. 执行此脚本的用户需要有 sudo systemctl 权限4. 脚本 ”mysql -uroot -p&#8217;eternalcenter&#8217; ec &#60; $sqlfile“ 中 “eternalcenter“ 是指本地 MariaDB 数据库 root &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/shell-remote-lnmp-restore/" class="more-link">Continue reading<span class="screen-reader-text"> "[工具] Shell 将远程服务器的 LNMP 备份在本地复原"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：将远程服务器的 LNMP 备份还原到本地<br>作用：将远程服务器的 LNMP 备份还原到本地</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. tmppath=/cache #本地用于备份数据的目录<br>2. webpath=/usr/share/nginx/html #本地用于存放网站文件的目录<br>3. key=”~/.ssh/eternalcenter” #本地私钥<br>4. tmpfile=tmpfile.txt #用于存储记录的文件<br>5. dbuser=ec #网站在数据库中的用户<br>6. ruser=eternalcenter #用于远程服务器的用户<br>7. rhost=eternalcenter.com #远程服务器<br>8. rcache=”/cache” #远程服务器用于备份数据的目录</p>



<h3>注意</h3>



<p>1. 本地需要已经搭建好 LNMP 平台<br>2. 用于远程服务器的用户，需要能免密钥 ssh 远程服务器，且对于本地用于备份数据的目录和远程服务器用于备份数据的目录拥有读和执行的权限<br>3. 执行此脚本的用户需要有 sudo systemctl 权限<br>4. 脚本 ”mysql -uroot -p&#8217;eternalcenter&#8217; ec &lt; $sqlfile“ 中 “eternalcenter“ 是指本地 MariaDB 数据库 root 用户的密码，需要修改成本地 MariaDB 数据库的 root 用户密码</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

tmppath=/cache
webpath=/usr/share/nginx/html
key="~/.ssh/eternalcenter"
tmpfile=tmpfile.txt
dbuser=ec

ruser=eternalcenter
rhost=eternalcenter.com
rcache="/cache"

####################### Separator ########################

nowdirectory=`pwd`

a=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`
sleep 10
b=`ssh -i $key $ruser@$rhost "du -s $rcache" | awk '{print $1}'`

if &#91; $a -eq 0 ];then
	echo "no file"
fi

if &#91; $a -ne $b ];then
        echo "backup is running now"
        exit
fi

c=0

if &#91; -f $tmpfile ];then
        c=`cat $tmpfile`
fi

if &#91; $a -eq $c ];then
        echo "no new file"
        exit
fi

echo $a &gt; $tmpfile

sqlfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep sql | tail -1" | awk '{print $NF}'`
if &#91; $? -eq 0 ]; then

        tarfile=`ssh -i $key $ruser@$rhost "ls -rtlh $rcache | grep tar | tail -1" | awk '{print $NF}'`
        if &#91; $? -eq 0 ]; then

                rm -rf $tmppath/*
                mkdir $tmppatch &amp;&gt; /dev/null

                echo $sqlfile
                echo $tarfile

                scp -i $key $ruser@$rhost:$rcache/$sqlfile $tmppath
                scp -i $key $ruser@$rhost:$rcache/$tarfile $tmppath

#                sudo systemctl stop nginx
#                sudo systemctl stop php-fpm

                cd $tmppath

                mysql -uroot -p'eternalcenter' -e "drop database $dbuser;"
                mysql -uroot -p'eternalcenter' -e "create database $dbuser;"
                mysql -uroot -p'eternalcenter' -e "grant all privileges on $dbuser.* to \"$dbuser\"@\"localhost\";"
                mysql -uroot -p'eternalcenter' ec &lt; $sqlfile

                sudo rm -rf $webpath/*
                sudo tar -zxvf $tarfile -C $webpath/ &amp;&gt; /dev/null

#                sudo systemctl start nginx
#                sudo systemctl start php-fpm

                cd $nowdirectory

        fi
fi</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell LNMP 没运行则重启系统 （systemctl 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-lnmp-check-restart-systemctl/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 10 Dec 2021 14:26:19 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Nginx Monitor (监控)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Website Service (网站服务)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=19607</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：LNMP 没运行则重启系统作用：LNMP 没运行则重启系统 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：LNMP 没运行则重启系统<br>作用：LNMP 没运行则重启系统</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash
  
systemctl status nginx | grep 'active (running)'
if &#91; $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status mariadb | grep 'active (running)'
if &#91; $? -ne 0 ];then
        /usr/sbin/reboot
fi

systemctl status php-fpm | grep 'active (running)'
if &#91; $? -ne 0 ];then
        /usr/sbin/reboot
fi</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量修改多个远程服务器某个用户的密码 （精致版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-password-change-refined-version/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 10 Oct 2021 13:08:50 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Others (其它)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Login Security (系统登录安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System User (系统用户)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=18100</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量修改多个远程服务器某个用户的密码作用：批量修改多个远程服务器某个用户的密码 使用方法 1. 将此脚本和清单 $list 文件放在同一目录下2. 清单 $list 里每服务器名占用 1 行3. 给脚本分割线里的变量赋值4. 给此脚本添加执行权限5. 执行此脚本 脚本分割线里的变量 1. list=”list.txt” #指定清单的目录和名称2. user=eternalcenter #指定要修改密码的用户3. password=eternalcenter #指定要修改的密码 注意 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器，并且可以通过 sudo 获得 su 的 root 权限 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量修改多个远程服务器某个用户的密码<br>作用：批量修改多个远程服务器某个用户的密码</p>



<h3>使用方法</h3>



<p>1. 将此脚本和清单 $list 文件放在同一目录下<br>2. 清单 $list 里每服务器名占用 1 行<br>3. 给脚本分割线里的变量赋值<br>4. 给此脚本添加执行权限<br>5. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. list=”list.txt” #指定清单的目录和名称<br>2. user=eternalcenter #指定要修改密码的用户<br>3. password=eternalcenter #指定要修改的密码</p>



<h3>注意</h3>



<p>此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器，并且可以通过 sudo 获得 su 的 root 权限</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

list="list.txt"
user=eternalcenter
password=eternalcenter

####################### Separator ########################

num=1

cat $list
for i in `cat $list`
do
        echo $num
        echo $i

	ssh -t $i "type lsb_release" &amp;&gt; /dev/null
        if &#91; $? -ne 0 ]; then
              distribution=`ssh -t $i "cat /etc/*release | grep '^NAME'"`
	      if &#91; $? -ne 0 ];then
		      distribution=`ssh -t $i "cat /etc/*release"`
	      fi
        else
              distribution=`ssh -t $i "lsb_release -i | grep 'ID' | grep -v 'n/a'"`
        fi;

        echo $distribution

	case $distribution in
		*"RedHat"* | *"Red Hat"*)
		ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
		if &#91; $? -eq 0 ];then
			echo -e "\033&#91;32m$i is success\033&#91;0m"
		else
			echo -e "\033&#91;31m$i is fail\033&#91;0m"
		fi
		;;

		*"CentOS"*)
		ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
		if &#91; $? -eq 0 ];then
			echo -e "\033&#91;32m$i is success\033&#91;0m"
		else
			echo -e "\033&#91;31m$i is fail\033&#91;0m"
		fi
		;;

		*"SUSE"* | *"SLES"*)
		ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
		if &#91; $? -eq 0 ];then
			echo -e "\033&#91;32m$i is success\033&#91;0m"
		else
			echo -e "\033&#91;31m$i is fail\033&#91;0m"
		fi
		;;
               
		*"openSUSE"*)
		ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
		if &#91; $? -eq 0 ];then
			echo -e "\033&#91;32m$i is success\033&#91;0m"
		else
			echo -e "\033&#91;31m$i is fail\033&#91;0m"
		fi
		;;

		*)
                echo -e "\033&#91;31m$i is fail \033&#91;0m" 
		;;
        esac

        let num++

        echo
done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 实时监控内存 （永久版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-real-time-monitoring-endless/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 03 Oct 2021 05:15:52 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17672</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：实时监控内存作用：实时监控内存，并每 3 秒钟更新 1 次状态信息 使用方法 1. 给此脚本添加执行权限2. 执行此脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：实时监控内存<br>作用：实时监控内存，并每 3 秒钟更新 1 次状态信息</p>



<h3>使用方法</h3>



<p>1. 给此脚本添加执行权限<br>2. 执行此脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

while true
do
        sleep 10
        free -m | head -1
        free -g | grep Mem
done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 实时监控内存 （进行 100 次版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-real-time-monitoring-100/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 01 Sep 2021 06:16:11 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17605</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：实时监控内存作用：实时监控内存，并每 3 秒钟更新 1 次状态信息，总过进行 100 次 使用方法 1. 给此脚本添加执行权限2. 执行此脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：实时监控内存<br>作用：实时监控内存，并每 3 秒钟更新 1 次状态信息，总过进行 100 次</p>



<h3>使用方法</h3>



<p>1. 给此脚本添加执行权限<br>2. 执行此脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

i=1

free -m | head -1

while &#91; $i -le 100 ]
do
        let i=i+1
        free -m | grep Mem
        sleep 3
done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量重启多个远程服务器的服务</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-batch-restart/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 06 Aug 2021 07:48:11 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Others (其它)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17263</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量重启多个远程服务器的服务作用：批量重启多个远程服务器的服务 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. myuser=”eternalcenter” #登录远程服务器的用户2. myserver=”192.168.1.1 192.168.1.2″ #要登录的远程服务器，以空格隔开3. myservice=&#8221;nginx&#8221; #需要重启的服务，以空格隔开4. mysudo=”no” #是否使用 sudo 提权，请选择 yes 或者 no 注意 1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器2. 必须以 root 用户执行本脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量重启多个远程服务器的服务<br>作用：批量重启多个远程服务器的服务</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. myuser=”eternalcenter” #登录远程服务器的用户<br>2. myserver=”192.168.1.1 192.168.1.2″ #要登录的远程服务器，以空格隔开<br>3. myservice=&#8221;nginx&#8221; #需要重启的服务，以空格隔开<br>4. mysudo=”no” #是否使用 sudo 提权，请选择 yes 或者 no</p>



<h3>注意</h3>



<p>1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器<br>2. 必须以 root 用户执行本脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

myuser="eternalcenter.com"
myserver="192.168.1.1 192.168.1.2 192.168.1.3" #each server is separated by a space
myservice="nginx" #each myservice is separated by a space
mysudo="yes" #please choose "yes" or "no"

####################### Separator ########################

mynow=`date +%Y-%m-%d-%H-%s`

if &#91; $mysudo == 'yes' ];then
        myrestart(){
                ssh -t $1@$2 "sudo -u root su - root -c \"systemctl restart $3\""
        }
        echo "use sudo"
fi

if &#91; $mysudo == 'no' ];then
        myrestart(){
                ssh -t $1@$2 "systemctl restart $3"
        }
        echo "don't use sudo"
fi

for services in $myservice
do

        for servers in `echo $myserver`
        do
                myrestart $myuser $servers $services
        done

done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量将本地文件拷贝到多个远程服务器</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-batch-copy/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 06 Aug 2021 07:37:57 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Others (其它)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17261</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：批量将本地文件拷贝到多个远程服务器作用：批量将本地文件拷贝到多个远程服务器 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. myuser=&#8221;eternalcenter&#8221; #登录远程服务器的用户2. myserver=&#8221;192.168.1.1 192.168.1.2&#8243; #要登录的远程服务器，以空格隔开3. myfile=&#8221;/home/zhumingyu/test1.txt /home/zhumingyu/test2.txt&#8221; #要拷贝的文件，以空格隔开，必须是绝对路劲4. mysudo=&#8221;no&#8221; #是否使用 sudo 提权，请选择 yes 或者 no 注意 1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器2. 必须以 root 用户执行本脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h2>介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量将本地文件拷贝到多个远程服务器<br>作用：批量将本地文件拷贝到多个远程服务器</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. myuser=&#8221;eternalcenter&#8221; #登录远程服务器的用户<br>2. myserver=&#8221;192.168.1.1 192.168.1.2&#8243; #要登录的远程服务器，以空格隔开<br>3. myfile=&#8221;/home/zhumingyu/test1.txt /home/zhumingyu/test2.txt&#8221; #要拷贝的文件，以空格隔开，必须是绝对路劲<br>4. mysudo=&#8221;no&#8221; #是否使用 sudo 提权，请选择 yes 或者 no</p>



<h3>注意</h3>



<p>1. 此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器<br>2. 必须以 root 用户执行本脚本</p>



<h2>脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

####################### Separator ########################

myuser="eternalcenter"
myserver="192.168.1.1 192.168.1.2" #each server is separated by a space
myfile="/home/zhumingyu/test1.txt /home/zhumingyu/test2.txt" #each file is separated by a space, absolute road force must be used
mysudo="no" #please choose "yes" or "no"

####################### Separator ########################

mynow=`date +%Y-%m-%d-%H-%s`
mycontext=${myfile##*\/}

if &#91; $mysudo == 'yes' ];then
        myreplace(){
                scp $3 $1@$2:/tmp/$5
                ssh -t $1@$2 "sudo -u root su - root -c \"mv $3 $3-$4;mv /tmp/$5 $3\""
        }
        echo "use sudo"
fi

if &#91; $mysudo == 'no' ];then
        myreplace(){
                scp $3 $1@$2:/tmp/$5
                ssh -t $1@$2 "mv $3 $3-$4;mv /tmp/$5 $3"
        }
        echo "don't use sudo"
fi

for files in $myfile
do

        if &#91; -f $files ];then

                for servers in `echo $myserver`
                do
                                myreplace $myuser $servers $files $mynow $mycontext
                done
        else
                echo "$files does not exist"
        fi

done</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 显示所有可升级的软件版本，并自动生成相应的升级命令 （openSUSE &#038; SLE）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-rpms-info-command-opensuse-sle/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 27 Jul 2021 08:34:16 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Monitor (监控)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17150</guid>

					<description><![CDATA[介绍 基本信息 作者：朱明宇名称：openSUSE &#38; SLE 显示所有可升级的软件版本，并自动生成相应的升级命令作用：openSUSE &#38; SLE 显示所有可升级的软件版本，并自动生成相应的升级命令 使用方法 给此脚本添加执行权限执行此脚本执行此脚本大致会生成以下内容： 脚本]]></description>
										<content:encoded><![CDATA[
<h2 id="介绍">介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：openSUSE &amp; SLE 显示所有可升级的软件版本，并自动生成相应的升级命令<br>作用：openSUSE &amp; SLE 显示所有可升级的软件版本，并自动生成相应的升级命令</p>



<h3>使用方法</h3>



<p>给此脚本添加执行权限<br>执行此脚本<br>执行此脚本大致会生成以下内容：</p>



<pre class="wp-block-code"><code>zypper update  MozillaFirefox-78.12.0-lp152.2.61.1 MozillaFirefox-translations-common-78.12.0-lp152.2.61.1 alsa-oss-1.1.8-lp152.4.3.1</code></pre>



<h2 id="脚本">脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash

m=''

for n in `zypper list-updates | tail -n +5 | awk '{print $7"-"$11}'`
do
        m="$m $n"
done

echo "zypper update $m"</code></pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
