没有写过shell? 没关系了,其实需求确定之后,你显然已经知道,这太简单了。不就是语法问题吗? 你别告诉我你不会谷歌,不会百度! 我就先抛几个需要考虑的点,后面直接给代码吧! 2、怎样防止同时多次运行同一个内容? 关键词: lock 4、怎样指定运行时间段,counter或者起始日期? 关键词: while, let, expr 5、附加:怎样知道当前的运行状态如何了? 关键词: echo , progress 把这些问题考虑好了,你就一步步去写吧,不知道语法的,直接谷歌、百度,代码参考如下: #/bin/bash # @author: youge # @date: 2015-12-22 startDate="2015-11-24" # when to start startDateTimestamp=`date -d "$startDate" +%s` endDate="2015-12-14" # when to end endDateTimestamp=`date -d "$endDate" +%s` sleepTime=25 # to take a break haveSthUndo=0 # check if there is something undo , if not , exit the program rootDir='/cygdrive/d/wamp/ppi/' dir=$rootDir"cron/" itemArr=("itemA" "itemB" "itemC") # the items you want to run there for item in ${itemArr[@]} do runFile=$rootDir$item".run"; if [ ! -f "$runFile" ] ; then haveSthUndo=1; echo $item" runs on me" $runFile " touched"; echo -e "script startTime: "`date "+%Y-%m-%d %H:%M:%S"` "\nbeginDate:" $startDate "\nendDate:" $endDate "\npath:" $dir >> $runFile touch "$runFile"; break;
Read full article from 写你的shell,其实很简单 - 等你归去来 - 博客园
No comments:
Post a Comment