判斷linux的用戶狀態

                    判斷linux的用戶狀態

目的:判斷linux系統中某一用戶的 是否存在,若存在,則輸出該用戶的家目錄,使用的內核和密碼狀態。

 具體的代碼:

#!/bin/bash
read -p "please input one account:" ACCOUNT
if grep "^$ACCOUNT\>" /etc/passwd &>/dev/null;then
HOMEDIR=`grep "^$ACCOUNT\>" /etc/passwd |cut -d: -f 6`
SHELL=`grep "^$ACCOUNT\>" /etc/passwd |cut -d: -f 7`
echo "this user $ACCOUNT is exist"
echo "this user homdir  is $HOMEDIR"
echo "this user shell is $SHELL"
/usr/bin/passwd -S $ACCOUNT &>/tmp/state

if grep -i "lock"  /TMP/STATE;then
    echo "lock"
elif grep -i "empty" /tmp/state;then
    echo "empty"
elif grep -i "md5" /tmp/state;then
    echo  "encry"
fi
else
echo "this user $ACCOUNT is not exist"
fi

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章