|
发表于 2006-9-21 03:15:53
|
显示全部楼层
Post by wawxdyy
那怎么把root权限回传给副进程啊,我记得你说过用exec,可我不知道怎么用,能给点简单的代码说明一下吗,麻烦了
比如说你的主程序叫A.sh,调用的子程序叫B.exp。
A.sh:
- #!/bin/bash
- if [[ "$USER" != "root" ]]; then
- rootpw=$(zenity --title="require root auth" --text="input the root passwd" --entry --hide-text)
- ./B.exp $rootpw
- exit 0
- fi
- echo "whatever you need from root"
- exit 0
复制代码
B: (expect)
- #!/usr/bin/expect -f
- set pw [lrange $argv 0 0]
- spawn su - root -c 'A.sh'
- expect ...
- ...
复制代码
Another way using gksu
- #!/bin/bash
- if [[ "$USER" != "root" ]]; then
- echo "Need root to run"
- exec gksu -u root ./A.sh
- fi
- echo "whatever you need from root"
- echo $USER
- exit 0
复制代码 |
|