判斷linux的用戶狀態

                    判斷linux的用戶狀態linux

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

 具體的代碼:bash

#!/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/stateide

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"
fithis

相關文章
相關標籤/搜索