LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2012, 01:38 PM   #1
shshivam
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Rep: Reputation: Disabled
Need help with creating a new user and backing up a partition


I have to do the following in a shell script:

1. Create a new user. Ask for the username, full name, and password. Then use this information to create a new user in the system.

2. Backup an entire partition. Ask for the partition name (directory associated with that partition) and the target location to save the backup file. Then make a copy of that directory in the desired location as a single archive file, with current date as the file extension.

This is what i have so far:
Code:
read input
     case $input in
        1)
          echo "Enter Username:"
          read username
          echo "Enter Full Name:"
          read name
          echo "Enter password:"
          read pass
          sudo useradd -m $user
          sudo passwd $user
          echo "User added"
          ;;
        2)
          echo "Enter partition name:"
          read partName
          echo "Enter target location:"
          read location
          dump 0u $location $partName
          echo "Done"
          ;;
For the first one, it creates a user but Im not able to log in to it. Also is there a way to assign the user the password the user enters?
I have no clue on how to do the second part.
 
Old 10-31-2012, 03:19 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by shshivam View Post
is there a way to assign the user the password the user enters?
See 'man useradd' ("-p") or 'man chpasswd'? There's more options from using 'openssl passwd' to Perl to probably distro-specific ones.
*BTW changing passwords this way completely bypasses any password strength checking if the machine or service uses PAM. It really should be a temporary password that must be changed on first login.
**Do check the account name doesn't exist and deny everything that could generate errors.


Quote:
Originally Posted by shshivam View Post
I have no clue on how to do the second part.
Making a backup of user directories and files with the current date as file extension isn't difficult. But backing up an entire partition doesn't make sense unless each user has its own home partition (or the user is supposed to know the partition name as you're requiesting input?). W/o error checking and asserting users have a directory in /home/ as well as local mail spool, crontab etc:
Code:
echo "Current user name: "; read CURNAME; [ -d "/home/${CURNAME}" ] && BACKUPFILES="/home/${CURNAME}"
BACKUPFILES="${BACKUPFILES} $(find /var -maxdepth 10 -type f -user $CURNAME 2>/dev/null)"
tar -cf "/path/to/$CURNAME-$(date +'%Y%m%d').tar" "${BACKUPFILES}"
 
1 members found this post helpful.
Old 10-31-2012, 04:33 PM   #3
shshivam
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post

Making a backup of user directories and files with the current date as file extension isn't difficult. But backing up an entire partition doesn't make sense unless each user has its own home partition (or the user is supposed to know the partition name as you're requiesting input?). W/o error checking and asserting users have a directory in /home/ as well as local mail spool, crontab etc:
Code:
echo "Current user name: "; read CURNAME; [ -d "/home/${CURNAME}" ] && BACKUPFILES="/home/${CURNAME}"
BACKUPFILES="${BACKUPFILES} $(find /var -maxdepth 10 -type f -user $CURNAME 2>/dev/null)"
tar -cf "/path/to/$CURNAME-$(date +'%Y%m%d').tar" "${BACKUPFILES}"
Yeah the user is supposed to know the partition name,the desired location of the backup file and the instructions require me to back up an entire partition. This has nothing to do with the users, or they having directories/partition's of their own This is not supposed to be a practical script, so I dont need to worry about errors.

Also, while creating a new user, how do I add the name of the user to the account?

Last edited by shshivam; 10-31-2012 at 04:35 PM.
 
Old 10-31-2012, 06:23 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by shshivam View Post
This is not supposed to be a practical script, so I dont need to worry about errors.
Famous last words ;-p


Quote:
Originally Posted by shshivam View Post
while creating a new user, how do I add the name of the user to the account?
'man useradd', look for "comment field".
 
Old 10-31-2012, 07:03 PM   #5
shshivam
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
So how do I backup an entire partition and have the current date as the file extension?
 
Old 10-31-2012, 07:27 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
In what way does a mount point differ from any other directory for backup purposes?
 
Old 10-31-2012, 07:36 PM   #7
shshivam
LQ Newbie
 
Registered: Oct 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Is there a way to do it with the "dump" command rather than "tar"?
Also I want the user to be able to specify a desired location where the backup will be made.

Would this work?
Code:
echo “Enter Partition address "; read partAddress; echo “Enter destination address:”; read reqAddress
tar -cf "$reqAddress-$(date +'%Y%m%d').tar" "${partAddress}"

Last edited by shshivam; 10-31-2012 at 08:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Backing up user accounts and groups. thekillerbean Linux - Newbie 1 12-25-2005 08:44 AM
Backing up my slack partition - what app to use? Garibaldi3489 Linux - Newbie 12 06-08-2005 07:00 PM
backing up a partition nkoplm Linux - General 2 05-26-2005 11:53 PM
backing up user profiles bunnyknight13 Linux - Newbie 2 08-29-2004 09:05 PM
Backing up entire Linux System (partition) podollb Linux - Software 4 10-14-2003 10:01 PM


All times are GMT -5. The time now is 03:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration