This is a discussion on need help to add user password using dialog utility within the Shell scripting forums, part of the Development/Scripting category; hello all i am facing one problame , can anybody send me script to add new user and set password ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
| Sponsored Links | ||
|
|
|
||||
|
I guess setting up password part is not working for you. This is common problem and can be solved using automated methods. Can you paste your current script, so that i can modify and make changes for you
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
|
|||
|
hello everybody
i am sending my script , plz help me in solving my problame , how to add new user and set the passwd using dialog utility. dialog --backtitle "HOV Services" --title "Add User" --inputbox "Enter the Username" 10 40 2>/tmp/useradd.$$ STAT=$? case $STAT in 1) rm -f /tmp/useradd.$$ ; return ;; 255) rm -f /tmp/useradd.$$ ; return ;; esac dialog --backtitle "HOV Services" --title "Add User" --inputbox "Enter the Password" 10 40 2>/tmp/userpass.$$ STAT=$? case $STAT in 1) rm -f /tmp/userpass.$$ ; return ;; 255) rm -f /tmp/userpass.$$ ; return ;; esac uname=`cat /tmp/useradd.$$` if [ $uname -eq: ] then dialog --backtitle "HOV Services" --title "Alert" --infobox " Enter the Username or press Cancel" 3 40 read return fi upass=`cat /tmp/userpass.$$` # save userpassword in to upass variable grep '\<$uname\>' /etc/passwd sel=$? if [ $sel -eq 0 ] then dialog --backtitle "Automation" --title "Alert" --infobox "User $uname Already Exist" 3 40 read return else useradd $uname passwd --stdin $uname < $upass dialog --backtitle "Automation" --title "Alert" --infobox "User $uname Added Successfully" 3 40 read return fi rm -f /tmp/useradd.$$ rm -f /tmp/userpass.$$ |
|
|||
|
Here is code:
Code:
#!/bin/bash
UP="/tmp/upass"
UN="/tmp/uname"
function getUser(){
dialog --backtitle "HOV Services" --title "Add User" --inputbox "Enter the Username" 10 40 2>$UN
STAT=$?
case $STAT in
1) rm -f $UN ; return ;;
255) rm -f $UN ; return ;;
esac
}
function getPassword(){
dialog --backtitle "HOV Services" --title "Add User" --inputbox "Enter the Password" 10 40 2>$UP
STAT=$?
case $STAT in
1) rm -f $UP ; return ;;
255) rm -f $UP ; return ;;
esac
}
function addUsertoSystem(){
user="$1"
# make sure user and password are supplied
if [ "$user" == "" -o ! -f $2 ]; then
dialog --backtitle "HOV Services" --title "Error" --yesno "Username or password is not given!\nDo you want to try again?" 7 60
if [ $? -eq 0 ]; then
getUser
getPassword
else
echo "Bye!"
exit 1
fi
fi
# make sure user does not exist
grep -E "^$user" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
dialog --backtitle "HOV Services" --title "Error" --yesno "Sorry user $user exits in system!\nDo you want to try again?" 7 60
if [ $? -eq 0 ]; then
rm -f $UP $UN
getUser
getPassword
addUsertoSystem "$(cat $UN)" "$UP"
else
echo "Bye!"
exit 1
fi
fi
# add user
echo Adding user $user with password $(cat $2)"
useradd $1
passwd --stdin $user < $2
}
######### main logic ################
getUser
getPassword
addUsertoSystem "$(cat $UN)" "$UP"
rm -f $UP $UN
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linux force user to set a password the first time they login | nixcraft | Getting started tutorials | 2 | 01-17-2008 08:43 PM |
| autoexpect utility | myfoot | CentOS / RHEL / Fedora | 1 | 12-11-2007 01:41 PM |
| Block Single User Login using root password | sayan4u86 | Networking, Firewalls and Security | 0 | 09-28-2007 07:47 AM |
| Shell script to delete a file with a dialog utility | shankar100 | Shell scripting | 4 | 03-02-2007 11:22 AM |
| HP UX user lock password, change password, password aging | rockdalinux | HP-UX | 0 | 12-20-2006 03:36 PM |