1. shell获取当前时间并输出到文件中
myname=$(date +%Y-%m-%d_%H:%M:%S)
echo $myname >> a.txt
2.后台启动python脚本,关闭终端不退出
#!/bin/sh
ps -fe|grep api_change_email_notify |grep -v grep
if [ $? -ne 0 ]
then
python api_change_email_notify.py&
#echo "start api_change_email_notify success!"
#else
#echo "process exist"
fi
#####
3.获取当前shell的文件夹位置
http://blog.csdn.net/samxx8/article/details/51254546
basepath=$(cd `dirname $0`; pwd)
4. 执行字符串命令
#!/bin/bash pid=`ps -ef|grep api_change_email_notify.py|grep -v grep|awk '{print $2}'` if [ -z "$pid" ];then date=`date +%Y%m%d_%-H:%-M:%S` basepath=$(cd `dirname $0`; pwd) cmd="python ${basepath}/xxxx.py&" eval $cmd #echo "$date 未检测到api_change_email_notify,现在启动" >> /var/wd/api_manager/bin/pidtest.txt else date=`date +%Y%m%d_%-H:%-M:%S` #echo "$date $pid" >> /var/wd/api_manager/bin/pidtest.txt fi