Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $(id -u) -eq 0 ]; then
- read -p "Insert username" username
- read -s -p "Insert password" password
- grep '$username' /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- echo "User exists"
- exit 1
- else
- useradd -m -p $password $username
- [ $? -eq 0 ] $$ echo "Success" || echo "Failed"
- fi
- else
- echo "Youre not root, could not do this"
- exit 2
- fi
- [root@ip-10-0-7-125 script_collection]# ./them_user.sh
- Insert usernameoidech
- Insert password./them_user.sh: line 11: [: missing `]'
- Failed
- #!/bin/bash
- if [ $(id -u) -eq 0 ]; then
- read -p "enter username: " username
- read -s -p "enter pass: " 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"
- fi
- else
- echo "only root could add"
- exit 2
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement