0
1

More than 3 years have passed since last update.

システム時刻設定(date コマンド利用のシェルスクリプト)

Posted at

こんにちは。
date コマンドを利用し、システム時刻設定(変更)を行うシェルスクリプトを作ってみました。ただし単に、BSDタイプの設定指定を Linux へ適用しただけです。12時00分ちょうどへ設定する動作例です。

$ sudo date_set.sh 1200
2019年 10月 8日 火曜日 11時59分59秒 JST
2019年 10月 8日 火曜日 12時00分00秒 JST
date_set.sh
#!/bin/sh
# usage: sudo date_set.sh 1200
date
if [ "$(uname)" = "Darwin" ]; then
  date "$1"
elif [ "$(uname -s | cut -c 1-5)" = "Linux" ]; then
  hh="$(echo "$1" | cut -c 1-2)"
  mm="$(echo "$1" | cut -c 3-4)"
  date -s "$hh:$mm:00"
fi
exit $?
0
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
0
1