0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

shellscript rootユーザ確認スクリプト

Posted at

概要

  • bashで今のユーザがrootかどうか判定するスクリプトです。

スクリプト

  • スクリプト名:check_user_root.sh

# !/bin/bash

# ----------------------------------------
# code by Taki_Naka
#
# version
# 2020/02/01 new
#
# note
#
# ----------------------------------------

# global variable
user_name=$(whoami)

# chock user name
function check_user_name(){
  if [[ "$user_name" = "root" ]]; then
    echo "user is "$user_name"."
    exit 0
  else
    echo "user is "$user_name"."
    echo "Please execute as root user"
    exit 255
  fi
}


# main
check_user_name

経緯

  • お名前.comのVPNで遊んでいます。
  • 構築を楽にしたくて、スクリプト化しています。
  • まずは、手動構築 ⇒ スクリプト化(主にbash)⇒ 自動構築OSS って感じでレベルアップしていければと思います。

note

  • Log関数を作って連携させたい。

参考

シェルスクリプト(bash)のif文やwhile文で使う演算子について
bashスクリプティング研修の資料を公開します
シェルで現在のユーザー名を取得する方法

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?