Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Shell script - craete user/password/home dir

Programming


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 12-02-2016
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 27 February 2017, 11:44 AM EST
Location: Lancashire, UK
Posts: 3,016
Thanks: 1,256
Thanked 575 Times in 522 Posts
You are getting there. Ask your user if they are a vxf or normal user, read in the reply then using an if set a variable for the home directory. You can then use this variable in the useradd command.



Let us know if you get stuck,
Robin
Sponsored Links
    #9  
Old Unix and Linux 12-02-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 February 2017, 5:50 AM EST
Posts: 46
Thanks: 5
Thanked 3 Times in 2 Posts
thanks Robin,

how do i catch the users input ie if they write v make a vfx_ftp or if they write n make a normal ftp

---------- Post updated at 02:06 PM ---------- Previous update was at 01:52 PM ----------

found the answer -
bash - How do I prompt for Yes/No/Cancel input in a Linux shell script? - Stack Overflow
Sponsored Links
    #10  
Old Unix and Linux 12-05-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 February 2017, 5:50 AM EST
Posts: 46
Thanks: 5
Thanked 3 Times in 2 Posts

Code:
#!/bin/bash
        echo "Enter UserName:"
        read user
                if id $user ; then
                echo "$user already exists as you can see above, please re-run the script"
                exit
                else
                echo "$user not in system, ok to continue"
                fi
        echo "Enter Password:"
        read passwd
        echo "$user:$passwd" >> /ftp_details/accounts.csv
        echo "is this a normal user (1) or vfx user (2) ?"
        read dir

        case $dir in
                1)
                useradd $user -s /sbin/nologin -b /mnt/data/
                touch /mnt/data/$user/files_will_get_deleted_older_than_14_days_old.txt
                ;;
                2)
                useradd $user -s /sbin/nologin -b /mnt/vfx/
                ;;
        esac
        echo $user:$passwd | chpasswd

The Following User Says Thank You to robertkwild For This Useful Post:
rbatte1 (12-05-2016)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Switching from root to normal user takes me to user's home dir syncmaster UNIX for Dummies Questions & Answers 1 10-03-2015 06:20 PM
how to change /export/home/user dir to /home /user in solaris kalyankalyan Solaris 2 05-31-2010 09:19 AM
unable to set user home dir some_one UNIX for Dummies Questions & Answers 14 04-30-2009 01:49 PM
need to restrict user to his home dir lidram Solaris 5 02-06-2008 11:03 AM
Modify user home dir kris_devis UNIX for Dummies Questions & Answers 4 04-17-2007 11:36 AM



All times are GMT -4. The time now is 08:48 PM.