Inspired by the oneStack script:
It turns out that the script can be executed with a certain user permission easily.
The script content is as follows:
#! /Bin/bash # filename: test. sh # email: wangxiaoyu@Live.com # date: 2013-09-02user = "root" if ['whoam '! = "$ {User}"]; then exec su-"$ {user}"-c "sh $ {PWD}/test. sh "fiecho" The following is the script body content "idecho" the end of executing the id command"
The debugging information is as follows:
Xiaoyuwang @ localhost :~ $ Sh-x test. sh
+ User = root
+ Whoami
+ [Xiaoyuwang! = Root]
+ Exec su-root-c sh/home/xiaoyuwang/test. sh
Password:
The content of the script body is as follows:
Uid = 0 (root) gid = 0 (root) groups = 0 (root)
The execution of the id command ends.
This article is from the "Greek Open Source" blog, please be sure to keep this source http://wangxiaoyu.blog.51cto.com/922065/1287600