0

スクリプトで特定のコマンドを実行したい。何かのようなもの:

if(today is monday){
  do something;
}

シェルスクリプトでこれを行う方法はありますか?

4

3 に答える 3

2

POSIX 準拠のシェルを使用している場合:

if [ "$(date +%A)" = "Monday" ]; then
    echo "something"
fi

+%Aは、現在の日の完全な名前を返します。見る

date --help

より多くのフォーマットオプションについて。

于 2013-03-25T18:23:46.410 に答える
1

bash スクリプトを想定すると、次のようになります。

#!/bin/bash

# Use the date command to get the numerical representation of the week 
# (or whatever format you are looking for)
check=$(date +%u)

if [ "$check" == 1 ]; then
    # Monday
    # Do something
elif [ "$check" == 2 ]; then
    # Monday
    # Do something
...
elif [ "$check" == 7 ]; then
    # Sunday
    # Do something
fi

編集 - 完全を期すために bin/bash を追加

于 2013-03-25T18:22:25.037 に答える
-1

Windows を使用している場合は、これを使用して特定の日付/時刻のプロセスをスケジュールできます。

schtasks

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true

曜日だけ確認したい場合は の最初の3文字が%DATE%曜日

于 2013-03-25T18:12:48.160 に答える