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


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-01-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 20 July 2017, 5:24 AM EDT
Posts: 68
Thanks: 7
Thanked 5 Times in 4 Posts
Shell script - craete user/password/home dir

Hi all,

I have created an ftps server using vsftpd and it works a treat

atm to create a user/password/home dir I do these two command -


Code:
useradd test -d /mnt/data/test
passwd test

also I have another dir that I use for home dirs, which is using a nfs location (vfx_ftp) and not the local sdb1 (data)


Code:
useradd test1 -d /mnt/vfx_ftp/test1
passwd test1

How can I make this into a script i.e. so it asks if its for a vfx ftp or local ftp and also so it appends a file each time with the username and password so in case someone forgets the password for their ftp I can look at the file and tell them

many thanks,

rob


Moderator's Comments:
Shell script - craete user/password/home dir
Please wrap all code, files, input & output/errors in CODE tags.
It makes it far easier to read and preserves spacing for indenting or fixed-width data.

Last edited by rbatte1; 12-01-2016 at 06:53 AM.. Reason: Added CODE tags and corrected spellings/case/spacing
Sponsored Links
    #2  
Old Unix and Linux 12-01-2016
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 21 August 2017, 11:23 AM EDT
Location: Lancashire, UK
Posts: 3,208
Thanks: 1,369
Thanked 616 Times in 557 Posts
How will you want to decide which user account is assigned to each?

It should be relatively easy to achieve if you can clearly state the rules you want to apply.


Kind regards,
Robin
Sponsored Links
    #3  
Old Unix and Linux 12-01-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 20 July 2017, 5:24 AM EDT
Posts: 68
Thanks: 7
Thanked 5 Times in 4 Posts
cant the script ask if you want it to be a vfx ftp (mounted on nfs share) or a data ftp (mounted on local sdb1 drive)?

and then from there it will ask you to enter a username and password and from the above question the home dir will be what you selected ie data mount or vfx mount
    #4  
Old Unix and Linux 12-01-2016
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 21 August 2017, 11:23 AM EDT
Location: Lancashire, UK
Posts: 3,208
Thanks: 1,369
Thanked 616 Times in 557 Posts
It can indeed, I was assuming that you needed an automatic way to work it out. A few questions, if I may:-
  • What shell are you using? (the output from echo $SHELL would be fine)
  • What OS version are you using? (the output from uname -a would be very useful here)
  • What have you tried?
I ask the last question because it is better for us to know your style and adjust it rather than to impose a solution that you cannot understand or support.

Please post all code, files, input & output/errors in CODE tags. It makes it far easier to read.



Kind regards,
Robin
Sponsored Links
    #5  
Old Unix and Linux 12-01-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 20 July 2017, 5:24 AM EDT
Posts: 68
Thanks: 7
Thanked 5 Times in 4 Posts
getting close -



Code:
 
#!/bin/bash
echo "Enter UserName:"
read user
echo "Enter Password:"
read passwd
echo "$user:$passwd" >> /ftp.txt
useradd $user -b /mnt/data/
echo $user:$passwd | chpasswd

Sponsored Links
    #6  
Old Unix and Linux 12-02-2016
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 August 2017, 5:07 PM EDT
Location: Aachen, Germany
Posts: 11,185
Thanks: 287
Thanked 3,447 Times in 3,176 Posts
Yes, getting closer. Now: ask if "vfx ftp" or "data ftp" the same way.
What do you need ftp.txt for?
Sponsored Links
    #7  
Old Unix and Linux 12-02-2016
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 20 July 2017, 5:24 AM EDT
Posts: 68
Thanks: 7
Thanked 5 Times in 4 Posts
i have made it to a T now -


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
  useradd $user -s /sbin/nologin -b /mnt/data/
  touch /mnt/data/$user/files_will_get_deleted_older_than_14_days_old.txt
  echo $user:$passwd | chpasswd


Last edited by robertkwild; 12-02-2016 at 11:08 AM..
Sponsored Links
Closed

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 05:20 PM
how to change /export/home/user dir to /home /user in solaris kalyankalyan Solaris 2 05-31-2010 08:19 AM
unable to set user home dir some_one UNIX for Dummies Questions & Answers 14 04-30-2009 12:49 PM
need to restrict user to his home dir lidram Solaris 5 02-06-2008 10:03 AM
Modify user home dir kris_devis UNIX for Dummies Questions & Answers 4 04-17-2007 10:36 AM



All times are GMT -4. The time now is 07:44 PM.