first commit

This commit is contained in:
iProbe 2022-10-18 16:59:37 +08:00
commit ba848e218d
1001 changed files with 152333 additions and 0 deletions

175
shell/awk.html Normal file
View file

@ -0,0 +1,175 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>awk</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">awk</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1506414295978_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 231px;">ARGC 命令行参数个数
ARGV 命令行参数排列
ENVIRON 支持队列中系统环境变量的使用
FILENAME awk浏览的文件名
FNR 浏览文件的记录数
FS 设置输入域分隔符,等价于命令行 -F选项
NF 浏览记录的域的个数
NR 已读的记录数
OFS 输出域分隔符
ORS 输出记录分隔符
RS 控制记录分隔符​​</pre><p>统计各连接状态的个数</p><p>netstat -anltp | awk '{++S[$6]} END {for(i in S) print "\t",i,"\t",S[i]}'</p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

165
shell/echo带颜色.html Normal file
View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>echo带颜色</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">echo带颜色</h1>
<div class="content-html" id="leanote-content"><p>格式: echo -e "\033[字背景颜色;字体颜色m字符串\033[0m"&nbsp;</p><p><strong></strong></p><div id="article_content" class="article_content">字背景颜色范围:40----49&nbsp;<br>40:黑&nbsp;<br>41:深红&nbsp;<br>42:绿&nbsp;<br>43:黄色&nbsp;<br>44:蓝色&nbsp;<br>45:紫色&nbsp;<br>46:深绿&nbsp;<br>47:白色&nbsp;<br><br>字颜色:30-----------39&nbsp;<br>30:黑&nbsp;<br>31:红&nbsp;<br>32:绿&nbsp;<br>33:黄&nbsp;<br>34:蓝色&nbsp;<br>35:紫色&nbsp;<br>36:深绿&nbsp;<br>37:白色&nbsp;<br><br>===============================================ANSI控制码的说明&nbsp;<br>\33[0m 关闭所有属性&nbsp;<br>\33[1m 设置高亮度&nbsp;<br>\33[4m 下划线&nbsp;<br>\33[5m 闪烁&nbsp;<br>\33[7m 反显&nbsp;<br>\33[8m 消隐&nbsp;<br>\33[30m -- \33[37m 设置前景色&nbsp;<br>\33[40m -- \33[47m 设置背景色&nbsp;<br>\33[nA 光标上移n行&nbsp;<br>\33[nB 光标下移n行&nbsp;<br>\33[nC 光标右移n行&nbsp;<br>\33[nD 光标左移n行&nbsp;<br>\33[y;xH设置光标位置&nbsp;<br>\33[2J 清屏&nbsp;<br>\33[K 清除从光标到行尾的内容&nbsp;<br>\33[s 保存光标位置&nbsp;<br>\33[u 恢复光标位置&nbsp;<br>\33[?25l 隐藏光标&nbsp;<br>\33[?25h 显示光标</div><p><br></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,178 @@
#!/bin/bash
# Edit by ZeroC
# 2020/03/13
eureka=/home/appuser/insurance/servers/application-insurance-discovery-server/application-insurance-discovery-server.jar
discovery=application-insurance-discovery-server.jar
env=dev
# 参数检查及赋值
getParameter()
{
while [ -n "$1" ];do
case $1 in
--publicdir)
if [ -n "$2" ];then
# jar包临时存放目录
publicdir=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
--basedir)
if [ -n "$2" ];then
# 项目根目录
basedir=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
--project)
if [ -n "$2" ];then
# 应用名字
project=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
--package)
if [ -n "$2" ];then
# 包名
package=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
--option)
if [ -n "$2" ];then
# jar启动参数
option=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
--proption)
if [ -n "$2" ];then
# 项目运行参数
proption=$2
shift 2
else
echo -e "\033[32m$1 not set! \033[0m"
exit 1
fi
;;
*)
echo -e "\033[32mParameter wrong! \033[0m"
exit 1
;;
esac
done
if [ ! -n $publicdir ] || [ ! -n $basedir ] || [ ! -n $project ] || [ ! -n $package ];then
echo -e "\033[32mpublicdir/basedir/project/package not set! \033[0m"
exit 1
fi
}
# 检查并创建目录
dirIsExists()
{
if [ ! -d $1 ];then
mkdir -p $1
fi
}
# 创建必要目录
mkDir()
{
# 配置文件目录
confdir=$basedir/prod_conf
# 配置文件目录
appconfdir=$confdir/$project
# 应用存放目录
projectdir=$basedir/$project
# 过去版本存放目录
versionsdir=$projectdir/versions
if [ ! -d "$appconfdir" ];then
echo -e "\033[32mConfig directory not EXISTS! Please CHECK ! \033[0m"
exit 1
fi
dirIsExists $projectdir
dirIsExists $versionsdir
}
# 移动到对应目录并创建软链接
lnSoft()
{
if [ -f $publicdir/$package ];then
sign=`date +%Y%m%d-%H%M%S`
projectname=`echo $package | awk -F'.' '{print $1}'`
mv $publicdir/$package $versionsdir/$projectname-${sign}.jar
find $versionsdir -name "$projectname-*.jar" -mtime +7 -exec rm -rf {} \;
rm -rf $basedir/servers/$project/$package
ln -s $versionsdir/$projectname-${sign}.jar $basedir/servers/$project/$package
else
echo -e "\033[32m$package not Found in $publicdir! \033[0m"
exit 1
fi
}
# 启动jar文件
jarAction()
{
e_status=`ps aux | grep $discovery | grep -v grep | awk '{print $2}'`
if [ -z $e_status ];then
nohup java -jar $eureka > /dev/null 2>&1 &
fi
echo -e "\033[31mCreate soft Link\033[0m"
lnSoft
echo -e "\033[31mStop $project if Exists! \033[0m"
jar_status=`ps aux | grep $package |grep "java -jar" | grep -v grep | awk '{print $2}'`
if [ -n '$jar_status' ];then
kill -9 $jar_status > /dev/null 2>&1
fi
echo -e "\033[31mStart $project Now! \033[0m"
#cd $basedir/servers/$project && echo "nohup java -jar $package --spring.profiles.active=$env -Dspring.config.location=$appconfdir/application-${env}.yml > /dev/null 2>&1 &" | bash
if [[ $option ]] && [[ $proption ]];then
#cd $basedir/servers/$project && echo "nohup java -jar $option $package > /dev/null 2>&1 &" | bash
cd $basedir/servers/$project && echo "nohup java -jar $option $package $proption > /dev/null 2>&1 &" | bash
elif [[ $option ]] && [[ ! $proption ]];then
cd $basedir/servers/$project && echo "nohup java -jar $option $package > /dev/null 2>&1 &" | bash
elif [[ ! $option ]] && [[ $proption ]];then
cd $basedir/servers/$project && echo "nohup java -jar $package $proption > /dev/null 2>&1 &" | bash
else
cd $basedir/servers/$project && echo "nohup java -jar $package > /dev/null 2>&1 &" | bash
fi
if [ -z '$jar_status' ];then
echo -e "\033[32m$project start FAIL! \033[0m"
exit 1
fi
}
main()
{
getParameter "$@"
mkDir
jarAction
}
source /home/appuser/.bash_profile
main "$@"

View file

@ -0,0 +1,60 @@
```
#!/bin/bash
##Edit by wangsuipeng
##Date 2016/10/20
## Rsync 客户端脚本
## 脚本说明:
##
## 操作说明:执行过本脚本以后,需要添加到定时任务中
## 并删除定时任务中的其他应用同步命令,即
## 带有/opt/appl/assist/rsync/的脚本,为
## 安全起见,请确认是否是应用同步脚本
##项目名
read -p "The Project name:[Not username]" PRO_NAME
##服务端IP
read -p "The Server IP:" PRO_HOST_IP
##脚本存放位置
DIRPATH=/usr/local/rsync
##密码文件
PASS_CFG=$DIRPATH/rsyncd.pass
##脚本文件
SCRIPT=$DIRPATH/rsync_${PRO_HOST_IP}-${PRO_NAME}.sh
EXCLUDE_CONF()
{
cat > /usr/local/rsync/exclude << EOF
log/*
logs/*
temp/*
backup/*
deployment/*
*.tar.gz
*.tgz
*.log
*.out
EOF
}
if [ -d $DIRPATH ]
then
if [ -f $DIRPATH/rsyncd.pwd ]
then
cd $DIRPATH && tar zcvf bak.`date +%d%H%M`.tar.gz --exclude *.tar.gz * --remove-files >/dev/null 2>&1
fi
else
mkdir -p $DIRPATH
fi
EXCLUDE_CONF
echo "/usr/bin/rsync -arP --delete --exclude-from=/usr/local/rsync/exclude --password-file=$PASS_CFG rsync@$PRO_HOST_IP::${PRO_NAME}2016 /opt/appl/$PRO_NAME/" > $SCRIPT
chmod +x $SCRIPT
echo "123456" > $PASS_CFG
```

View file

@ -0,0 +1,68 @@
```
#!/bin/bash
##Edit by wangsuipeng
##Date 2016/10/25
## Rsync 客户端脚本-用于灾备环境搭建
##
## 脚本说明:
##
## 操作说明:执行过本脚本以后,需要添加到定时任务中
## 并删除定时任务中的其他应用同步命令,即
## 带有/opt/appl/assist/rsync/的脚本,为
## 安全起见,请确认是否是应用同步脚本
##项目名
read -p "The Project name[Not username]" PRO_NAME
##服务端IP
read -p "The Server IP:" PRO_HOST_IP
##容器
read -p "The Software[jboss/tomcat]:" SOFT
yum -y install rsync xinetd > /dev/null 2>&1
##脚本存放位置
DIRPATH=/usr/local/rsync
##密码文件
PASS_CFG=$DIRPATH/rsyncd.pass
##脚本文件
SCRIPT=$DIRPATH/rsync_${PRO_HOST_IP}-${PRO_NAME}.sh
EXCLUDE_CONF()
{
cat > /usr/local/rsync/exclude << EOF
log/*
logs/*
temp/*
backup/*
deployment/*
*.tar.gz
*.tgz
*.log
*.out
jdk*
work/*
EOF
}
if [ -d $DIRPATH ]
then
if [ -f $DIRPATH/rsyncd.pwd ]
then
cd $DIRPATH && tar zcvf bak.`date +%d%H%M`.tar.gz --exclude *.tar.gz * --remove-files >/dev/null 2>&1
fi
else
mkdir -p $DIRPATH
fi
EXCLUDE_CONF
echo "#!/bin/bash" > $SCRIPT
echo "/usr/bin/rsync -arP --delete --bwlimit=200 --exclude-from=/usr/local/rsync/exclude --password-file=$PASS_CFG rsync@$PRO_HOST_IP::${PRO_NAME}19 /opt/appl/$PRO_NAME/$SOFT" >> $SCRIPT
chmod +x $SCRIPT
echo "123456" > $PASS_CFG
```

View file

@ -0,0 +1,103 @@
```
#!/bin/bash
##Edit by wangsuipeng
##Date 2016/10/20
## Rsync 服务器端脚本
## 脚本说明如果系统中已存在rsyncd.conf文件在该文件后面追加配置项
## 如果不存在,则新建该文件,并添加配置项
## 操作说明:执行过本脚本以后,需要做客户端配置
##项目名
read -p "The Project name:[Not username]" PRO_NAME
##客户端IP
read -p "The Client IP:" PRO_BACK_IP
##项目存放位置(类似/opt/appl/project)
read -p "The Project path:[/opt/appl/project]" PRO_PATH
##项目用户UID
PRO_UID=`stat -c %u $PRO_PATH`
##配置文件
RSYNC_CFG=/etc/rsyncd.conf
##密码文件
PASS_CFG=/etc/rsyncd.pass
yum -y install rsync xinetd > /dev/null 2>&1
##存在rsyncd.conf文件
EXCFG()
{
cat >> $RSYNC_CFG <<EOF
[${PRO_NAME}2016]
path = $PRO_PATH
uid = $PRO_UID
gid = 1500
read only = yes
list = yes
allows host = $PRO_BACK_IP
secrets file = /etc/rsyncd.pass
EOF
}
##不存在rsyncd.conf文件
NOCFG()
{
cat > $RSYNC_CFG <<EOF
uid = root
gid = root
use chroot = no
max connections = 100
timout = 600
pid file = /var/run/rsyncd.pid
lock file =/var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[${PRO_NAME}2016]
path = $PRO_PATH
uid = $PRO_UID
gid = 1500
read only = yes
list = yes
allows host = $PRO_BACK_IP
secrets file = /etc/rsyncd.pass
EOF
}
if [ -f $RSYNC_CFG ]
then
EXCFG
else
NOCFG
fi
echo "rsync:123456" > $PASS_CFG
if grep -q "rsync:$PRO_BACK_IP:allow" /etc/hosts.allow
then
# exit 0 ---直接退出脚本
echo
else
echo "rsync:$PRO_BACK_IP:allow" >> /etc/hosts.allow
fi
if grep -q "\byes\b" /etc/xinetd.d/rsync
then
sed -i 's/yes/no/g' /etc/xinetd.d/rsync
fi
service xinetd restart
if grep -q "\b873\b" /etc/sysconfig/iptables
then
# exit 0 ---直接退出脚本
echo
else
iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT && service iptables save && service iptables restart
fi
```

View file

@ -0,0 +1,103 @@
```
#!/bin/bash
##Edit by wangsuipeng
##Date 2016/10/25
## Rsync 服务器端脚本-用于灾备环境搭建
##
## 脚本说明如果系统中已存在rsyncd.conf文件在该文件后面追加配置项
## 如果不存在,则新建该文件,并添加配置项
## 操作说明:执行过本脚本以后,需要做客户端配置
##项目名
read -p "The Project name[Not username]:" PRO_NAME
##灾备IP
read -p "The DR IP:" PRO_BACK_IP
##项目存放位置(类似/opt/appl/project/[tomcat/jboss])
read -p "The Project path[/opt/appl/project/[tomcat/jboss]]:" PRO_PATH
##项目用户UID
PRO_UID=`stat -c %u $PRO_PATH`
##配置文件
RSYNC_CFG=/etc/rsyncd.conf
##密码文件
PASS_CFG=/etc/rsyncd.pass
yum -y install rsync xinetd > /dev/null 2>&1
##存在rsyncd.conf文件
EXCFG()
{
cat >> $RSYNC_CFG <<EOF
[${PRO_NAME}19]
path = $PRO_PATH
uid = $PRO_UID
gid = 1500
read only = yes
list = yes
allows host = $PRO_BACK_IP
secrets file = /etc/rsyncd.pass
EOF
}
##不存在rsyncd.conf文件
NOCFG()
{
cat > $RSYNC_CFG <<EOF
uid = root
gid = root
use chroot = no
max connections = 100
timout = 600
pid file = /var/run/rsyncd.pid
lock file =/var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[${PRO_NAME}19]
path = $PRO_PATH
uid = $PRO_UID
gid = 1500
read only = yes
list = yes
allows host = $PRO_BACK_IP
secrets file = /etc/rsyncd.pass
EOF
}
if [ -f $RSYNC_CFG ]
then
EXCFG
else
NOCFG
fi
echo "rsync:123456" > $PASS_CFG
if grep -q "rsync:$PRO_BACK_IP:allow" /etc/hosts.allow
then
# exit 0 ---直接退出脚本
echo
else
echo "rsync:$PRO_BACK_IP:allow" >> /etc/hosts.allow
fi
if grep -q "\byes\b" /etc/xinetd.d/rsync
then
sed -i 's/yes/no/g' /etc/xinetd.d/rsync
/etc/init.d/xinetd restart
fi
if grep -q "\b873\b" /etc/sysconfig/iptables
then
# exit 0 ---直接退出脚本
echo
else
iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT && service iptables save && service iptables restart
fi
```

15
shell/safe/00-backup.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
# 备份
cp /etc/pam.d/su $backupdir
cp /etc/pam.d/sshd $backupdir
cp /etc/pam.d/login $backupdir
cp /etc/ssh/sshd_config $backupdir
cp /etc/profile $backupdir
cp /etc/sysctl.conf $backupdir
cp /etc/hosts.allow $backupdir
cp /etc/hosts.deny $backupdir
cp /etc/selinux/config $backupdir

View file

@ -0,0 +1,6 @@
#!/bin/bash
# 密码长度
sed -i 's/^PASS_MIN_LEN 5/PASS_MIN_LEN $lenth/g' /etc/login.defs
# 密码过期
sed -i 's/^PASS_MAX_DAYS 99999/PASS_MAX_DAYS $days/g' /etc/login.defs

6
shell/safe/02-host.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
sed -i '$a\ALL:ALL:deny' /etc/hosts.deny
for ip in $ip_h;do
sed -i '$a\sshd:$ssh_port:allow' /etc/hosts.allow
done

3
shell/safe/03-selinux.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
sed -i 's@^SELINUX=enforcing@SELINUX=permissive@' /etc/selinux/config

10
shell/safe/04-firewall.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
# 添加端口访问
for ip in $ip_f;do
firewall-cmd --zone=work --add-source=$ip/24 --permanent
done
firewall-cmd --zone=work --add-port=$ssh_port/tcp --permanent
firewall-cmd --zone=work --add-port=$http_port/tcp --permanent
firewall-cmd --zone=work --add-port=$https_port/tcp --permanent
firewall-cmd --reload

10
shell/safe/05-sshd.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
# sshd端口
sed -i "/^#Port 22/a\Port $ssh_port" /etc/ssh/sshd_config
# 限制root用户远程
sed -i '/#PermitRootLogin yes/a\PermitRootLogin no' /etc/ssh/sshd_config
# 限制管理用户与应用用户登录。允许manager登录允许appl_user通过ip_ssh登录
sed -i "\$a\AllowUsers $manager $appl_user@$ip_ssh" /etc/ssh/sshd_config
/bin/systemctl restart sshd

6
shell/safe/06-limit.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
# 禁止非whell组用户使用su切换用户
sed -i '/pam_wheel.so use_uid$/a\auth\t\trequired\tpam_wheel.so use_uid' /etc/pam.d/su
# 只允许wheel组中的用户使用su
sed -i '$a\SU_WHEEL_ONLY yes' /etc/login.defs

5
shell/safe/07-lock.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# 登录失败3次就锁用户300s
sed -i '/^#%PAM-1.0/a\auth\t required\tpam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=300' /etc/pam.d/sshd
sed -i '/^#%PAM-1.0/a\auth\trequired\tpam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=300' /etc/pam.d/login

20
shell/safe/08-sysctl.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# 开启SYN Cookies预防Flood
sed -i '$a\net.ipv4.tcp_syncookies = 1' /etc/sysctl.conf
# 开启重用允许将TIME-WAIT套接字重新用于新的TCP连接
sed -i '$a\net.ipv4.tcp_tw_reuse = 1' /etc/sysctl.conf
# 开启TCP连接中TIME-WAIT套接字的快速回收
sed -i '$a\net.ipv4.tcp_tw_recycle = 1' /etc/sysctl.conf
# 如果套接字由本端要求关闭这个参数决定了它保持在FIN-WAIT-2状态的时间单位s
sed -i '$a\net.ipv4.tcp_fin_timeout = 30' /etc/sysctl.conf
# 当keepalive启用时TCP发送keepalive消息的频度单位s
sed -i '$a\net.ipv4.tcp_keepalive_time = 1200' /etc/sysctl.conf
# 向外连接的端口范围
sed -i '$a\net.ipv4.ip_local_port_range = 1024 65000' /etc/sysctl.conf
# SYN队列的长度
sed -i '$a\net.ipv4.tcp_max_syn_backlog = 8192' /etc/sysctl.conf
# 系统同时保持TIME_WAIT套接字的最大数量
sed -i '$a\net.ipv4.tcp_max_tw_buckets = 5000' /etc/sysctl.conf
/usr/sbin/sysctl -p

6
shell/safe/09-timeout.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
# 3分钟未操作断掉连接
sed -i 's/^#ClientAliveInterval 0/ClientAliveInterval 60/' /etc/ssh/sshd_config
sed -i 's/^#ClientAliveCountMax/ClientAliveCountMax/' /etc/ssh/sshd_config
sed -i '$a\TMOUT=300\nexport TMOUT' /etc/profile

7
shell/safe/10-umask.sh Normal file
View file

@ -0,0 +1,7 @@
#!/bin/bash
# umask
sed -i 's/umask 022/umask $umask_/' /etc/profile
sed -i 's/umask 002/umask $umask_/' /etc/profile
sed -i 's/umask 022/umask $umask_/' /etc/bashrc
sed -i 's/umask 002/umask $umask_/' /etc/bashrc

33
shell/safe/11-user.sh Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
## 创建管理用户
echo $root_password | passwd --stdin root
# 管理组
/usr/sbin/groupadd -g $manager_group_id $manager_group
# 应用管理组
/usr/sbin/groupadd -g $appl_group_id $appl_group
# 数据库管理组
/usr/sbin/groupadd -g $db_group_id $db_group
# 查看日志组
/usr/sbin/groupadd -g $logs_group_id $logs_group
# 管理用户
/usr/sbin/useradd -u $manager_id -g $manager_group_id -G 0,10 $manager
echo $manager_password | passwd --stdin $manager
# 应用管理用户
/usr/sbin/useradd -u $appl_user_id -g $appl_group_id $appl_user
echo $appl_user_password | passwd --stdin $appl_user
# 数据库管理用户
/usr/sbin/useradd -u $db_user_id -g $db_group_id $db_user
echo $db_user_password | passwd --stdin $db_user
# 查看日志用户
/usr/sbin/useradd -u $logs_user_id -g $logs_group_id -G $appl_group_id $logs_user
echo $logs_user_password | passwd --stdin $logs_user

28
shell/safe/12-chattr.sh Normal file
View file

@ -0,0 +1,28 @@
#/bin/bash
# 锁定文件
chattr +i /etc/passwd
chattr +i /etc/group
chattr +i /etc/sudoers
chattr +i /etc/profile
chattr +i /etc/bashrc
chattr +i /etc/ssh/sshd_config
chattr +i /etc/init.d/
chattr +i /etc/rc.d/
chattr +i /etc/crontab
chattr +i /etc/cron.d/
chattr +i /etc/hosts.allow
chattr +i /etc/hosts.deny
chattr +i /usr/bin
chattr +i /usr/sbin
chattr +i /usr/local/sbin
chattr +i /usr/local/bin
chattr +i /usr/libexec
chattr +i /sbin/
chattr +i /bin/
chattr +i /etc/yum.repos.d/
chattr +i /var/spool/cron/

64
shell/safe/config.sh Normal file
View file

@ -0,0 +1,64 @@
#!/bin/bash
# 备份目录
backupdir=/opt
# root密码
root_password="Op@2019"
# 管理组
manager_group="ops"
# 管理组id
manager_group_id=500
# 管理用户
manager="opm"
# 管理用户id
manager_id=501
# 管理用户密码
manager_password="Opm#Qhiex&19"
# 应用组
appl_group="appgroup"
# 应用组id
appl_group_id=1000
# 应用用户
appl_user="appuser"
# 应用用户id
appl_user_id=1001
# 应用用户密码
appl_user_password="appuser@2019"
# 数据库管理组
db_group="dbgroup"
# 数据库管理组id
db_group_id=1500
# 数据库管理用户
db_user="dbuser"
# 数据库管理用户id
db_user_id=1501
# 数据库管理用户密码
db_user_password="database@2019"
# 查看日志组
logs_group="devgroup"
# 查看日志组id
logs_group=2000
# 查看日志用户
logs_user="dev"
# 查看日志用户id
logs_user_id=2001
# 查看日志用户密码
logs_user_password="dev@2019"
# ssh端口
ssh_port=16512
# http端口
http_port=80
# https端口
https_port=443
# 密码最短长度
lenth=8
# 密码过期时间
days=180
# umask
umask_=027
# 访问ip(firewall),以空格为分隔符
ip_f="192.168.1.0"
# 访问ip(hosts),以空格为分隔符
ip_h="192.168.1.*"
# 限制登录ip
ip_ssh="172.18.104.*"

17
shell/safe/jiagu.sh Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
. ./config.sh
./00-backup.sh
./01-password.sh
./02-host.sh
./03-selinux.sh
./04-firewall.sh
./05-sshd.sh
./06-limit.shi
./07-lock.sh
./08-sysctl.sh
./09-timeout.s
./10-umask.sh
./11-user.sh
./12-chattr.sh

View file

@ -0,0 +1,196 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>shell中的字典与数组</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">shell中的字典与数组</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1489540684458_0" class="brush:sh ace-tomorrow">#!/bin/bash
echo "shell定义字典"
#必须先声明
declare -A dic
dic=([key1]="value1" [key2]="value2" [key3]="value3")
#打印指定key的value
echo ${dic["key1"]}
#打印所有key值
echo ${!dic[*]}
#打印所有value
echo ${dic[*]}
#遍历key值
for key in $(echo ${!dic[*]})
do
echo "$key : ${dic[$key]}"
done
echo "shell定义数组"
#数组
list=("value1" "value2" "value3")
#打印指定下标
echo ${list[1]}
#打印所有下标
echo ${!list[*]}
#打印数组下标
echo ${list[*]}
#数组增加一个元素
list=("${list[@]}" "value3")</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>shell切分字符串</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">shell切分字符串</h1>
<div class="content-html" id="leanote-content"><p>假设有变量 var=http://www.aaa.com/123.htm.</p><p><strong>1. # 号截取,删除左边字符,保留右边字符。</strong></p><pre id="leanote_ace_1510641012228_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 21px;">echo ${var#*//}</pre><div class="cnblogs_Highlighter sh-gutter"></div><p>&nbsp;其中 var 是变量名,# 号是运算符,*// 表示从左边开始删除第一个 // 号及左边的所有字符<br>即删除 http://<br>结果是 www.aaa.com/123.htm</p><p><strong>2. ## 号截取,删除左边字符,保留右边字符。</strong></p><pre id="leanote_ace_1510641029237_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 21px;">echo ${var##*/}</pre><p>##*/ 表示从左边开始删除最后(最右边)一个 / 号及左边的所有字符<br>即删除 http://www.aaa.com/</p><p>结果是 123.htm</p><p><strong>3. %号截取,删除右边字符,保留左边字符</strong></p><pre id="leanote_ace_1510641048759_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 21px;">echo ${var%/*}</pre><p>%/* 表示从右边开始,删除第一个 / 号及右边的字符</p><p>结果是http://www.aaa.com</p><p><strong>4. %% 号截取,删除右边字符,保留左边字符</strong></p><pre id="leanote_ace_1510641063144_0" class="brush:sh ace-tomorrow" data-mce-style="line-height: 1.5; font-size: 14px; height: 21px;">echo ${var%%/*}</pre><div class="cnblogs_Highlighter sh-gutter"></div><p>&nbsp;%%/* 表示从右边开始,删除最后(最左边)一个 / 号及右边的字符<br>结果是http:<br>5. 从左边第几个字符开始,及字符的个数</p><pre id="leanote_ace_1510641082309_0" class="brush:sh ace-tomorrow">echo ${var:0:5}</pre><p>其中的 0 表示左边第一个字符开始5 表示字符的总个数。<br>结果是http:</p><p><strong>6. 从左边第几个字符开始,一直到结束。</strong></p><pre id="leanote_ace_1510641095161_0" class="brush:sh ace-tomorrow">echo ${var:7}</pre><p>其中的 7 表示左边第8个字符开始一直到结束。<br>结果是 www.aaa.com/123.htm</p><p><strong>7. 从右边第几个字符开始,及字符的个数</strong></p><pre id="leanote_ace_1510641110972_0" class="brush:sh ace-tomorrow">echo ${var:0-7:3}</pre><p>其中的 0-7 表示右边算起第七个字符开始3 表示字符的个数。<br>结果是123</p><p><strong>8. 从右边第几个字符开始,一直到结束。</strong></p><pre id="leanote_ace_1510641115755_0" class="brush:sh ace-tomorrow">echo ${var:0-7}</pre><p>表示从右边第七个字符开始,一直到结束。<br>结果是123.htm</p><p>注:(左边的第一个字符是用 0 表示,右边的第一个字符用 0-1 表示)</p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,34 @@
#!/bin/bash
# 关闭端口
# 未判断端口是否是数字
# /usr/bin/firewall-cmd --zone=work --remove-port=xx/tcp --permanent
if [ $# -eq 0 ];then
echo -e "\033[32;1mUSGE:$0 [port]\033[0m"
exit 1
else
while [ $# -gt 0 ]; do
read -p "$1: TCP or UDP[default TCP]:" protocol
: ${protocol:=tcp}
case $protocol in
tcp|TCP)
protocol="tcp"
;;
udp|UDP)
protocol="udp"
;;
*)
echo -e "\033[31;1mCan not recognization the $protocol\033[0m"
;;
esac
port=`/usr/bin/firewall-cmd --zone=work --list-port | grep -o $1/$protocol`
if [[ -n $port ]];then
/usr/bin/firewall-cmd --zone=work --remove-port=$1/$protocol --permanent
else
echo -e "\033[31;1m$1/$protocol not open! \033[0m"
fi
shift
done
/usr/bin/firewall-cmd --reload
fi

View file

@ -0,0 +1,26 @@
#!/bin/bash
## 定时任务
if [ $# -le 5 ];then
echo -e "\033[32;1m格式错误\033[0m"
echo -e "\033[32;1mUSGE:$0 \"x x x x x [script]\"\033[0m"
exit 1
else
read -p "Choose User Execute the task[default root]:" user
: ${user:=root}
u=`cat /etc/passwd | awk -F ':' '{print $1}' |grep $user`
if [ -n $u ];then
chattr -i /etc/crontab
chattr -i /etc/cron.d/
chattr -i /var/spool/cron/
echo $* >> /var/spool/cron/$user
chattr +i /etc/crontab
chattr +i /etc/cron.d/
chattr +i /var/spool/cron/
else
echo -e "\033[31;1m$user is not exists! \033[0m"
exit 1
fi
fi

View file

@ -0,0 +1,39 @@
#!/bin/bash
## 更新或安装软件
# yum install/update -y [software]
if [ $# -eq 0 ];then
echo -e "\033[31;1mUSGE:$0 [software]\033[0m"
exit 1
else
# chattr -i
chattr -i /usr/bin
chattr -i /usr/sbin
chattr -i /usr/local/sbin
chattr -i /usr/local/bin
chattr -i /usr/libexec
chattr -i /sbin/
chattr -i /bin/
chattr -i /etc/yum.repos.d/
while [ $# -gt 0 ];do
soft=`/usr/bin/yum list $1 | grep Error`
if [ -n $soft ];then
/usr/bin/yum install -y $1
else
/usr/bin/yum update -y $1
fi
shift
done
# chattr +i
chattr +i /usr/bin
chattr +i /usr/sbin
chattr +i /usr/local/sbin
chattr +i /usr/local/bin
chattr +i /usr/libexec
chattr +i /sbin/
chattr +i /bin/
chattr +i /etc/yum.repos.d/
fi

34
shell/tools/open-ports.sh Normal file
View file

@ -0,0 +1,34 @@
#!/bin/bash
## 开放端口
# 未判断端口是否是数字
# /usr/bin/firewall-cmd --zone=work --add-port=xx/tcp --permanent
if [ $# -eq 0 ];then
echo -e "\033[32;1mUSGE:$0 [port]\033[0m"
exit 1
else
while [ $# -gt 0 ]; do
read -p "$1: TCP or UDP[default TCP]:" protocol
: ${protocol:=tcp}
case $protocol in
tcp|TCP)
protocol="tcp"
;;
udp|UDP)
protocol="udp"
;;
*)
echo -e "\033[31;1mCan not recognization the $protocol\033[0m"
;;
esac
port=`/usr/bin/firewall-cmd --zone=work --list-port | grep -o $1/$protocol`
if [[ -n $port ]];then
echo -e "\033[31;1m$1/$protocol opened already! \033[0m"
else
/usr/bin/firewall-cmd --zone=work --add-port=$1/$protocol --permanent
fi
shift
done
/usr/bin/firewall-cmd --reload
fi

View file

@ -0,0 +1,18 @@
#!/bin/bash
## 密码过期续期
# /usr/bin/chage -M 180 [username]
if [ $# -eq 0 ];then
echo -e "\033[31;1mUSGE:$0 [username]\033[0m"
exit 1
else
while [ $# -gt 0 ];do
user=`cat /etc/passwd | awk -F ':' '{print $1}'| grep $1`
if [ $user == $1 ];then
/usr/bin/chage -M 180 $1
else
echo -e "\033[31;1m$1 is not exists! \033[0m"
fi
shift
done
fi

View file

@ -0,0 +1,19 @@
#!/bin/bash
# 解锁用户
# /usr/sbin/pam_tally2 -r -u [username]
if [ $# -eq 0 ];then
echo -e "\033[31;1mUSGE:$0 [username]\033[0m"
exit 1
else
while [ $# -gt 0 ];do
user=`cat /etc/passwd | awk -F ':' '{print $1}'| grep $1`
if [ $user == $1 ];then
/usr/sbin/pam_tally2 -r -u $1
else
echo -e "\033[31;1m$1 is not exists! \033[0m"
fi
shift
done
fi

90
shell/tools/user-add.sh Normal file
View file

@ -0,0 +1,90 @@
#!/bin/bash
# 检查用户名是否已存在
check_user()
{
user=$1
u=`cat /etc/passwd | awk -F ':' '{print $1}'| grep $user`
if [ -n "$u" ];then
return 1
else
return 0
fi
}
# UID
get_uid()
{
g=`cat /etc/group |grep $1| awk -F ':' '{print $3}'`
if [ -z $g ];then
echo -e "\033[31;1m$1 not exists\033[0m"
exit 1
fi
max=$[g+500]
uids=`cat /etc/passwd | awk -F ':' '{print $3}'`
for uid in $uids;do
if [ $uid -gt $g -a $uid -lt $max ];then
g=$uid
fi
done
echo $[g+1]
}
## 添加用户
if [ $# -eq 0 ];then
echo -e "\033[31;1mUSGE:$0 [username]\033[0m"
else
# chattr -i
chattr -i /etc/passwd
chattr -i /etc/group
while [ $# -gt 0 ];do
echo -e "\033[32;1m++++++Group Lists++++++\033[0m"
echo -e "\033[32;1m\ta: devgroup\n\tb: ops\n\tc: appgroup\n\td: dbgroup\033[0m"
read -p "Choose Group for $1[default devgroup]:" group
: ${group:=devgroup}
case $group in
a|A|devgroup)
echo -e "\033[31;1mAdd user for check logs! \033[0m"
Gid=1000
;;
b|B|ops)
echo -e "\033[31;1mAdd user for system manager! \033[0m"
Gid=10
;;
c|C|appgroup)
echo -e "\033[31;1mAdd user for app! \033[0m"
Gid=0
;;
d|D|dbgroup)
echo -e "\033[31;1mAdd user for database! \033[0m"
Gid=0
;;
*)
echo -e "\033[31;1mNo Support! \033[0m"
Gid=0
;;
esac
gid=`cat /etc/group |grep $group| awk -F ':' '{print $3}'`
if [[ `check_user $1` -eq 1 ]];then
echo -e "\033[31;1m$1 exists already! \033[0m"
else
u=`get_uid $group`
if [ $Gid -gt 0 ];then
/usr/sbin/useradd -u $u -g $gid -G $Gid $1
else
/usr/sbin/useradd -u $u -g $gid $1
fi
password=`/usr/bin/openssl rand -base64 8`
echo -e "$1 password: \033[033;1m$password\033[0m"
echo $password | passwd --stdin $1
fi
shift
done
# chattr +i
chattr +i /etc/passwd
chattr +i /etc/group
fi

165
shell/创建目录.html Normal file
View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>创建目录</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">创建目录</h1>
<div class="content-html" id="leanote-content"><p>项目描述:/root目录下有两个目录/opt和/appl。现在需要每天创建一个日期目录并把前一天的目录归档存放。</p><div><div><strong>方法1复杂</strong></div><div>#/bin/sh</div><div><br></div><div>dir1=/root/opt</div><div>dir2=/root/appl</div><div><br></div><div>list=($dir1&nbsp;$dir2)</div><div><br></div><div>for((i=0;i&lt;${#list[@]};i++))</div><div>do</div><div>&nbsp;&nbsp;if&nbsp;[&nbsp;-d&nbsp;${list[i]}/$(date&nbsp;-d"1&nbsp;day&nbsp;ago"&nbsp;+"%Y-%m-%d")&nbsp;]</div><div>&nbsp;&nbsp;&nbsp;&nbsp;then</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mv&nbsp;${list[i]}/$(date&nbsp;-d"1&nbsp;day&nbsp;ago"&nbsp;+"%Y-%m-%d")&nbsp;${list[i]}/history</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mkdir&nbsp;${list[i]}/$(date&nbsp;+"%Y-%m-%d")</div><div>&nbsp;&nbsp;&nbsp;&nbsp;fi</div><div>done</div></div><div><br></div><div>方法2</div><div><br></div></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,53 @@
```
#!/bin/bash
# Edit by ZeroC
# Date 2017/11/08
## 需要调用/data/script/rsync/rsync_server_to_remote.sh
serverlist=("admin" "api" "bases" "capital" "contract" "fullscale" "orders" "others" "pc" "products" "repayment" "scan" "swoole" "sysaccount" "transaction" "trusteeship" "users")
dir=/data/htdocs/v
rollbackdate=`date +%Y-%m-%d`
now=`date +%Y-%m-%d-%H-%M`
sourcedir=/data/backup/$rollbackdate
Listdir()
{
dir=`echo $1|tr '[:upper:]' '[:lower:]'`
list=`ls $sourcedir| grep $server`
echo -e "\033[31;1m$dir:\033[0m"
for l in $list;do
echo -e "\t\033[32;1m$i\033[0m"
done
}
Action()
{
server=$1
backupdir=$2
# localhost : ( backup --> serverdir )
/usr/bin/rsync -a $sourcedir/$backupdir $dir/
# ( localhost : serverdir ) --> ( remote : server )
echo -e "\033[31;1mExecute the script (rsync_server_to_remote.sh) to RollBack the $server now ...\033[0m"
# 调用/data/script/rsync/rsync_server_to_remote.sh执行更新
(echo "$server" && echo "")| /bin/bash /data/script/rsync/rsync_server_to_remote.sh
}
RollBack()
{
echo -e "\033[31;1mThe Server You Can Choose\033[0m"
for server in ${serverlist[@]};do
echo -e "\t\033[32;1m$server\033[0m"
done
read -p "Your Choice:" server
echo -e "\033[31;1mThe Backup of The $server:\033[0m"
Listdir $server
read -p "Choose The Backup Which You Want To RollBack [default $server]:" choice
: ${choice:="$server"}
Action $server $choice
}
RollBack
```

View file

@ -0,0 +1,85 @@
```
#!/bin/bash
#上海银行存管系统备份
# Edit by ZeroC
# Date 2017/11/07
serverlist=("admin" "api" "bases" "capital" "contract" "fullscale" "orders" "others" "pc" "products" "repayment" "scan" "swoole" "sysaccount" "transaction" "trusteeship" "users")
dir=/data/htdocs/v
backupdate=`date +%Y-%m-%d`
now=`date +%Y%m%d%H%M`
weekago=`date -d 'a week ago' +%Y-%m-%d`
backupdir=/data/backup/$backupdate
packagedir=/data/backup/$weekago
logdir=/data/logs/backup/$backupdate
if [ ! -d $backupdate ];then
mkdir -p $backupdir
fi
if [ ! -d $logdir ];then
mkdir -p $logdir
fi
Backup()
{
server=`echo $1|tr '[:upper:]' '[:lower:]'`
cd $dir
if [ $server == 'all' ];then
for name in ${serverlist[*]};do
echo "Backup $name at $now ..." >> $logdir/$name
if [ ! -d "$backupdir/$name" ];then
/usr/bin/rsync -a $dir/$name/ $backupdir/$name >> $logdir/$name
else
/usr/bin/rsync -a $dir/$name/ $backupdir/$name-$now >> $logdir/$name
fi
echo -e "----------End----------\n" >> $logdir/$name
cat $logdir/$name
done
else
if [[ ${serverlist[@]} =~ $server ]];then
echo "Backup $server at $now ..." >> $logdir/$server
if [ ! -d "$backupdir/$server" ];then
/usr/bin/rsync -a $dir/$server/ $backupdir/$server >> $logdir/$server
else
/usr/bin/rsync -a $dir/$server/ $backupdir/$server-$now >> $logdir/$server
fi
echo -e "----------End----------\n" >>$logdir/$server
cat $logdir/$server
else
echo "Wrong ServerName!"
fi
fi
}
Package()
{
if [ -d $packagedir ];then
cd /data/backup
echo "-------------------" >> $logdir/package-$backupdate
tar zcvf $weekago-$now.tar.gz $weekago --remove-files >> $logdir/package-$backupdate
else
echo "-------------------" >> $logdir/package-$backupdate
echo "Not Backup at $backupdate or Package already !" >> $logdir/package-$backupdate
fi
}
if [ $# -eq 0 ];then
sc=$0
echo -e "\t\033[32;1m++++++++++server list++++++++++\033[0m"
for i in ${serverlist[*]};do
echo -e "\t\t\033[33;1m$i\033[0m"
done
echo -e "\t\t\033[33;1mall [以上所有]\033[0m"
read -p "The server[default all]:" server
:
Backup $server
Package
elif [ $# -eq 1 ];then
Backup $1
Package
else
echo -e "Stupid behavior !!"
fi
```

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>字符串大小写替换</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">字符串大小写替换</h1>
<div class="content-html" id="leanote-content"><p>echo "ABC" | tr [[:upper:]] &nbsp;[[:lower:]] &nbsp; &nbsp; &nbsp;大写替换成小写</p><p>echo "abc" | tr [[:lower:]] &nbsp;[[:upper:]] &nbsp; &nbsp;&nbsp;小写替换成大写</p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

165
shell/字符串长度.html Normal file
View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>字符串长度</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">字符串长度</h1>
<div class="content-html" id="leanote-content"><p>name=Alex<br>echo ${#name}</p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>字符串首字母大写</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">字符串首字母大写</h1>
<div class="content-html" id="leanote-content"><p>echo "abcd"|sed 's/\b[a-z]/\U&amp;/'<br></p><p>说明:\b \U是正则表达式的元符号。\b用来定界\U大小转换。&amp;是sed前面被替换的字符串</p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,217 @@
```
#!/bin/bash
## Edit by ZeroC
# 20170908
. ./server
logpath=/root/update
DIRDATE=`date +%Y-%m-%d`
UPDATE=`date +%Y-%m-%d:%H:%M:%S`
## 帮助
Help()
{
if [ $# -eq 1 ];then
baseName=$1
echo -e "\033[31;1mUsge:\t'bash $baseName help' 打印帮助信息\n\t'bash $baseName' 更新应用服务\033[0m\n"
elif [ $# -eq 2 -a $2 == "list" ];then
echo -e "\033[32;1m++++++++ServerName List++++++++\033[0m"
echo -e "\033[31;1m\ta api\n\tb admin\n\tc pc\n\td swoole\n\te users\n\tf transaction\n\tg products\n\th orders\n\ti fullscale\n\tj repayment\n\tk capital\n\tl sysaccount\n\tm bases\n\tn trusteeship\n\to contract\n\tp others\n\tq scan\033[0m\n"
fi
}
## ip列表
IPlist()
{
server=$1
List=$2
echo "$server:"
for ip_l in ${List[@]};do
echo -e "\033[33;1m\t$ip_l\033[0m"
done
}
## rsync推送更新
Rsync()
{
server_c=$1
ip=$2
if [ ! -d $logpath/$DIRDATE/$server_c ];then
mkdir -p $logpath/$DIRDATE/$server_c
fi
echo "+++++++++++++++++++++++++++++++++++++++++" >> $logpath/$DIRDATE/$server_c/$ip
echo $UPDATE >> $logpath/$server_c/$ip
/usr/bin/rsync -avz --exclude-from=/data/script/rsync/exclude --password-file=/data/script/rsync/pass /data/htdocs/v/$server_c/ rsync@$ip::server >> $logpath/$DIRDATE/$server_c/$ip
echo "+++++++++++++++++++++++++++++++++++++++++" >> $logpath/$DIRDATE/$server_c/$ip
echo >> $logpath/$DIRDATE/$server_c/$ip
}
## 重启微服务
Restart()
{
#serverU=`echo $1|sed 's/\b[a-z]/\U&/'`
ip=$2
ssh root@$ip "/bin/bash /data/script/run.sh restart"
}
## 更新模块
UpdateM()
{
serverM=$1
server="\<$1\>"
iparray=$2
## 同一服务的所有ip都更新
if [ $# -eq 2 ];then
## 微服务
if [[ "${micro[@]}" =~ $serverM ]];then
for ip in ${iparray[@]};do
Rsync $serverM $ip
Restart $serverM $ip
sleep 5
done
## swoole
elif [ $serverM == "swoole" ];then
for ip in ${iparray[@]};do
Rsync swoole $ip
Restart swoole $ip
sleep 5
done
## api/admin/pc
elif [ $serverM == "api" -o "admin" -o "pc" ];then
for ip in ${iparray[@]};do
Rsync $serverM $ip
done
fi
# 一个服务只更新其中一个ip
elif [ $# -eq 3 ]; then
## 微服务
if [[ "${micro[@]}" =~ $serverM ]];then
if [[ "${iparray[@]}" =~ $3 ]];then
Rsync $serverM $3
Restart $serverM $3
else
echo -e "\033[31;1mWrong IP!\033[0m"
exit 1
fi
## swoole
elif [ $serverM == "swoole" ];then
if [[ "${swoole[@]}" =~ $3 ]];then
Rsync swoole $3
Restart swoole $3
else
echo -e "\033[31;1mWrong IP!\033[0m"
exit 1
fi
# api/admin/pc
elif [ $serverM == "api" -o "admin" -o "pc" ];then
if [[ "${iparray[@]}" =~ $2 ]];then
Rsync $serverM $3
else
echo -e "\033[31;1mWrong IP!\033[0m"
exit 1
fi
else
echo -e "\033[31;1mWrong Server!\033[0m"
fi
fi
}
## 更新系统
UpdateS()
{
serverS=$1
serverL=$2
read -p "The IP[default all ip]:" addr
if [ -z $addr ];then
echo -e "\033[33;1mUpdate all $serverS\033[0m"
UpdateM $serverS "${serverL[*]}"
else
echo -e "\033[33;1mUpdate one of $serverS: $addr\033[0m"
UpdateM $serverS "${serverL[*]}" $addr
fi
}
## Main
echo -e "\033[33;1mChoose the server you want to update\033[0m"
Help $0 list
read -p "Your choose:" sername
case $sername in
help)
Help $0
;;
a|A|api)
IPlist api "${api[*]}"
UpdateS api "${api[*]}"
;;
b|B|admin)
IPlist admin "${admin[*]}"
UpdateS admin "${admin[*]}"
;;
c|C|pc)
IPlist pc "${pc[*]}"
UpdateS pc "${pc[*]}"
;;
d|D|swoole)
IPlist swoole "${swoole[*]}"
UpdateS swoole "${swoole[*]}"
;;
e|E|users)
IPlist users "${users[*]}"
UpdateS users "${users[*]}"
;;
f|F|transaction)
IPlist transaction "${transaction[*]}"
UpdateS transaction "${transaction[*]}"
;;
g|G|products)
IPlist products "${products[*]}"
UpdateS products "${products[*]}"
;;
h|H|orders)
IPlist orders "${orders[*]}"
UpdateS orders "${orders[*]}"
;;
i|I|fullscale)
IPlist fullscale "${fullscale[*]}"
UpdateS fullscale "${fullscale[*]}"
;;
j|J|repayment)
IPlist repayment "${repayment[*]}"
UpdateS repayment "${repayment[*]}"
;;
k|K|capital)
IPlist capital "${capital[*]}"
UpdateS capital "${capital[*]}"
;;
l|L|sysaccount)
IPlist sysaccount "${sysaccount[*]}"
UpdateS sysaccount "${sysaccount[*]}"
;;
m|M|bases)
IPlist bases "${bases[*]}"
UpdateS bases "${bases[*]}"
;;
n|N|trusteeship)
IPlist trusteeship "${trusteeship[*]}"
UpdateS trusteeship "${trusteeship[*]}"
;;
o|O|contract)
IPlist contract "${contract[*]}"
UpdateS contract "${contract[*]}"
;;
p|P|others)
IPlist others "${others[*]}"
UpdateS others "${others[*]}"
;;
q|Q|scan)
IPlist scan "${scan[*]}"
UpdateS scan "${scan[*]}"
;;
*)
echo -e "\033[31;1mWrong option!\033[0m"
;;
esac
```

View file

@ -0,0 +1,26 @@
```
# 微服务列表
micro=("users" "transaction" "products" "orders" "fullscale" "repayment" "capital" "sysaccount" "bases" "trusteeship" "contract" "others" "scan")
# api ip列表
api=("192.168.6.63" "192.168.6.64")
# admin ip列表
admin=("192.168.6.69" "192.168.6.70")
# pc ip列表
pc=("192.168.6.60" "192.168.6.61" "192.168.6.62")
#各微服务ip列表
users=("192.168.6.73" "192.168.6.74" "192.168.6.106")
transaction=("192.168.6.75" "192.168.6.76" "192.168.6.109")
products=("192.168.6.77" "192.168.6.78")
orders=("192.168.6.81" "192.168.6.82" "192.168.107")
fullscale=("192.168.6.83" "192.168.6.84")
repayment=("192.168.6.85" "192.168.6.86")
capital=("192.168.6.87" "192.168.6.88" "192.168.6.108")
sysaccount=("192.168.6.89" "192.168.6.90")
bases=("192.168.6.91" "192.168.6.92")
trusteeship=("192.168.6.93" "192.168.6.94")
contract=("192.168.6.95" "192.168.6.96")
others=("192.168.6.97" "192.168.6.98")
scan=("192.168.6.99" "192.168.6.100")
# swoole ip列表
swoole=("${users[*]}" "${transaction[*]}" "${products[*]}" "${orders[*]}" "${fullscale[*]}" "${repayment[*]}" "${capital[*]}" "${sysaccount[*]}" "${bases[*]}" "${trusteeship[*]}" "${contract[*]}" "${others[*]}" "${scan[*]}")
```

View file

@ -0,0 +1,386 @@
```
#!/bin/bash
## Edit by wangsuipeng
## Date 2017/03/02
## 需要与以下脚本配合使用
## ldap安装脚本sh_ldap_client.sh
## nagios安装脚本nagios_client.sh
## zabbix安装脚本zabbix_agentd.sh
## rsync安装脚本rsync_server.sh
## 检查结果列表
OUTPUT="`pwd`/output"
LIST="$OUTPUT/list"
SCRIPT="$OUTPUT/done.sh"
DATE=`date +%Y-%m-%d`
HOSTNAME=`hostname`
if [ ! -d $OUTPUT ];then
mkdir -p $OUTPUT
else
if [ -f $LIST ];then
echo > $LIST
fi
fi
## 生成缺省配置脚本
DONE()
{
cat > $SCRIPT << EOF
#!/bin/bash
## Edit by checklist
## Date $DATE
INI="./list"
EOF
}
## 服务检查,主要是检查服务是否存在
## 有两个参数,服务名与端口号
SERVER()
{
server=`lsof -i:$2|awk '{print $9}'| grep -v NAME|grep $1|head -n1`
if [ -n "$server" ];then
echo "$1=yes" >> $LIST
return 0
else
echo "$1=" >> $LIST
echo -e "\033[31;49;1mThe snot startup or install !\033[31;49;0m"
return 1
fi
}
## 安装配置ldap客户端
# -*- 脚本配置 -*-
LDCONF()
{
cat >> $SCRIPT << EOF
service autofs restart >/dev/null 2>&1 && service nslcd restart >/dev/null 2>&1
if [ \$? -ne 0 ];then
read -p "Ldap is not installed , Do you want to install it? yes or no ? [Default:yes]" LDC
: \${LDC:='y'}
case "\$LDC" in
y|Y|YES|yes)
bash ../sh_ldap_client.sh
sed -i 's/ldap=/ldap=yes/' \$INI
;;
n|N|NO|no)
echo -e '\033[31;49;1mldap will not be installed!\033[31;49;0m'
;;
*)
echo -e 'You choose a bad option!'
continue
;;
esac
fi
EOF
}
## 检查ldap服务状态
LDAP()
{
echo "## The List of LDAP" >> $LIST
echo "[ldap]" >> $LIST
# -*- 脚本配置 -*-
echo "## Config ldap" >> $SCRIPT
SERVER ldap 389
if [ $? -ne 0 ];then
# -*- 脚本配置 -*-
LDCONF
else
# -*- 脚本配置 -*-
echo "# -*- PASS -*-" >> $SCRIPT
fi
echo >> $LIST
}
## 安装配置Zabbix-agent
# -*- 脚本配置 -*-
ZBCONF()
{
cat >> $SCRIPT << EOF
ZBAGENT="/etc/init.d/zabbix_agentd"
if [ ! -f \$ZBAGENT ];then
read -p "ZABBIX is not install.Do you want to install it?yes or no ? [Default:yes]" ZBC
: \${ZBC:='y'}
case "\$ZBC" in
y|Y|YES|yes)
bash ../zabbix_agentd.sh
sed -i 's/zabbix=/zabbix=yes/' \$INI
;;
n|N|NO|no)
echo -e '\033[31;49;1mzabbix will not be installed!\033[31;49;0m'
;;
*)
echo -e 'You choose a bad option!'
continue
;;
esac
else
service zabbix_agentd restart >/dev/null 2>&1
fi
EOF
}
## 检查zabbix服务状态默认编译安装在/usr/local/zabbix中
ZABBIX()
{
echo "## The List of ZABBIX" >> $LIST
echo "[zabbix]" >> $LIST
# -*- 脚本配置 -*-
echo "## Config ldap" >> $SCRIPT
SERVER zabbix 10050
if [ $? -ne 0 ];then
# -*- 脚本配置 -*-
ZBCONF
else
# -*- 脚本配置 -*-
echo "# -*- PASS -*-" >> $SCRIPT
fi
echo >> $LIST
}
## 安装配置nagios客户端
# -*- 脚本配置 -*-
NGCONF()
{
cat >> $SCRIPT << EOF
XINNRPE="/etc/xinetd.d/nrpe"
if [ ! -f \$XINNRPE ];then
read -p "Nagios is not install.Do you want to install it?yes or no ? [Default:yes]!" NGC
: \${NGC:='y'}
case "\$NGC" in
y|Y|YES|yes)
bash ../nagios_client.sh
sed -i 's/nagios=/nagios=yes/' \$INI
echo '\033[32;49;1mYou need config the server at 172.16.3.2\033[32;49;0m'
;;
n|N|NO|no)
echo -e '\033[31;49;1mNagios will not be installed!\033[31;49;0m'
;;
*)
echo -e 'You choose a bad option!'
continue
esac
else
if egrep -q 'disable = no' \$XINNRPE;then
service xinetd restart > /dev/null 2>&1
else
sed -i "/disable/ s/yes/no/" \$XINNRPE
service xinetd restart > /dev/null 2>&1
fi
fi
EOF
}
## 检查nagios服务状态默认安装在/usr/local/nagios中
NAGIOS()
{
echo "## The List of NAGIOS" >> $LIST
echo "[nagios]" >> $LIST
# -*- 脚本配置 -*-
echo "## Config nagios" >> $SCRIPT
SERVER nrpe 5666
if [ $? -ne 0 ];then
NGCONF
else
# -*- 脚本配置 -*-
echo "# -*- PASS -*-" >> $SCRIPT
fi
echo >> $LIST
}
## 安装rsync服务器端
# -*- 脚本配置 -*-
RSCONF()
{
cat >> $SCRIPT << EOF
CONF="/etc/rsyncd.conf"
if [ ! -f \$CONF ];then
read -p "Rsync is not install.Do you want to install it?yes or no ? [Default:yes]!" RSC
: \${RSC:='y'}
case "\$RSC" in
y|Y|YES|yes)
bash ../rsync_server.sh
sed -i 's/rsync=/rsync=yes/' \$INI
echo '\033[32;49;1mYou need config the client\033[32;49;0m'
;;
n|N|NO|no)
echo -e '\033[31;49;1mRsync will not be installed!\033[31;49;0m'
;;
*)
echo -e 'You choose a bad option!'
continue
esac
else
service xinetd restart >>/dev/null 2>&1
fi
EOF
}
## 检查rsync服务状态默认rpm包安装
RSYNC()
{
echo "## The List of RSYNC" >> $LIST
echo "[rsync]" >> $LIST
# -*- 脚本配置 -*-
echo "## Config rsync" >> $SCRIPT
SERVER rsync 873
if [ $? -ne 0 ];then
RSCONF
else
# -*- 脚本配置 -*-
echo "# -*- PASS -*-" >> $SCRIPT
fi
echo >> $LIST
}
## 时间同步
# -*- 脚本配置 -*-
NTPCONF()
{
cat >> $SCRIPT << EOF
echo "00 01 * * * /usr/sbin/ntpdate -u 172.16.3.2 > /dev/null 2>&1" >> /var/spool/cron/root
sed -i 's/ntp=/ntp=yes/' \$LIST
EOF
}
## 检查时间同步
NTPDATE()
{
echo "## The List of ntp" >> $LIST
echo "[ntp]" >> $LIST
# -*- 脚本配置 -*-
echo "## Config ntp" >> $SCRIPT
crontab -l | grep ntpdate|egrep '[^#]' > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "ntp=" >> $LIST
NTPCONF
else
echo "ntp=yes" >> $LIST
# -*- 脚本配置 -*-
echo "# -*- PASS -*-" >> $SCRIPT
fi
echo >> $LIST
}
## 检查hosts
HOSTS()
{
echo "## The List of Hosts" >> $LIST
echo "[hosts]" >> $LIST
echo "## /etc/hosts" >> $LIST
cat /etc/hosts >> $LIST
echo >> $LIST
echo "## /etc/hosts.allow" >> $LIST
cat /etc/hosts.allow >> $LIST
echo >> $LIST
}
## 防火墙配置导出
IPTABLES()
{
echo "## The List of iptables" >> $LIST
echo "[iptables]" >> $LIST
/etc/init.d/iptables status | grep "not running" >/dev/null 2>&1
if [ $? -ne 0 ];then
cat /etc/sysconfig/iptables >> $LIST
else
echo "## iptables is not running!" >> $LIST
fi
echo >> $LIST
}
## 系统优化主要配置导出
OPTIMA()
{
echo "## The List of optimalize" >> $LIST
echo "[optimalize]" >> $LIST
echo "## limits.conf" >> $LIST
cat /etc/security/limits.conf >> $LIST
echo >> $LIST
echo "## sysctl.conf" >> $LIST
cat /etc/sysctl.conf >> $LIST
echo >> $LIST
echo "## umask" >> $LIST
grep '^umask' /etc/sysconfig/init >> $LIST
echo >> $LIST
}
## 加固检查
FIRMED()
{
echo "## The firmed" >> $LIST
echo "[firmed]" >> $LIST
if egrep -q "^PermitRootLogin no|^LoginGraceTime 30|^ClientAliveInterval 3600|^ClientAliveCountMax 0|^UseDNS no" /etc/ssh/sshd_config;then
echo "firmed=yes" >> $LIST
else
echo "firmed=" >> $LIST
fi
}
## 主程序
if [ $# -eq 0 ];then
echo "check the all programe"
DONE
LDAP
ZABBIX
NAGIOS
RSYNC
NTPDATE
HOSTS
IPTABLES
OPTIMA
FIRMED
echo -e "\n\n## *** END ***" >> $LIST
else
case $1 in
-h|--help|?)
echo -e "usage:bash checklist.sh [-h][Function]\n\t-h:帮助文档\n\tFunction:检查项一次只能检查一个包括LDAP,ZABBIX,NAGIOS,RSYNC,NTPDATE,HOSTS,IPTABLES,OPTIMA,FIRMED\n\t无参数:默认执行所有的检查并生成配置脚本done.sh\n"
;;
LDAP|ldap|Ldap)
LDAP
;;
ZABBIX|zabbix|Zabbix)
ZABBIX
;;
NAGIOS|nagios|Nagios)
NAGIOS
;;
RSYNC|rsync|Rsync)
RSYNC
;;
NTPDATE|ntpdate|Ntpdate)
NTPDATE
;;
HOSTS|hosts|Hosts)
HOSTS
;;
IPTABLES|iptables|Iptables)
IPTABLES
;;
OPTIMA|optima|Optima|optimalize)
OPTIMA
;;
FIRMED|firmed|Firmed)
FIRME
;;
*)
echo "please choose a invalid option!"
esac
fi
echo -e "检查列表为'$LIST'\n查漏脚本'$SCRIPT'"
chmod +x $SCRIPT
```

View file

@ -0,0 +1,18 @@
10个参数输出最大值
```shell
#!/bin/bash
if [ $# -lt 10 ];then
exit 1
else
temp=0
while [ -n "$1" ];do
if [[ $temp -gt $1 ]];then
temp=$temp
else
temp=$1
fi
shift
done
fi
echo $temp
```

View file

@ -0,0 +1,156 @@
```
#!/bin/bash
##Edit by wangsuipeng
##2016/08/30
##用法bash Adduser.sh 用户uid 用户名 项目名
##添加应用用户,减少无意义的重复劳动
#GRP=/etc/group
#PSW=/etc/passwd
SD=/etc/sudoers
PRO=/opt/appl
# 应用用户UID
PRJUID=$1
# 应用用户名
USERNAME=$2
# 项目名
PRJNAME=$3
echo "应用用户名最好小于等于8个字符且不带下划线"
HM=/home/$USERNAME/.bash_profile
## Add the USERNAME to opmm
SUDOERS()
{
if egrep -q '^opmm\b' $SD;then
sed -i "/^opmm/ s/$/,\/bin\/su - $USERNAME/" $SD
else
sed -i "/^root/a opmm\tALL=(ALL)\tNOPASSWD: " $SD
sed -i "/^opmm/ s/$/\/bin\/su - $USERNAME/" $SD
fi
}
## Config the TOMCAT
TCONF()
{
sed -i "/^PATH/i TOMCAT_HOME=$PRO\/$PRJNAME\/tomcat" $HM
sed -i "/^PATH/ s/$/:\$TOMCAT_HOME/" $HM
echo 'cd $TOMCAT_HOME'>> $HM
echo -e '\033[32;1mDownload the tomcat8.0 now ! Please wait a moment ...\033[0m'
wget http://soft.iboxpay.com/soft/java/apache-tomcat-8.0.32.tar.gz >/dev/null 2>&1
tar zxvf apache-tomcat-8.0.32.tar.gz >/dev/null 2>&1
rm -rf apache-tomcat-8.0.32.tar.gz
ln -s apache-tomcat-8.0.32 tomcat
sed -i 's#Connector port="8080" protocol="HTTP/1.1"#Connector port="'$PORT'" protocol="HTTP/1.1"#' $PRO/$PRJNAME/tomcat/conf/server.xml
cd tomcat
}
## Config and Check the JDK
JCONF()
{
if egrep -q '^TOMCAT_HOME' $HM;then
sed -i "/^TOMCAT_HOME/a JAVA_HOME=$PRO\/$PRJNAME\/tomcat\/jdk" $HM
sed -i "/^PATH/ s/$/:\$JAVA_HOME\/bin/" $HM
else
sed -i "/^PATH/a JAVA_HOME=$PRO\/$PRJNAME\jdk\nPATH=\$PATH:\$JAVA_HOME\/bin" $HM
fi
cd $PRO/ && chown -R $USERNAME:fspfappl $PRJNAME
su - $USERNAME -c "java -version" > /dev/null 2>&1
if [ "$?" == 0 ];then
echo -e "\033[32;1mCongratulations !! The JDK is ok now !\033[0m"
else
echo -e "\033[31;1;5moh no ! it has something wrong !! You need to check !\033[0m"
fi
}
## The main
if [ $# -ne 3 ];then
echo 'Please make sure that the disk has already add!!'
echo -e '\033[31;1mUSEAGE:bash Adduser.sh PRJUID USERNAME PRJNAME\033[0m'
echo -e 'PRJUID:The UID of The User UID!\nUSERNAME:The Username of Project\nPRJNAME:The Name of Project'
exit 1
else
# Add the USERNAME
useradd -u $PRJUID -g 1500 $USERNAME
#sed -i "/^PATH/a TOMCAT_HOME=\/opt\/appl\/$PRJNAME\/tomcat\nJAVA_HOME=\/opt\/appl\/$PRJNAME\/tomcat\/jdk\nPATH=\$PATH:\$JAVA_HOME/bin:\$TOMCAT_HOME" $HM
SUDOERS
# Create the base of project
mkdir -p $PRO/$PRJNAME && chmod 755 $PRO && cd $PRO/$PRJNAME
# The project port
echo -e '\033[32;1mThe project may need a port !\nIf you do not input a port , it will use 8080\033[0m'
read -p "The port:[8080]" PORT
${PORT:-8080}&&echo -e 'The Project $PRJNAME use the \033[32;5;1mPort $PORT\033[0m !'
# Open the port
iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport $PORT -j ACCEPT
/etc/init.d/iptables save
service iptables restart
# Download the tomcat or not
# Default tomcat 8 X64
echo -e "\033[32;1mYou can get jboss4/8 , tomcat 7/8 , jdk 1.7/1.8 i586 and jre 1.7 from http://soft.iboxpay.com/soft/java !\033[0m"
echo -e "\033[33;1mWARNING!!!If you need jdk1.6 , please input no!! You can get the tomcat 7 like this\033[0m"
echo -e "\033[32;5;1m\n\twget http://soft.iboxpay.com/soft/java/apache-tomcat-7.0.70.tar.gz \033[0m"
echo -e "\033[32;1mDo you need tomcat 8???\033[0m"
read -p "yes or no[Default:yes]" TV
: ${TV:='y'}
case "$TV" in
Y|yes|y|YES)
TCONF
;;
N|no|n|NO)
echo "You can do something later!"
;;
*)
echo -e "\033[31;1;5mAre you kidding me ???\033[0m"
exit 1
;;
esac
# Download the jdk or not
# Default jdk1.8
echo -e "\t\033[33;1m################\n\t+ 1.jdk1.6 x64 +\n\t+ 2.jdk1.7 x64 +\n\t+ 3.jdk1.8 x64 +\n\t+ 4.other +\n\t################\033[0m"
read -p "Please input the version of the jdk:1 or 2 or 3 or 4:" JV
: ${JV:='jdk1.8'}
case "$JV" in
1|jdk1.6|6|1.6)
wget http://soft.iboxpay.com/soft/java/jdk1.6.0_45.tgz >/dev/null 2>&1
echo -e '\033[32;1mDownload the jdk1.6 now ! Please wait a moment ...\033[0m'
tar zxvf jdk1.6.0_45.tgz >/dev/null 2>&1
rm -rf jdk1.6.0_45.tgz
ln -s jdk1.6.0_45 jdk
JCONF
;;
2|jdk1.7|7|1.7)
wget http://soft.iboxpay.com/soft/java/jdk-7u80-linux-x64.tar.gz >/dev/null 2>&1
echo -e '\033[32;1mDownload the jdk1.7 now ! Please wait a moment ...\033[0m'
tar zxvf jdk-7u80-linux-x64.tar.gz >/dev/null 2>&1
rm -rf jdk-7u80-linux-x64.tar.gz
ln -s jdk1.7.0_80 jdk
JCONF
;;
3|jdk1.8|8|1.8)
wget http://soft.iboxpay.com/soft/java/jdk-8u45-linux-x64.tar.gz >/dev/null 2>&1
echo -e '\033[32;1mDownload the jdk1.8 now ! Please wait a moment ...\033[0m'
tar zxvf jdk-8u45-linux-x64.tar.gz >/dev/null 2>&1
rm -rf jdk-8u45-linux-x64.tar.gz
ln -s jdk1.8.0_45 jdk
JCONF
;;
4|other|o|O)
echo "You can choose aother software later!"
;;
*)
echo -e "\033[311;5mAre you kidding me ???\033[0m"
exit 1
;;
esac
fi
```

181
shell/读取文件.html Normal file
View file

@ -0,0 +1,181 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>读取文件</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">读取文件</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1506652562212_0" class="brush:sh ace-tomorrow">#!/bin/bash
for i in `awk '{print $1}' host`
do
j=`awk -v I="$i" '{if(I==$1)print $2}' host`
echo "ip=$i"
echo "pas=$j"
done
</pre><p>host文件</p><pre id="leanote_ace_1506652623491_0" class="brush:sh ace-tomorrow">192.168.6.1 wwwwwwwwwww1
192.168.6.2 wwwwwwwwwww2
192.168.6.3 wwwwwwwwwww3
192.168.6.4 wwwwwwwwwww4
192.168.6.5 wwwwwwwwwww5
192.168.6.6 wwwwwwwwwww6
192.168.6.7 wwwwwwwwwww7
192.168.6.8 wwwwwwwwwww8
192.168.6.9 wwwwwwwwwww9</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,176 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>changid.sh</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">changid.sh</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1489541124116_0" class="brush:sh ace-tomorrow">#!/bin/bash
## Edit by wangsuipeng
## 20170223
## 目的逐行读取ip地址并通过ex脚本执行远程操作
## USAGE: bash changeid
for i in `cat ip`
do
host=$i
./ex $host &amp;
done</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,184 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>ex</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">ex</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1489541163584_0" class="brush:sh ace-tomorrow">#!/usr/bin/env expect
## Edit by wangsuipeng
## 20170223
## 远程执行脚本
## 请执行bash changeid
set PASSWD XXXXXXX
set IP [lindex $argv 0]
set timeout 5
spawn ssh opmm@$IP
expect {
"*(yes/no)?" {send "yes\r";exp_continue}
"*password:" {send "$PASSWD\r";exp_continue}
"*Password:" {send "$PASSWD\r"}
}
send "sudo su - root -c 'bash /home/ldaphome/wangsuipeng/changeid.sh'\r" ##执行远程脚本/home/ldaphome/wangsuipeng/changeid.sh,此处省略脚本上传到远程主机的操作
##send "sudo su - root -c '&gt;/etc/salt/minion_id &amp;&amp; /etc/init.d/salt-minion restart'" ##与上一步目的一样
expect eof</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,178 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>ip</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">ip</h1>
<div class="content-html" id="leanote-content"><pre class="code highlight">172.19.0.1
172.19.0.2
172.19.0.3
172.19.0.4
172.19.0.5
172.19.0.6
172.19.0.7
172.19.0.8
172.19.0.9
172.19.0.10
172.19.0.11
172.19.0.12
172.19.0.13
172.19.0.14</pre></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,229 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>mqaction-v1.sh</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">mqaction-v1.sh</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1509518437791_0" class="brush:sh ace-tomorrow">#!/bin/bash
#20171025
#Service_name=(Users Orders Capital Sysaccount Products Trusteeship)
#Users_port=9611
#Orders_port=9615
#Capital_port=9617
#Sysaccount_port=9618
#Products_port=9619
#Trusteeship_port=9620
declare -A Service
Service=([Users]=9611 [Orders]=9615 [Capital]=9617 [Sysaccount]=9618 [Products]=9619 [Trusteeship]=9620)
# source function library
. /etc/rc.d/init.d/functions
action()
{
does=$1
server=$2
SPORT=${Service[$server]}
is_exists=`netstat -anltp| grep $SPORT`
if [ x != x"$is_exists" ];then
if [ $does == 'start' ];then
echo "The $server already start!"
elif [ $does == 'stop' ];then
lsof -i:$SPORT| grep php| grep -v grep | awk '{print $2}'|xargs kill -9
elif [ $does == 'restart' ];then
action stop $server
action start $server
elif [ $does == 'status' ];then
echo "The $server running..."
fi
else
if [ $does == 'start' ];then
cd /data/htdocs/v/ServiceModule/$server
nohup /usr/local/php7/bin/php mqconsumer.php &gt;/dev/null 2&gt;&amp;1 &amp;
#cd /data/htdocs/v/ServiceModule/$server &amp;&amp; nohup /usr/local/php7/bin/php mqconsumer.php &gt;/dev/null &amp;
elif [ $does == 'stop' ];then
echo "The $server already stop!"
elif [ $does == 'restart' ];then
action stop $server
action start $server
elif [ $does == 'status' ];then
echo "The $server stopping..."
fi
fi
}
cycle()
{
doing=$1
sername=$2
if [ $sername == 'all' ];then
for key in $(echo ${!Service[*]});do
action $doing $key
done
else
action $doing $sername
fi
}
cycle $1 $2
</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>

View file

@ -0,0 +1,235 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="tool" content="leanote-desktop-app">
<title>mqaction-v2.sh</title>
<style>
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
body {
margin: 0;
}
/*公用文字样式*/
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
.note-container{
width:850px;
margin:auto;
padding: 10px 20px;
box-shadow: 1px 1px 10px #eee;
}
#title {
margin: 0;
}
table {
margin-bottom: 16px;
border-collapse: collapse;
}
table th, table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
table th {
font-weight: bold;
}
table tr {
background-color: none;
border-top: 1px solid #ccc;
}
table tr:nth-child(2n) {
background-color: rgb(247, 247, 249);
}
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
border: 1px solid #ddd;
border-collapse: collapse;
padding: 6px 13px;
}
blockquote {
border-left-width:10px;
background-color:rgba(128,128,128,0.05);
border-top-right-radius:5px;
border-bottom-right-radius:5px;
padding:15px 20px;
border-left:5px solid rgba(128,128,128,0.075);
}
blockquote p {
margin-bottom:1.1em;
font-size:1em;
line-height:1.45
}
blockquote ul:last-child,blockquote ol:last-child {
margin-bottom:0
}
pre {
padding: 18px;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
display: block;
}
code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
white-space: nowrap;
background-color: #f9f2f4;
border-radius: 4px;
}
.footnote {
vertical-align: top;
position: relative;
top: -0.5em;
font-size: .8em;
}
hr {
margin:2em 0
}
img {
max-width:100%
}
pre {
word-break:break-word
}
p,pre,pre.prettyprint,blockquote {
margin:0 0 1.1em
}
hr {
margin:2em 0
}
img {
max-width:100%
}
.sequence-diagram,.flow-chart {
text-align:center;
margin-bottom:1.1em
}
.sequence-diagram text,.flow-chart text {
font-size:15px !important;
font-family:"Source Sans Pro",sans-serif !important
}
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
fill:#f6f6f6
}
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
stroke:#3f3f3f
}
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
stroke:none
}
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
fill:#3f3f3f
}
ul,ol {
margin-bottom:1.1em
}
ul ul,ol ul,ul ol,ol ol {
margin-bottom:1.1em
}
kbd {
padding:.1em .6em;
border:1px solid rgba(63,63,63,0.25);
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
box-shadow:0 1px 0 rgba(63,63,63,0.25);
font-size:.7em;
font-family:sans-serif;
background-color:#fff;
color:#333;
border-radius:3px;
display:inline-block;
margin:0 .1em;
white-space:nowrap
}
.toc ul {
list-style-type:none;
margin-bottom:15px
}
</style>
<!-- 该css供自定义样式 -->
<link href="../leanote-html.css" rel="stylesheet">
</head>
<body>
<div class="note-container">
<h1 class="title" id="leanote-title">mqaction-v2.sh</h1>
<div class="content-html" id="leanote-content"><pre id="leanote_ace_1523266647677_0" class="brush:sh ace-tomorrow">#!/bin/bash
# Edit by ZeroC
# 20180407
. /etc/init.d/functions
name=$1
action=$2
basedir=/data/htdocs/v/$name
startmq(){
cd $basedir
statusmq
if [ $? -eq 0 ];then
#echo -e "\033[33;1m$name MQ监听启动\033[0m"
nohup /usr/local/php70/bin/php mqconsumer.php &gt; /dev/null 2&gt;&amp;1 &amp;
echo -e "\033[33;1mInfo\033[0m:\033[32;1m$name MQ监听启动完成\033[0m"
elif [ $? -eq 1 ];then
echo -e "\033[33;1mWarning\033[0m:\033[33;1m$name MQ监听已启动\033[0m"
fi
}
stopmq(){
cd $basedir
statusmq
if [ $? -eq 1 ];then
#echo -e "\033[33;1m$name MQ监听停止\033[0m"
/usr/local/php70/bin/php mqconsumer.php stop &gt; /dev/null
ps aux | grep php-ps| grep -v grep | awk '{print $2}'| xargs kill -9 &gt; /dev/null 2&gt;&amp;1
echo -e "\033[33;1mInfo\033[0m:\033[32;1m$name MQ监听停止完成\033[0m"
elif [ $? -eq 0 ];then
echo -e "\033[33;1mWarning\033[0m:\033[33;1m$name MQ监听已停止\033[0m"
fi
}
restartmq(){
stopmq
startmq
}
statusmq(){
cd $basedir
result1=`/usr/local/php70/bin/php mqconsumer.php status`
result2=`netstat -anltp | grep php-ps| grep -v grep`
if [ $result1 -eq 0 ] &amp;&amp; [ x == x"$result2" ];then
echo -e "\033[33;1mStatus\033[0m:\033[32;1m$name MQ监听已停止\033[0m"
return 0
elif [ $result1 -eq 1 ] &amp;&amp; [ x != x"$result2" ];then
echo -e "\033[33;1mStatus\033[0m:\033[32;1m$name MQ监听在运行\033[0m"
return 1
fi
}
case $action in
start)
startmq
;;
stop)
stopmq
;;
status)
statusmq
;;
restart)
restartmq
;;
*)
echo -e "\033[33;1mi\t参数异常!\nUsage: bash $0 $name (start|stop|restart|status)\033[0m"
;;
esac
</pre><p><br data-mce-bogus="1"></p></div>
</div>
<!-- 该js供其它处理 -->
<script src="../leanote-html.js"></script>
</body>
</html>