LoginSignup
2
1

More than 5 years have passed since last update.

毎月最終金曜(プレミアムフライデー)だったら実行するシェルスクリプト

Posted at

背景

今日は、プレミアムフライデーらしいです。
https://premium-friday.go.jp/
そんなことはお構いなく仕事していますが、プレミアムフライデーのみ動作するスクリプトを書いてみます。

環境

  • CentOS
  • bash

スクリプト

premiumfriday.sh
#!/bin/bash
export LANG=C

# 実行曜日 以下のいずれかを指定
# Sun, Mon, Tue, Wed, Thu, Fri, Sat
DAY_OF_WEEK=Fri

# 曜日チェック
now_date=`date +%a`
if [ "x$DAY_OF_WEEK" != "x$now_date" ]; then
    # 金曜ではありません。残念。
    exit 1
fi

# +7日して、翌月になったら、最終週
now_month=`date +%m`
next_week_month=`date +%m --date '7 days'`
if [ "x$now_month" == "x$next_week_month" ]; then
    # 金曜だけど最終週ではないので終了。残念。
    exit 1
fi

# プレミアムフライデーだ!
echo "Hayaku Kaere!!"
exit 0

解説

解説するほどではないですね。もう少しスマートにできるとは思うのですが・・・

あとがき

来月は早く帰るぞ!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1