BackUp Home/Creating User from File


 
Thread Tools Search this Thread
# 1  
BackUp Home/Creating User from File

Hi!
I want to test something to learn Shell scripting better.

1)
How can I make a BackUp from all users and groups homedirectory?

I want to save that backup in an archiv.
Can I choose how to name the backUp archiv?

2)
Ok I want to make a file like csv, in this file are listed Users.
How can I read the file and then from the given info create as many users as they are inside the file?
I think I have to use a for loop...?

I just started yesterday with this, only now the loops and variables etc.
# 2  
Hi there!

1. You can use tar to create backup:
Code:
tar cvf home-backup.tar /home
## The below works on Linux or systems using GNU tar
tar cvzf home-backup.tar.gz /home

2. Try to understand this code on your own; you will be good to go
Code:
 sed -e 's/\,/\n/g' my_csv_file | while read name; do /usr/sbin/useradd "$name"; done;

Ohh forgot to tell you this: Happy Learning Smilie
# 3  
Code:
 -e 's/\,/\n/g'

What does the -e mean?

And if I create a user like this
Code:
useradd Name -p Passwort

I cant login with this user??
# 4  
-e switch is used to define one executable block of sed. You can simply ignore this in this case; however, it's very useful when you want to process a text multiple times with different regular expression. For an example:

Code:
sed -e 's/ /\n/g' -e '/^$/d' file

This replaces spaces with new line as well as deletes any empty line in file. You could do this with help of pipe and running sed (without -e switch) two times (takes more time than the above one):

Code:
sed 's/ /\n/g' file | sed '/^$/d'

You can use the -p switch to enter encrypted password for the new user. So, if you are simply entering the password with the -p switch, it's not going to work.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Switching from root to normal user takes me to user's home dir

Whenever i switch from root to another user, by doing su - user, it takes me to home directory of user. This is very annoying as i want to be in same dir to run different commands as root sometimes and sometimes as normal user. How to fix this? (1 Reply)
Discussion started by: syncmaster
1 Replies

2. UNIX for Advanced & Expert Users

Change user while creating spool file

Hi, I have a script which generate a HTML file from a unix user. Script spool the data extracted from DB using sqlplus. Problem is html file which gets generated is automatically assigned/owned with oracle user so my unix user just having read only permission to that HTML file. So I want... (1 Reply)
Discussion started by: sv0081493
1 Replies

3. Shell Programming and Scripting

Backup home directory

Hi Team, I want to write a script which will take a backup of my home directory. But will only backup the changes made in files not whole home directory. I want to upload that on server. I don't have any idea. please help me. (3 Replies)
Discussion started by: paragnehete
3 Replies

4. Shell Programming and Scripting

Need help in creating file restoration script from a backup script.

Hi all i am struggling in creating a restore of env files while doing applications clone. the first file i created for copying the important configurations file which is running perfect now for reverting the changes i mean when i am restoring these files to its original places i have to do... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

5. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

6. UNIX for Dummies Questions & Answers

Creating tar file for subdirs, excluding one and preserving user info

Hi All, I am not one of the super users / root for AIX 5.3 system. There is a filesystem Say /DIR1 and its has several subdirs in it say SUBDIR1, SUBDIR2, SUBDIR3. Can I create a tar file for all files under DIR1 and SUBDIR1, SUBDIR3. Excluding SIBDIR2? Also how can I preserve... (2 Replies)
Discussion started by: Hangman2
2 Replies

7. Solaris

How to backup /home directories?

I know that how to backup the home directories in sun sparc server. Firstly, umount the filesystem, Secondly, fsck the filesystem, Thirdly, ufsdump the filesystem. Anybody know how to type the full command line backup the /home directory? (1 Reply)
Discussion started by: kingsan
1 Replies

8. Solaris

Automate to backup the /home directory

Can anybody know that how to automate backup the /home directory using the own shell script especially crontab job. How to script the code in starting process of the sun sparc server in /etc/init.d/ Thank's a lot. (1 Reply)
Discussion started by: kingsan
1 Replies

9. Shell Programming and Scripting

Creating User Accounts from a list in file

I have a file that contains a list of names. I need a loop that creates user accounts to all the names in the list where username = names in file password = username Another question: how can i validate that a particular var is of 6 characters length I need an if statement that will... (8 Replies)
Discussion started by: Laila Saif
8 Replies

Featured Tech Videos