LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-03-2009, 05:48 PM   #1
fshstx1
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Help me make this work.


I am trying to get this working with option to loop or exit
Code:
#!/bin/bash

create_user () {
clear
read -p "Enter username : " username
read -p "Enter Group : " group
        useradd -g $group -p $username $username
        chage -d 0 $username
        echo "User has been added to system!"
        echo "User must change password at first login"
        read -p "Create another user : (y)es (n)o : " repeat
        if [ $repeat = n ]
        then creat_user
        else
        exit
}
This is only the portion that I want to repeat and it works up until the if statement. please help. I am using Red Hat

Last edited by pixellany; 12-03-2009 at 06:03 PM.
 
Old 12-03-2009, 06:09 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I fixed the [CODE] tags (no extra charge....)

Assuming that "creat_user" was meant to be "create_user", I do not understand calling a function from within its own definition code. Assuming that this is legal, then I think the logic is wrong---if $repeat = y, you want to create another user.
 
Old 12-03-2009, 06:14 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Maybe a while loop instead of an if condition?
Code:
#!/bin/bash

create_user () {
clear
repeat = y
while [ $repeat != n ]
do
read -p "Enter username : " username
read -p "Enter Group : " group
        useradd -g $group -p $username $username
        chage -d 0 $username
        echo "User has been added to system!"
        echo "User must change password at first login"
        read -p "Create another user : (y)es (n)o : " repeat
done
}
 
Old 12-03-2009, 06:31 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Note
Quote:
-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The default is to disable the account.
Means you have to encrypt the passwd before you call useradd.

If you supply a plaintext passwordd, do this instead

echo password | passwd --stdin $USER

which will encrypt it for you and add it to /etc/shadow.
 
Old 12-03-2009, 11:12 PM   #5
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Code:
#!/bin/bash

create_user () {
clear
read -p "Enter username : " username
read -p "Enter Group : " group
        useradd -g $group -p $username $username
        chage -d 0 $username
        echo "User has been added to system!"
        echo "User must change password at first login"
        read -p "Create another user : (y)es (n)o : " repeat
        if [ $repeat = y ]
        then create_user
        else
        exit
fi
what about this code now , is it working?
it works on my pc
recursion in bash , nice idea

Last edited by deepinlife; 12-03-2009 at 11:14 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make Xconfig doesn't work, make menuconfig does work Debian/KDE bucovaina78 Linux - Kernel 1 10-15-2008 01:26 PM
1st time installing redhat - Make and Make Install does not work runlikeanantelope Linux - Newbie 4 02-19-2007 03:58 PM
Trying to make mod_ssl work - virtualhosts make trouble Belize Linux - Software 0 02-26-2005 08:30 PM
How do I make a change to a current kernel? Would 'make oldconfig' work... jtp51 Slackware 11 11-01-2004 11:02 PM
'make' and 'make install' commands dont work on my system? ginda Linux - Newbie 9 04-18-2004 11:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration