LoginSignup
5
6

More than 5 years have passed since last update.

rootで処理を行うシェルスクリプト

Posted at

シェルの途中でルートパスワードを入力させて、それ以降をルートで実行するためには以下のようにするとできます。


#!/bin/bash

Passwd()
{
        su root -c "$0 '#'"
}

Root_exe()
{
        #execute commands as root
}

if [ "$1" = '#' ]; then
        Root_exe || exit $?
else
        Passwd || exit $?
fi
5
6
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
5
6