2537
平时编写的一些shell脚步例举笔记
乐果 发表于 2018 年 09 月 06 日 标签:shell
批量杀死进程
ps -ef|grep test.sh
xiao 3296 28517 0 10:09 pts/3 00:00:06 /bin/bash ./test.sh
xiao 3365 28517 0 10:09 pts/3 00:00:06 /bin/bash ./test.sh
xiao 3401 28517 0 10:09 pts/3 00:00:06 /bin/bash ./test.sh
xiao 3443 28517 0 10:09 pts/3 00:00:06 /bin/bash ./test.sh
xiao 3480 28517 0 10:09 pts/3 00:00:06 /bin/bash ./test.sh
xiao 5299 28517 0 10:10 pts/3 00:00:06 /bin/bash ./test.sh
xiao 5396 28517 0 10:10 pts/3 00:00:06 /bin/bash ./test.sh
xiao 5431 28517 0 10:10 pts/3 00:00:06 /bin/bash ./test.sh
xiao 5470 28517 0 10:10 pts/3 00:00:06 /bin/bash ./test.sh
xiao 5488 28517 0 10:10 pts/3 00:00:06 /bin/bash ./test.sh
xiao 6589 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 6754 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 6899 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 6972 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 7015 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 7095 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 7129 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
xiao 7172 28517 0 10:33 pts/3 00:00:05 /bin/bash ./test.sh
ps -ef|grep test.sh|awk '{print "kill -9 " $2}'|sh
服务启动、重启、停止
一个服务的启动、重启、停止的shell脚步:
#!/bin/sh
NowPath=`pwd`/${0%/*}
CMD=$1
if [ "$CMD"x = "stop"x ]
then
cat $NowPath/log/app.pid | xargs kill
elif [ "$CMD"x = "reload"x ]
then
cat $NowPath/log/app.pid | xargs kill -USR2
cat $NowPath/log/app.pid | xargs echo
elif [ "$CMD"x = "start"x ]
then
rm $NowPath/nohup.out
cd $NowPath
/bin/sh -c 'nohup ./ppfs-api-gym &'
cat $NowPath/log/app.pid | xargs echo
else
echo "./bin start | reload | stop"
fi
git仓库的钩子
一个git仓库的钩子脚步:
#!/bin/sh
unset GIT_DIR
NowPath=`pwd`
echo "now path is :"$NowPath
pullDev(){
cd $1
echo $1
echo $2
echo $3
echo $4
#build
echo "================================="
echo "npm rum build ... "
a=`stat -c %Y ./package.json`
b=`date +%s`
c=`expr $b - $a`
if [ $c -lt 5 ]
then
echo "npm install ... "
npm install --registry=https://registry.npm.taobao.org
fi
echo "npm run build ... "
npm run build:$4
#chmod -R 777 $2
#raync
echo "================================="
echo "rsync ... "
#cd $NowPath
rsync -aH -O --no-p --no-g --no-o --delete --progress --exclude=".git/" --exclude="Log/*" $2 $3 >/dev/null
echo "rsync fine"
chmod -R 777 $3
}
DevPath="/data/codeSrc/dev/ppfs/ppfs-web-base"
DevBuildPath="/data/codeSrc/dev/ppfs/ppfs-web-base/dist/"
DevWebPath="/data/www-data/dev/ppfs/ppfs-web-base/"
buildCode="demo"
echo "deploy path is :"$DevPath
cd $DevPath
echo "cd deploy path"
#git fetch origin
echo "================================="
echo "pull ... "
git checkout dev
devPullResult=`git pull`
echo "deploy done"
echo "pull fine"
if [ "$devPullResult"x != "Already up-to-date."x ]
then
pullDev $DevPath $DevBuildPath $DevWebPath $buildCode
else
#pullDev $DevPath $DevBuildPath $DevWebPath $buildCode
rsync -aH -O --no-p --no-g --no-o --delete --progress --exclude=".git/" --exclude="Log/*" $DevBuildPath $DevWebPath >/dev/null
echo "rsync fine"
chmod -R 777 $DevWebPath
fi
exit 0
mysql备份脚步
#!/bin/sh
nowmouth=`date --date='0 days ago' "+%Y%m"`
nowtime=`date --date='0 days ago' "+%Y%m%d_%H_%M_%S"`
nowhours=`date --date='0 days ago' "+%H"`
mkdir -p /data2/db-back/data/$nowmouth
###############################################
oldmouth=`date --date='7 days ago' "+%Y%m"`
oldtime=`date --date='7 days ago' "+%Y%m%d_%H_%M_%S"`
nowhours=`date --date='0 days ago' "+%H"`
if [ "$nowhours"x = "12"x ]
then
echo "aaaa"
rm /data2/db-back/data/$oldmouth/ppos_stadia.$oldtime.sql
fi
###############################################
oldoldmouth=`date --date='120 days ago' "+%Y%m"`
rm -rf /data2/db-back/data/$oldoldmouth
###############################################
/data/service/mysql56/bin/mysqldump -h 127.0.0.1 -utoot -p123456 --routines --events --triggers --single-transaction --flush-l
ogs --databases --set-gtid-purged=off ppos_stadia > /data2/db-back/data/$nowmouth/ppos_stadia.$nowtime.sql
乐果 发表于 2018 年 09 月 06 日 标签:shell