jumpserver/sudoadd.sh

36 lines
664 B
Bash
Raw Normal View History

2014-08-14 09:22:25 +00:00
#!/bin/bash
username=$1
password=$2
cwd (){
dir=$0
dirname $dir
}
dir=$(cwd)
. ${dir}/shell.conf
sudo_file=${dir}/sudo.ldif
2014-08-21 09:49:39 +00:00
user_sudo_file=${dir}/${username}.ldif
2014-08-14 09:22:25 +00:00
if [ -z $1 ];then
echo
echo "usage: ./sudoadd.sh username "
echo
exit 3
fi
id ${username} &> /dev/null
if [ $? != '0' ];then
echo "$username is not exit!"
exit 3
fi
2014-08-21 09:49:39 +00:00
sed -i "/guanghongwei/ s@dianping@$domain@g" ${sudo_file}
sed -i "/guanghongwei/ s@com@$suffix@g" ${sudo_file}
2014-08-14 09:22:25 +00:00
sed -e "s@guanghongwei@$username@g" ${sudo_file} > $user_sudo_file
2014-08-21 09:49:39 +00:00
ldapadd -x -h ${host} -w ${ldapassword} -D "cn=admin,dc=$domain,dc=$suffix" -f $user_sudo_file
rm -f $user_sudo_file