批次加使用者指令碼
批次加使用者指令碼
建立100個系統使用者,登入使用者名稱取值範圍為(exam0~exam99)使用者登入密碼與其使用者名稱相同,使用者的預設shell為要求為bash,使用者的home目錄要求在/home 下的與其使用者名稱相同的資料夾下;這100個使用者的uid應該從1001開始依次向後排列,同時這些使用者都應該屬於gid為1001的study組。
這個指令碼怎麼寫?
這個指令碼怎麼寫?
你看過鳥哥的私房菜沒有?第三版的??哪裡面有介紹,而且還有一個事例,也是講的如何批次的新增使用者!!你可以看看!好像是在shell指令碼這一章! 指令碼這個東西我也在學習中,不是太懂!所以.......你看看鳥哥的介紹吧!
===
#!/bin/bash
read -p "您想要建立多少個使用者:" count
i=1
name=user
while [ $i -le $count ]
do
if [ $i -le 9 ];then
i=0$i
fi
useradd $name$i
i='expr $i + 1'
done
-------------------------------------------------
自己修改下
read -p "您想要建立多少個使用者:" count
i=1
name=user
while [ $i -le $count ]
do
if [ $i -le 9 ];then
i=0$i
fi
useradd $name$i
i='expr $i + 1'
done
-------------------------------------------------
自己修改下
=====
我就拿十個來搞~~
[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study -g 1001
for i in $(seq 0 9)
do
ii=$[ $i+1000 ]
useradd exam$i -s /bin/bash -u $ii -g study
echo exam$i | passwd --stdin exam$i
done
++++++++++++++++++++++++++++++++++++++++++++++++++
[root@alibaba ~]# ./useradd
Changing password for user exam0.
passwd: all authentication tokens updated successfully.
Changing password for user exam1.
passwd: all authentication tokens updated successfully.
Changing password for user exam2.
passwd: all authentication tokens updated successfully.
Changing password for user exam3.
passwd: all authentication tokens updated successfully.
Changing password for user exam4.
passwd: all authentication tokens updated successfully.
Changing password for user exam5.
passwd: all authentication tokens updated successfully.
Changing password for user exam6.
passwd: all authentication tokens updated successfully.
Changing password for user exam7.
passwd: all authentication tokens updated successfully.
Changing password for user exam8.
passwd: all authentication tokens updated successfully.
Changing password for user exam9.
passwd: all authentication tokens updated successfully.
[root@alibaba ~]# tail -10 /etc/passwd
exam0:x:1000:1001::/home/exam0:/bin/bash
exam1:x:1001:1001::/home/exam1:/bin/bash
exam2:x:1002:1001::/home/exam2:/bin/bash
exam3:x:1003:1001::/home/exam3:/bin/bash
exam4:x:1004:1001::/home/exam4:/bin/bash
exam5:x:1005:1001::/home/exam5:/bin/bash
exam6:x:1006:1001::/home/exam6:/bin/bash
exam7:x:1007:1001::/home/exam7:/bin/bash
exam8:x:1008:1001::/home/exam8:/bin/bash
exam9:x:1009:1001::/home/exam9:/bin/bash
[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study -g 1001
for i in $(seq 0 9)
do
ii=$[ $i+1000 ]
useradd exam$i -s /bin/bash -u $ii -g study
echo exam$i | passwd --stdin exam$i
done
++++++++++++++++++++++++++++++++++++++++++++++++++
[root@alibaba ~]# ./useradd
Changing password for user exam0.
passwd: all authentication tokens updated successfully.
Changing password for user exam1.
passwd: all authentication tokens updated successfully.
Changing password for user exam2.
passwd: all authentication tokens updated successfully.
Changing password for user exam3.
passwd: all authentication tokens updated successfully.
Changing password for user exam4.
passwd: all authentication tokens updated successfully.
Changing password for user exam5.
passwd: all authentication tokens updated successfully.
Changing password for user exam6.
passwd: all authentication tokens updated successfully.
Changing password for user exam7.
passwd: all authentication tokens updated successfully.
Changing password for user exam8.
passwd: all authentication tokens updated successfully.
Changing password for user exam9.
passwd: all authentication tokens updated successfully.
[root@alibaba ~]# tail -10 /etc/passwd
exam0:x:1000:1001::/home/exam0:/bin/bash
exam1:x:1001:1001::/home/exam1:/bin/bash
exam2:x:1002:1001::/home/exam2:/bin/bash
exam3:x:1003:1001::/home/exam3:/bin/bash
exam4:x:1004:1001::/home/exam4:/bin/bash
exam5:x:1005:1001::/home/exam5:/bin/bash
exam6:x:1006:1001::/home/exam6:/bin/bash
exam7:x:1007:1001::/home/exam7:/bin/bash
exam8:x:1008:1001::/home/exam8:/bin/bash
exam9:x:1009:1001::/home/exam9:/bin/bash
========
從板凳的理念出發~~
[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study123 -g 3001
read -p "建立使用者數:" count
for i in $(seq 0 "$count")
do
ii=$[ $i+3000 ]
useradd exama$i -s /bin/bash -u $ii -g study123
echo exama$i | passwd --stdin exama$i
done
[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study123 -g 3001
read -p "建立使用者數:" count
for i in $(seq 0 "$count")
do
ii=$[ $i+3000 ]
useradd exama$i -s /bin/bash -u $ii -g study123
echo exama$i | passwd --stdin exama$i
done
========
建立10個系統賬戶,並加入到yewu組的指令碼
#!/bin/bash
i=1
groupadd yewu
while [ $i -le 10 ]
do
if [ $i -le 10 ] ;then
useradd stu0$i -g yewu
else
useradd stu$i -g yewu
fi
let i++
done
#!/bin/bash
i=1
groupadd yewu
while [ $i -le 10 ]
do
if [ $i -le 10 ] ;then
useradd stu0$i -g yewu
else
useradd stu$i -g yewu
fi
let i++
done
===========
互動式建立賬戶的腳步
#!/bin/bash
echo -n "please input a username:"
read AA
useradd $AA -s /sbin/nologin
echo "$AA" | passwd --stdin $AA &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
while [ $BB = yes ]
do
echo -n "please input a username:"
read EE
useradd $EE -s /sbin/nologin
echo "$EE" | passwd --stdin $EE &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
done
#!/bin/bash
echo -n "please input a username:"
read AA
useradd $AA -s /sbin/nologin
echo "$AA" | passwd --stdin $AA &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
while [ $BB = yes ]
do
echo -n "please input a username:"
read EE
useradd $EE -s /sbin/nologin
echo "$EE" | passwd --stdin $EE &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
done
====
迴圈語句 比如for
useradd home目錄自動解決了
密碼那 可以用 echo username:passwd | chpasswd 相關位置 變數代替
useradd home目錄自動解決了
密碼那 可以用 echo username:passwd | chpasswd 相關位置 變數代替
====
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23141985/viewspace-704838/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 批次殺程式指令碼指令碼
- 批次kill session實現指令碼Session指令碼
- 批次過程獲取指令碼指令碼
- Linux vsftp vuer虛擬使用者的建立批次指令碼LinuxFTPVue指令碼
- 資料庫批次授權指令碼資料庫指令碼
- 批次起停資料庫指令碼資料庫指令碼
- Oracle批次生成Merge指令碼程式Oracle指令碼
- 批次刪除指定目錄下的sh指令碼指令碼
- 【Excel】Excel 拆分以及批次匯入指令碼開發Excel指令碼
- CentOS使用expect批次遠端執行指令碼和命令CentOS指令碼
- apache ab壓力測試工具-批次壓測指令碼Apache指令碼
- 跑wordpress使用者密碼指令碼密碼指令碼
- 如何在shell指令碼里使用sftp批次傳送檔案指令碼FTP
- 批次檢查主機是否可達的ping指令碼.指令碼
- shell指令碼批量操作使用者指令碼
- shell oracle 建立使用者指令碼Oracle指令碼
- hr使用者示例建立指令碼指令碼
- ROS指令碼ip-mac繫結 批次繫結ip和macROS指令碼Mac
- Linux批量建立使用者指令碼Linux指令碼
- sqlserver 查詢使用者角色指令碼SQLServer指令碼
- linux批量新增使用者指令碼Linux指令碼
- Sqlserver 2014 用指令碼批次賦予使用者可以執行儲存過程的許可權SQLServer指令碼儲存過程
- 自動批次實現linux機器ssh免密shell指令碼Linux指令碼
- shell指令碼建立使用者及批量建立使用者指令碼
- 簡單介紹Shell指令碼之檔案批次建立與修改的方法指令碼
- 批次顯示指定目錄下的檔案數量的sh指令碼指令碼
- 對大量ip:port進行批次telnet檢測的python指令碼Python指令碼
- 通過shell指令碼 批量新增使用者指令碼
- 新增多個使用者的shell指令碼指令碼
- 指令碼建立表空間、使用者、表指令碼
- 在Linux中,用psswd批次修改使用者密碼Linux密碼
- 使用Linux expect批次巡檢Linux Aix Solaris磁碟使用率指令碼LinuxAI指令碼
- Oracle 建立表空間和使用者指令碼Oracle指令碼
- 巧用shell指令碼分析資料庫使用者指令碼資料庫
- linux 指令碼切換使用者不用輸入密碼Linux指令碼密碼
- mysql檢視使用者的許可權指令碼MySql指令碼
- Oracle的預設使用者及其建立指令碼[轉]Oracle指令碼
- Linux使用者登入記錄分析指令碼Linux指令碼