Changing to root user inside shell script

后端 未结 5 1374
不思量自难忘°
不思量自难忘° 2021-01-03 21:13

I have a shell script which needs non-root user account to run certain commands and then change the user to root to run the rest of the script. I am using SUSE11. I have use

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 21:57

    The easiest way to do that would be to create a least two scripts.

    The first one should call the second one with root privileges. So every command you execute in the second script would be executed as root.

    For example:

    runasroot.sh

    sudo su-c'./scriptname.sh'
    

    scriptname.sh

    apt-get install mysql-server-5.5
    

    or whatever you need.

提交回复
热议问题