shell脚本中判断进程是否存在
#! /bin/bash
PROC_NAME=docker
ProcNumber=`ps -ef |grep -w $PROC_NAME|grep -v grep|wc -l`
if [ $ProcNumber -le 0 ];then
echo "testPro is not run"
sh /root/shell/docker-start.sh
else
echo "testPro is running.."
fi
Linux find 排除某个目录
find . -path ./ggpay/model -prune -o -name '*.class' -not -type d -print
查看用户test的所有进程
ps -eLf | grep 'test'
判断文件中是否存在指定内容
if [ `grep -c "WantedBy" /etc/systemd/system/rc-local.service` -eq '0' ]; then
echo "start to write config to /etc/systemd/system/rc-local.service"
sudo echo "
[Install]
WantedBy=multi-user.target
Alias=rc-local.service" >> /etc/systemd/system/rc-local.service
读取文件并写入到另外一个文件
echo "" >compose/.env
while read -r line || [[ -n ${line} ]]
do
name=$(echo "${line}" | cut -d '=' -f 1 | sed "s/-/_/g")
image=$(echo "${line}" | cut -d '=' -f 2)
if [[ -n "$image" ]]; then
echo "${name^^}_IMAGE=$image" >>compose/.env
fi
done < images/RELEASE