#!/bin/bash
# Script to add a user to Linux system
for (( i = 1 ; i <= 50; i++ ))
do
if [ $(id -u) -eq 0 ]; then
egrep "^user$i" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' "123456")
useradd -m -p $pass user$i
[ $? -eq 0 ] && echo "user$i has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi
done
ไม่มีความคิดเห็น:
แสดงความคิดเห็น