I have been looking all over for a simple way to combine various scripts to do this. I am not the strongest at scripting but I am working on improving so go easy on me. Any assistance here is appreciated.
I am not the author of this but I am using it as a start. I'd like to understand what the best approach to running this against a list of ips would be. I'm most interested in simplicity and understanding if a user exists already and if it errors out.
#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User 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