LoginSignup
17
19

More than 5 years have passed since last update.

シェルスクリプトでsudoを実行する

Posted at

仮にApacheの再起動をしたい場合などは、

echo "パスワード" | sudo -S /etc/rc.d/init.d/httpd restart

と書いてやると実行できます。

もちろん、実行ユーザにはvisudoで権限を与えてやって下さい。

全てOKであれば

visudo
hoge ALL=(ALL)

ApacheとMySQLの操作だけにしたい場合は、

visudo
hoge ALL=(ALL) /etc/rc.d/init.d/httpd,/etc/rc.d/init.d/mysqld

などなど。

17
19
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
17
19