您的位置:首页 > 运维架构 > Shell

通过脚本的方式杀tomcat进程(shell脚本),shell中将一个文件的内容读出赋值给一个变量

2017-11-16 20:47 811 查看
#!/bin/bash

echo "==================stop tomcat========================="
ps -aux | grep /usr/local/tomcat/ | grep -v grep > tomcat_info.txt
sed 's/  / /g' tomcat_info.txt > tomcat_info1.txt
sed 's/  / /g' tomcat_info1.txt > tomcat_info.txt
sed 's/  / /g' tomcat_info.txt > tomcat_info1.txt
cat tomcat_info1.txt | cut -d' ' -f 2 > tomcat_info.txt

for line in `cat tomcat_info.txt`
do
kill -9 $line
done

#/etc/init.d/tomcat stop
echo "==================stop tomcat success================="

echo "================start copy project===================="
cd /usr/local/tomcat/webapps
rm -rf xxxxxx_api*
cp -R /root/.jenkins/workspace/xxxxxx_api_pre/qt360-web/target/xxxxxx_api /usr/local/tomcat/webapps
echo "================end copy project======================"

echo "==================start tomcat========================"
BUILD_ID=DONTKILLME
#sh /usr/local/tomcat/bin/startup.sh
/etc/init.d/tomcat start
echo "==================start tomcat success================"

echo "==================start drop linux cache=============="
sync
echo 3 > /proc/sys/vm/drop_caches
echo "==================drop linux cache success============"


将一个文件中的内容读出,然后赋值给一个变量的方法:

#!/bin/bash
var=`cat file.txt`  反引号
或者
var=$(cat file.txt)


然后执行以下命令:

chmod +777 test.sh
sh test.sh
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: