计算日期:
1.用天计算
(Year*365)+(Year/4)-(Year/100)+(Year/400)+(Month*306001/1000)+(Day)
注意:一月二月Month+13,Year-1;其他月份仅仅是Month+1
使用函数:
如何直接调用函数:
a./etc/init.d/functions向其中添加我们的函数
b.使用source命令生效后天添加的函数
# source /etc/init.d/functions
自定义库文件:
不要显示grep这个命令显示结果:
[root@desktop4 hgx]# ps -ef |grep vsftpd | grep -v grep
help提示和确定只能有一个程序在运行
#提示命令的用法,
if [ $# -ne 0 ] #如果脚本执行参数为0,则提示错误,并还回1
then
echo "Usage:hahhahahahhahahhahah"
echo "hegkhdkfklsdklgjlksdjgklj"
exit 1
fi
#插入时间标志:
echo "!!!Begin to find top at :`date`!!!"
#确定只能同时运行一个脚本实例:
ps -ef | grep "sh findcdr.sh" | grep -v grep | awk '{print $9}' > pidinfo
pn=`cat pidinfo | grep -c findcdr.sh`
echo "checking findcdr.sh process: $pn" #通过统计符合的值来确定运行实例的个数
ps -ef | grep 'sh findcdr.sh' | grep -v grep
if [ $pn -ne 1 ] #如果运行实例不是唯一一个,则输出错误并还回1
then
echo "!!! Another one is running this script,abort the script!!!"
exit 1
fi
rm pidinfo >/dev/null 2>&1
#sleep 10
case $X in:
运行的命令:sh findcdr.sh $1 $2 $3,然后判断参数(下面是参数3)是属于哪一种情况,然后分别赋值变量,方便以后的IF判断等。
#
# process cdr type
#
echo ""
echo ""
echo ""
echo "You want to find SCDR for $2"
echo "<-------------------------------------------------------------->"
cdrtypeid=1
;;
sacdr)
echo ""
echo ""
echo ""
echo "You want to find SACDR for $2"
echo "<-------------------------------------------------------------->"
cdrtypeid=2
;;
all)
echo ""
echo ""
echo ""
echo "You want to find SCDR&SACDR for $2"
echo "<-------------------------------------------------------------->"
cdrtypeid=3
;;
*)
echo ""
echo ""
echo ""
echo "This script is only used for sacdr ,or sacdr ,or scdr&sacdr"
echo "<-------------------------------------------------------------->"
exit 1
;;
esac
云平台开发运维解决方案@george.sre
GitHub: https://github.com/george-sre
欢迎交流~