1 #!/bin/bash
2
3 #it is for root to change shell for users
4 #wrote by badboy 2011.10.9
5
6 echo
7 echo "####### It is for root to change users'shell ########"
8 echo
9 echo "#### Wrote by badboy #####"
10 echo "#####################################################"
11 echo "## for example : user=root shell=/bin/bash ##"
12 echo "#####################################################"
13 read -p " enter the user name :" USER
14 read -p " enter the shell for $USER :" SHELL
15
16 ######### to see if the user exit
17
18 if grep $USER /etc/passwd 1> /dev/null
19 then
20 echo
21 else
22 echo "System does not exit the user"
23 exit
24 fi
25
26 OIFS=$IFS
27 IFS=:
28 cat /etc/passwd | while read a b c d e f OLDSHELL
29 do
30 if [ $a = $USER ]
31 then
32 echo "$a:$b:$c:$d:$e:$f:$SHELL" >>/etc/passwd.old
33 else
34 echo "$a:$b:$c:$d:$e:$f:$OLDSHELL" >>/etc/passwd.old
35 fi
36 done
37 IFS=$OIFS
38 cp /etc/passwd /etc/passwd.`date %y%m%d` #备份passwd
39 cat /etc/passwd.old >/etc/passwd && cat /dev/null >/etc/passwd.old
阅读(3283) | 评论(0) | 转发(0) |