shell总结
启动jar包脚本
#!/bin/sh
nohup java -jar ./overseasNews.jar > /dev/null 2>&1 &
echo `jps | grep overseasNews.jar | grep -v grep ` " started!!!"
启动脚本2
#!/bin/bash
mypath=.
mainclass=com.isi.JdbcTest
for f in lib/*.jar
do
mypath=$mypath:$f
done
java -Xmx2g -cp $mypath $mainclass
停止指定线程脚本
#!/bin/sh
info=`ps -ef|grep overseasNews.jar |grep -v grep`
echo "killing thread info ####### " $info
pid=`echo $info |awk '{print $2}' `
kill -9 $pid
echo "pid " $pid " ##### killed!!!!"
停止线程脚本
kill -9 `ps -ef|grep harm_mirror_crawler.jar | grep -v grep|awk '{print $2}'`
两个脚本合并,通过输入参数控制启动和停止
#!/bin/sh
if [ $# = 1 ] && [ $1 = "start" ] ; then
nohup java -jar ./overseasNews.jar > /dev/null 2>&1 &
echo `jps | grep overseasNews.jar | grep -v grep ` " started!!!"
elif [ $# = 1 ] && [ $1 = "stop" ] ; then
info=`ps -ef|grep overseasNews.jar |grep -v grep`
echo "killing thread info ####### " $info
pid=`echo $info |awk '{print $2}' `
kill -9 $pid
echo "pid " $pid " ##### killed!!!!"
else
echo " arg error the only argument is start/stop"
fi
递归删除
find . -name '*.exe' -type f -print -exec rm -rf {} \;
查看端口是否通
wget 192.167.1.1:2233
循环请求
#!/bin/bash
for ((i=1; i<=127; i ++))
do
curl is ""
sleep 4s
done
压缩与解压
tar -cvf test.zip test
tar -zxvf test.zip
批量启动
#!/bin/bash
dir=`pwd`
server=`ls -d *server*`
echo "server path is "$dir/$server
cd $dir/$server
sh ./sbin/start.sh
echo "server is starting wait for 10 s"
sleep 10s
cd $dir
for i in `ls -d client*`
do
cd $dir/$i
echo "client path is==>" $dir/$i
sh ./sbin/start.sh
sleep 1s
done
批量清空
for i in `find . -name "*.out"`; do cat /dev/null >$i; done
find . -name '*log' -type f -print -exec truncate -s 0 {} \;
批量删除
find . -name '*.log' -type f -print -exec rm -rf {} \;
for i in `find . -name "*.out"`; rm -rf >$i; done
注意:如果使用for循环的批量删除和清空,磁盘空间如果满了,就会报 No space left on device,使用find的 -exec就不会
监控日志,重启卡死程序
#!/bin/bash
dir=`pwd`
while true
do
cd $dir
for i in `ls -d client*/`
do
cd $dir/$i
echo "client path is==>" $dir/$i
size=`cat $dir/$i/nohup.out | wc -l`
if [ $size == 0 ]
then
sh ./sbin/stop-client.sh
sh ./sbin/start-client.sh
echo "size is 0 restart client!!!"
else
echo "logsize="$size
fi
done
echo "scan over sleep 1 min!!!!"
sleep 60s
done
上一篇: 网络爬虫(网页追逐者)是什么 网络爬虫原理详情介绍
下一篇: 一视同仁