Created
May 27, 2015 13:19
-
-
Save yatt/9498b3a657d19411d5dc to your computer and use it in GitHub Desktop.
easy task scheduler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| # easy task scheduler | |
| # | |
| # 1. mkdir taskscheduler/app/bin/cal/log | |
| # taskscheduler | |
| # ├── app (775) | |
| # │.. ├── renkei_0001.sh | |
| # │.. └── renkei_0002.sh | |
| # ├── bin (775) | |
| # │.. ├── taskforwarder (775) | |
| # ├── cal (775) | |
| # │.. ├── renkei_0001.txt | |
| # │.. └── renkei_0002.txt | |
| # └── log (777) | |
| # ├── renkei_0001 | |
| # │.. ├── 20150527_2159.log | |
| # │.. ├── 20150527_2204.log | |
| # │.. └── 20150527_2207.log | |
| # └── renkei_0002 | |
| # ├── 20150527_2147.log | |
| # ├── 20150527_2148.log | |
| # ├── 20150527_2149.log | |
| # └── 20150527_2150.log | |
| # 2. add a line below your crontab | |
| # * * * * * /path/to/taskscheduler/bin/taskforwarder | |
| timestamp=$(date +'%Y-%m-%d %H:%M') | |
| ts2=$(date +'%Y%m%d_%H%M') | |
| base=$(dirname $0)/../ | |
| for f in $base/cal/*.txt | |
| do | |
| \grep -P "(?<!#)${timestamp}" $f 2>&1 > /dev/null | |
| if [ $? -eq 0 ]; then | |
| # TODO: guard duplicate running | |
| app=$base/app/$(basename $f .txt).sh | |
| log=$base/log/$(basename $f .txt)/${ts2}.log | |
| mkdir -p $(dirname $log) | |
| echo command: "$app 2>&1 >> $log" >> $log | |
| echo >> $log | |
| nohup $app 2>&1 >> $log & | |
| fi; | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment