提示用户输入一个用户名,输入要sudo执行的命令,如果执行该shell的不是以root的身份在执行的话则退出脚本,然后输入用户能够sudo的命令名称,加入信号捕捉。
如下:
#!/bin/bash
# Description:
# Date && Time:2010-12-26 07:39:12
# Author:AIDA_ZYF
# Version:2.6.18-164.el5
trap `echo "QUIT...";exit 1` SIGINT
if [ ! $USER='root' ];then
echo "Only root can execute this scripts."
exit 1
else
echo "Please input a name."
read NAME
if grep "^$NAME" /etc/passwd &>/dev/null ;then
read -p "Please give $NAME a run command" COM
echo "$NAME ALL=(ALL) NOPASSWD:/sbin/$COM" >>/etc/sudoers
else
echo "Please input a right name."
fi
fi
阅读(758) | 评论(0) | 转发(0) |