Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $(id -u) -eq 0 ]; then
- read -p "User name: " username
- read -p "Password: " password
- read -p "Days to expired: " dias
- final=$(date "+%Y-%m-%d" -d "+$dias days")
- gui=$(date "+%d/%m/%Y" -d "+$dias days")
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- echo "Username $username already exists!"
- exit 1
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -e $final -M -s /bin/false -p $pass $username
- [ $? -eq 0 ] && echo "Active until $gui!" || echo "Could not create the User!"
- fi
- else
- echo "Only root may add a user to the system"
- exit 2
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement