shell脚本入门

来源:互联网 发布:利拉德体测数据 编辑:程序博客网 时间:2024/04/28 18:28

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/bashpid=`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.txtelse    date=`date +%Y%m%d_%-H:%-M:%S`    #echo "$date  $pid" >> /var/wd/api_manager/bin/pidtest.txtfi


原创粉丝点击