赞
踩
简述:在开发过程中,有时需要将开发程序的debug 信息写入文件中,以便调试查看。但是如果直接在文件中添加写文件的操作又比较繁琐,频繁的写文件也增加的程序的压力。下面提供一个方法,将已经开发完的程序的debug 信息写入文件。
通过写脚本启动程序,并且在脚本中自定义 输出debug信息文件的路径和名称
startup.sh
#!/bin/bash
base_dir="$(dirname "$0")"
cd $base_dir
if [[ $# == 1 ]] && [[ $1 == "debug" ]];then
nohup ./XXXX >debug.log 2>&1 &
else
nohup ./XXXX >/dev/null 2>&1 &
fi
echo $! > ./XXXX.pid
echo "----"
echo "XXXX started."
核心部分
脚本路径/脚本名 >/dev/null 2>&1
说明:
可以简单的理解/dev/null是Linux下的回收站
>默认是把标准输出重定向
2>&1是把出错输出也定向到标准输出
shutdown.sh
#!/bin/bash
base_dir="$(dirname "$0")"
cd $base_dir
echo "----"
echo "XXXX is shutting down..."
if [ -f ./XXXX.pid ];then
pid=`cat ./XXXX.pid`
kill $pid
rm -f ./XXXX.pid
echo ""
echo "Done."
else
echo ""
echo "Error: pid file is NOT FOUND!"
fi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。