建立KVM01~KVM20的帳號
並同時建造家目錄中的網站目錄
在網站目錄中自動產生index.html檔
並寫入內容,內容為使用者名稱
批次建立kvm01~kvm20帳號及密碼存到user.txt
$nano cruser
===================================
rm user.txt
touch user.txt
myvar=1
while [ $myvar -ne 10 ]
do
echo "kvm0"$myvar":123" >> user.txt
myvar=$(( $myvar + 1 ))
done
while [ $myvar -ne 21 ]
do
echo "kvm"$myvar":123" >> user.txt
myvar=$(( $myvar + 1 ))
done
===================================
建立使用者並產生家目錄及index.html等檔案
$nano mkuser
===================================
w=$(whoami)
[ $w != "root" ] && echo 需要root權限 && exit 1
[ ! -e user.txt ] && echo 找不到user.txt && exit 1
s=$(cat user.txt)
for us in $s
do
u1=${us%%:*}
u2=${us##*:}
echo $u1已建立
useradd -m -s /bin/bash $u1
echo "$u1:$u2" | chpasswd
mkdir /home/$u1/kmdepot
touch /home/$u1/kmdepot/index.html
echo "<"h1">" $u1 "<"/h1">" /home/$u1/kmdepot/index.html
sudo ln -s /home/$u1/kmdepot /var/www/$u1
done
===================================
刪除使用者
$nano rmuser
===================================
w=$(whoami)
[ $w != "root" ] && echo 需要root權限 && exit 1
[ ! -e user.txt ] && echo 找不到user.txt && exit 1
s=$(cat user.txt)
for us in $s
do
u1=${us%%:*}
userdel -r $u1
echo $u1 已刪除
done
===================================
沒有留言:
張貼留言