shell脚本(linux)
发布网友
发布时间:2022-04-24 01:32
我来回答
共2个回答
热心网友
时间:2023-10-18 19:32
if cat /etc/passwd | cut -d":" -f1 | grep -E "\busr2\b" > /dev/null 2>&1
then
echo "Account usr2 exists!"
else
useradd usr2 -d /home/usr2 -s /sbin/nologin && edquota -p usr1 usr2
fi
exit 0
----------------------
直接grep ^usr2不能精确匹配 ,类似usr22这样的也能被匹配到 ,可能造成错误
热心网友
时间:2023-10-18 19:33
MARK=`cat /etc/passwd | grep ^usr2`
if [ -z $MARK ] ; then
useradd usr2 -s /sbin/nologin
edquota -p usr1 usr2
else
echo "user usr2 exists"
fi
exit 0
热心网友
时间:2023-10-18 19:32
if cat /etc/passwd | cut -d":" -f1 | grep -E "\busr2\b" > /dev/null 2>&1
then
echo "Account usr2 exists!"
else
useradd usr2 -d /home/usr2 -s /sbin/nologin && edquota -p usr1 usr2
fi
exit 0
----------------------
直接grep ^usr2不能精确匹配 ,类似usr22这样的也能被匹配到 ,可能造成错误
热心网友
时间:2023-10-18 19:33
MARK=`cat /etc/passwd | grep ^usr2`
if [ -z $MARK ] ; then
useradd usr2 -s /sbin/nologin
edquota -p usr1 usr2
else
echo "user usr2 exists"
fi
exit 0