スクリプトで特定のコマンドを実行したい。何かのようなもの:
if(today is monday){
do something;
}
シェルスクリプトでこれを行う方法はありますか?
スクリプトで特定のコマンドを実行したい。何かのようなもの:
if(today is monday){
do something;
}
シェルスクリプトでこれを行う方法はありますか?
POSIX 準拠のシェルを使用している場合:
if [ "$(date +%A)" = "Monday" ]; then
echo "something"
fi
+%Aは、現在の日の完全な名前を返します。見る
date --help
より多くのフォーマットオプションについて。
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 を追加
Windows を使用している場合は、これを使用して特定の日付/時刻のプロセスをスケジュールできます。
schtasks
曜日だけ確認したい場合は の最初の3文字が%DATE%
曜日