logo
¡¡ whois | dll-download | HandBook | ¹ØÓÚ±¾Õ¾ | ºǫ́¹ÜÀí  ¡¡
¡ô              
2008 Äê 5 ÔÂ
ÈÕ Ò» ¶þ Èý ËÄ Îå Áù
    123
45678910
11121314151617
18192021222324
25262728293031
ÉÏÔ MONTH ÏÂÔ¡¡¡¡ÉÏÒ»Äê YEAR ÏÂÒ»Äê

Óû§Ãû:
ÃÜ¡¡Âë:

¡¡Õ¾ÄÚËÑË÷
¡¡Í³¼ÆÐÅÏ¢
¹²ÓÐÎÄÕÂ: 647
¹²·ÃÎÊÊý: 9475455
½ñÈÕ·ÃÎÊ: 3611
ÔÚÏßÈËÊý: 2
¡¡×îÐÂÎÄÕÂ
¡¡½ñÌ죬ÎÒ³´¹ÉÁË
¡¡RedHat AS4 ÕûºÏMyS...
¡¡windows server 200...
¡¡Ê¹ÓÃfind²éÕÒÎļþµÄ...
¡¡Linux Ö¸Áî¼òµ¥½«¹¥...
¡¡LinuxÏÂÅäÖÃÍêÕû°²È...
¡¡¹ØÓÚÎÞ×é¼þÉÏ´«µÄAD...
¡¡ÓÖһƪviϸ½âÎÄÕÂ
¡¡viÌæ»»ÃüÁîÓ÷¨Ïê½â
¡¡squid-2.6.STABLE1Ö...
¡¡Áã³É±¾ LinuxÏÂÇáËÉ...
¡¡squidÓÖһƪÏêϸÅäÖ...
¡¡as4 ͨ¹ýyum×Ô¶¯Éý¼...
¡¡È«¹ú¸÷µØÍøÍ¨DNS
¡¡squidÓ¦ÓÃÏê½â
¡¡mysql³£ÓÃÃüÁî
¡¡ÐÞ¸´ Table 'xxx' i...
¡¡MYSQLÐÔÄÜÓÅ»¯ÉèÖÃ
¡¡Clamav + Amavisd-n...
¡¡amavisd-newÔÚ¸øÓʼ...
¡¡×îÐÂÆÀÂÛ
¡¡Hi there :))) I in...
¡¡·¢²¼Õß°®ºÃÕßÌṩ×î...
¡¡Hi all! Excellent ...
¡¡Best views O_O Mov...
¡¡µû·§¹«Ë¾£¬¹«Ë¾-Éó...
¡¡Congratulations!!!...
¡¡Good day... Moving...
¡¡ÉϺ£,Öܱßsnooker b...
¡¡Hi ^_^ Great .Now ...
¡¡Congratulations. C...
¡¡Hi there! Good wor...
¡¡Good day! Nice sit...
¡¡Hi 8-) Palatable w...
¡¡Ò×ͨ±¨¼Û£¬gate val...
¡¡Hi there - Thanks ...
¡¡°üÀ¨¹«ÒæÍøÌṩרҵ...
¡¡Hi all :))) The be...
¡¡Hello ^_^ Palatabl...
¡¡»¶Ó­·ÃÎÊ£¬
¡¡»¶Ó­·ÃÎÊ£¬
¡¡×îÐÂÒýÓÃ
¡¡×î½üÎÞÒýÓÃÄÚÈÝ
¡¡ÓÑÇéÁ´½Ó
-¡¡Ä¿Ç°ÎÞÓÑÇéÁ´½Ó (0)
¡¡ÎÄÕ¾ۺÏ
RSS View v:1.0 RSS View v:2.0
ATOM View v:0.3 channel
×î½ü 10 ÌõÆÀÂÛ RSS View Powered by Blog
Creative Commons DeCode: GB2312
PHP MySQL
¡¡[Õ¾³¤½éÉÜ]
Õ¾³¤£º Glen
ÐÅÏ䣺 root@domsn.net
http://wwww.domsn.net

One Step Ahead
ÅúÁ¿Ôö¼ÓÓû§    2006-09-27 21:51:00

Linux AS4ϲâÊÔÀý×Ó£º
#cat namelistfile
aa
bb
-bash-3.00[lg]# ./adduser.sh -f namelistfile
Reading usernamelist file(namelistfile) ...
namelistfile
Now Let's set some options or you can use default settings.
Would you like to add a new group to add these users to it?
Enter (yes)to create a new group otherwise you must verify the group.
Your Answer: yes
Please enter the group's name: aa
All these users will be added to group(aa)...
Adding group ...
The group(aa) is added!
The passwd is used by default 000000.
The user(aa) is added.
Changing password for user aa.
passwd: all authentication tokens updated successfully.
The user(aa)'s password is setted!
The passwd is used by default 000000.
The user(bb) is added.
Changing password for user bb.
passwd: all authentication tokens updated successfully.
The user(bb)'s password is setted!
==================================

