nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

need help to add user password using dialog utility

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 ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 07-13-2006, 01:09 AM
Junior Member
User
 
Join Date: Jul 2006
Location: Pune
Posts: 5
Rep Power: 0
vishal Titre
Send a message via MSN to vishal Titre Send a message via Yahoo to vishal Titre
Default need help to add user password using dialog utility

hello all
i am facing one problame , can anybody send me script to add new user and set password for new user using dialog utility.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-13-2006, 02:23 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

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
Reply With Quote
  #3 (permalink)  
Old 07-13-2006, 02:35 AM
Junior Member
User
 
Join Date: Jul 2006
Location: Pune
Posts: 5
Rep Power: 0
vishal Titre
Send a message via MSN to vishal Titre Send a message via Yahoo to vishal Titre
Default

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.$$
Reply With Quote
  #4 (permalink)  
Old 07-13-2006, 06:20 PM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

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
Hope this helps
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT +5.5. The time now is 07:42 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36