今日が1日かどうかを調べるツール
Windowsのコントロールパネルのタスク(タスクスケジューラ)では、スケジュールに「毎月1日」は設定できても、「毎月1日以外のすべての日」は設定できないようです。
バッチファイルから使える、「今日が1日かどうかを調べるツール」があったら便利だと思いました。というわけで、作りました。
firstdayofmonth.c:
/* firstdayofmonth: returns whether today is first day of month or not. ** exit status 0 : first day of month ** 1 : not first day of month */ #include <stdio.h> #include <time.h> /* prototype */ void usage(void); int main(int argc, char *argv[]) { time_t global_time; struct tm *local_time; if (argc > 1) { usage(); } global_time = time(NULL); local_time = localtime(&global_time); return (local_time->tm_mday == 1) ? 0 : 1; } void usage(void) { puts("firstdayofmonth: returns " \ "whether today is first day of month or not."); puts("exit status 0 : first day of month"); puts(" 1 : not first day of month"); }
英語は適当なので、間違っていても許してください (^^;
使い方はシンプルで、実行すると終了ステータス(ERRORLEVEL)に次の値をセットします。
- 実行した日が1日の場合:0
- 実行した日が1日でない場合:1
オプションに何か指定すると、使い方を表示します。
(このコマンドでは1日であることを正常として扱っています。1日の場合に0を返すのは、正常終了の場合に0を返すUNIXコマンドの終了ステータス規約に合わせました)
バッチファイルからは、次のように使います。
firstdayofmonth if errorlevel 1 goto :SKIP echo Today is the first day of month. :SKIP