½Å±¾ÄÚÈÝÈçÏ£º
#!/bin/sh
#-----------------------------------
chkUID(){
  getUID(){
    id|sed -e 's/(.*$//' -e 's/^uid=//'
    }

  if [ "`getUID`" -ne 0 ]
  then
    echo -e "\tYou are not root!"
    exit 0
  fi
  }
chkUID
usagePRT(){
  echo ${USAGE:='USAGE:' `basename Linux AS4ϲâÊÔÀý×Ó£º
#cat namelistfile
aa
bb
-bash-3.00[lg]# ./adduser.sh -f namelistfile
Reading usernamelist file(namelistfile) ...
namelistfile
Now Let's set some options or you can use default settings.
Would you like to add a new group to add these users to it?
Enter (yes)to create a new group otherwise you must verify the group.
Your Answer: yes
Please enter the group's name: aa
All these users will be added to group(aa)...
Adding group ...
The group(aa) is added!
The passwd is used by default 000000.
The user(aa) is added.
Changing password for user aa.
passwd: all authentication tokens updated successfully.
The user(aa)'s password is setted!
The passwd is used by default 000000.
The user(bb) is added.
Changing password for user bb.
passwd: all authentication tokens updated successfully.
The user(bb)'s password is setted!
==================================

½Å±¾ÄÚÈÝÈçÏ£º
#!/bin/sh
#-----------------------------------
chkUID(){
  getUID(){
    id|sed -e 's/(.*$//' -e 's/^uid=//'
    }

  if [ "`getUID`" -ne 0 ]
  then
    echo -e "\tYou are not root!"
    exit 0
  fi
  }
chkUID
usagePRT(){
  echo ${USAGE:='USAGE:' `basename ` '-f namelistfile'}
  }
chkFILE(){
echo
  if [ ! "`awk 'NF!=2{print NF;exit;}' `" ] && [ "`awk 'NF!=2{print NF;exit;}' `" -ne 2 ] ; then
    echo -e "The file's format is not right!"
    exit 0
  fi
  }

userCHK(){
  for USER in `awk '{print ;}' `
  do
    if grep -wq $USER /etc/passwd ; then
      echo -e "The user($USER) has been added!"
      exit 1
    fi
    if echo $USER|grep -wq "^[0-9].*" ; then
      echo -e "The user($USER)'s name is wrong format!"
      exit 1
    fi
  done
  }

setOPT(){
  echo -e "Now Let's set some options or you can use default settings."
  setGRPNAME(){
    while :
    do
    echo -e "Would you like to add a new group to add these users to it?"
    echo -e "Enter (yes)to create a new group otherwise you must verify the group."
    printf "Your Answer: "
    read grpopt
    case $grpopt in
      yes)
      printf "Please enter the group's name: "
      read grpoptnew
      if cat /etc/group|sed 's/:.*//'|grep -wq $grpoptnew ; then
        echo "The group's name($grpoptnew) exist."
        exit
      else
        grpname=$grpoptnew
        echo -e "All these users will be added to group($grpname)..."
        echo -e "Adding group ..."
        if cp /etc/group /etc/group.$$ ; then
          if groupadd $grpname ; then
            echo -e "The group($grpname) is added!"
            rm -f /etc/group.$$
            break 1
          else
            echo -e "There's something wrong when adding the group($grpname)."
            echo -e " *** Please recovered the group file. *** "
            echo -e "You can cp /etc/group.$$ to /etc/group to recover."
          fi
        else
          echo "Error! Please check the program or your disk space."
          exit 0
        fi
      fi
      ;;
      *) : ;;
    esac
    done
    }
  setGRPNAME
  }

addUSER(){
  if cp /etc/passwd /etc/passwd.$$ && cp /etc/shadow /etc/shadow.$$ ; then

  for user in `sed 's/ .*//' `
  do
  pass=`awk '{
   ~/$name/
   {print ;exit}
   } name=$user' `
  if [ -z "$pass" ] ; then
    echo -e "The passwd is used by default 000000."
    pass=000000
  fi
  if [ ${#pass} -lt 6 ] ; then
    echo -e "The user($user)'s password is too short!"
    echo -e "Use default password: 000000."
    pass=000000
  fi
  if useradd $user -g $grpname ; then
    echo -e "The user($user) is added."
      if echo $pass|passwd $user --stdin ; then
        echo -e "The user($user)'s password is setted!"
      else
        echo -e "The user($user)'s password is NOT set!"
      fi
  else
    echo -e "The user($user) is NOT add."
  fi
  done
  rm -f /etc/passwd.$$ /etc/shadow.$$
  else
    echo -e "There something wrong when backup the passwd and shadow file."
  fi
  }

if [ $# -ne 2 ] ; then
  usagePRT
  exit 0
fi

case "" in
  -f)
  if [ -f "" ] ; then
    echo -e "Reading usernamelist file""("")" "..."
    chkFILE
    userCHK
    setOPT
    addUSER
  else
    echo -e "There's no usernamelist file!"
  fi
  ;;
  *) usagePRT
  exit 0
  ;;
esac
` '-f namelistfile'}
  }
chkFILE(){
echo
  if [ ! "`awk 'NF!=2{print NF;exit;}' `" ] && [ "`awk 'NF!=2{print NF;exit;}' `" -ne 2 ] ; then
    echo -e "The file's format is not right!"
    exit 0
  fi
  }

userCHK(){
  for USER in `awk '{print ;}' `
  do
    if grep -wq $USER /etc/passwd ; then
      echo -e "The user($USER) has been added!"
      exit 1
    fi
    if echo $USER|grep -wq "^[0-9].*" ; then
      echo -e "The user($USER)'s name is wrong format!"
      exit 1
    fi
  done
  }

setOPT(){
  echo -e "Now Let's set some options or you can use default settings."
  setGRPNAME(){
    while :
    do
    echo -e "Would you like to add a new group to add these users to it?"
    echo -e "Enter (yes)to create a new group otherwise you must verify the group."
    printf "Your Answer: "
    read grpopt
    case $grpopt in
      yes)
      printf "Please enter the group's name: "
      read grpoptnew
      if cat /etc/group|sed 's/:.*//'|grep -wq $grpoptnew ; then
        echo "The group's name($grpoptnew) exist."
        exit
      else
        grpname=$grpoptnew
        echo -e "All these users will be added to group($grpname)..."
        echo -e "Adding group ..."
        if cp /etc/group /etc/group.$$ ; then
          if groupadd $grpname ; then
            echo -e "The group($grpname) is added!"
            rm -f /etc/group.$$
            break 1
          else
            echo -e "There's something wrong when adding the group($grpname)."
            echo -e " *** Please recovered the group file. *** "
            echo -e "You can cp /etc/group.$$ to /etc/group to recover."
          fi
        else
          echo "Error! Please check the program or your disk space."
          exit 0
        fi
      fi
      ;;
      *) : ;;
    esac
    done
    }
  setGRPNAME
  }

addUSER(){
  if cp /etc/passwd /etc/passwd.$$ && cp /etc/shadow /etc/shadow.$$ ; then

  for user in `sed 's/ .*//' `
  do
  pass=`awk '{
   ~/$name/
   {print ;exit}
   } name=$user' `
  if [ -z "$pass" ] ; then
    echo -e "The passwd is used by default 000000."
    pass=000000
  fi
  if [ ${#pass} -lt 6 ] ; then
    echo -e "The user($user)'s password is too short!"
    echo -e "Use default password: 000000."
    pass=000000
  fi
  if useradd $user -g $grpname ; then
    echo -e "The user($user) is added."
      if echo $pass|passwd $user --stdin ; then
        echo -e "The user($user)'s password is setted!"
      else
        echo -e "The user($user)'s password is NOT set!"
      fi
  else
    echo -e "The user($user) is NOT add."
  fi
  done
  rm -f /etc/passwd.$$ /etc/shadow.$$
  else
    echo -e "There something wrong when backup the passwd and shadow file."
  fi
  }

if [ $# -ne 2 ] ; then
  usagePRT
  exit 0
fi

case "" in
  -f)
  if [ -f "" ] ; then
    echo -e "Reading usernamelist file""("")" "..."
    chkFILE
    userCHK
    setOPT
    addUSER
  else
    echo -e "There's no usernamelist file!"
  fi
  ;;
  *) usagePRT
  exit 0
  ;;
esac


Posted by glen in [shell] | ÆÀÂÛ:7 | ×Üä¯ÀÀ:1033 | [´òÓ¡È«ÎÄ]

¹Ø¼ü×Ö:
¹Ø¼ü×Ö: ÅúÁ¿ Ôö¼Ó Óû§,²©Ö¾,soft,glen'blog,blog,weblog,blog,qzhiwu@msn.com
ÒýÓÃ [0]
±¾ÎÄÎÞTrackback
Ìí¼ÓÆÀÂÛ
êdzÆ: * ÃÜÂë:
ÐÅÏä: ͬʱע²áÕâ¸öêdzÆ
Ö÷Ò³: http://¿ªÍ·
£Ñ£Ñ:
¡¡ *
ÁªÏµÎÒÃÇ |  
¡¡
Copyright © 2006-2008 DoMsN All Rights Reserved.
ÔÁICP±¸05141795ºÅ