两个shell脚本

脚本1停止lampp

#!/bin/bash

#set -xv 开启调试模式?

count=`ps -ef|grep lampp|grep -v "grep"|wc -l`  # ”`”是Tab键上面那个按住shift会出现~符号,除去grep本身的命令统计行数

if [ $count -gt 0 ] # 大于一才说明有进程启动了

then

ps -ef|grep lampp|grep -v "grep"|awk '{print $2}' | xargs kill -9 #awk去第二个,是进程号,xargs是全部杀掉

echo 'lampp has stopped...'

else

echo 'lampp is not running...'

fi

脚本2定时任务

touch /root/zuoye2.sh

vi /root/zuoye2.sh

#!/bin/bash       

cat /opt/lampp/logs/access_log > /tmp/`date +%Y-%m-%d`.log  # ”`”是Tab键上面那个,重定向到另一个文件

cat /dev/null > /root/test.txt #清空这个文件

crontab –e

59 23 * * * bash /root/zuoye2.sh #建立定时任务

脚本1停止lampp

 

#!/bin/bash

#set -xv

count=`ps -ef|grep lampp|grep -v "grep"|wc -l`  # ”`”Tab键上面那个按住shift会出现~符号

if [ $count -gt 0 ]

then

ps -ef|grep lampp|grep -v "grep"|awk '{print $2}' | xargs kill -9

echo 'lampp has stopped...'

else

echo 'lampp is not running...'

fi

 

脚本2定时任务

touch /root/zuoye2.sh

vi /root/zuoye2.sh

 

#!/bin/bash       

cat /opt/lampp/logs/access_log > /tmp/`date +%Y-%m-%d`.log  # ”`”Tab键上面那个

cat /dev/null > /root/test.txt

 

crontab –e

59 23 * * * bash /root/zuoye2.sh

原文地址:https://www.cnblogs.com/xiaojinniu425/p/6216206.html