# Shell Scripting for Beginner



## Just_Johnny (Jan 7, 2009)

hello, 

I'm trying to copy all of my home directories to a central location. (daily)

This could be done with a simple cron job. (i know)

If a new home directory is created I would like to copy it's contents without editing the cron job.  

What would be the best way to do this? 

--


----------



## hedwards (Jan 7, 2009)

Do you want all those directories in the same new directory?

You can just do something like:

```
tar cvpf - /usr/home | tar xpf - -C /path/to/other/home
```


----------



## Just_Johnny (Jan 7, 2009)

*forget the first post*

Sorry, I'm kind of new to the Unix enviroment. I'm still thinking in 2D and not FreeBSD.  

Do I have to learn perl to be a good systems administrator?


----------



## kamikaze (Jan 7, 2009)

No you don't. What prevents you from simply copying all the home directories at once?


----------



## Just_Johnny (Jan 7, 2009)

kamikaze said:
			
		

> No you don't. What prevents you from simply copying all the home directories at once?



I guess nothing.

cp -r /usr/home /somewhere

right?


----------



## SirDice (Jan 7, 2009)

Use tar as shown above, cp will screw up any hard and softlinks.


----------



## lme@ (Jan 7, 2009)

Also, for keeping the permissions when using cp, you should use "cp -a".


----------



## estrabd (Jan 7, 2009)

Use rsync, even if the location is local.


----------



## hedwards (Jan 7, 2009)

Just_Johnny said:
			
		

> Sorry, I'm kind of new to the Unix enviroment. I'm still thinking in 2D and not FreeBSD.
> 
> Do I have to learn perl to be a good systems administrator?


You really don't have to, but it depends upon what you're needing/wanting to do. It's not going to hurt if you do learn it, but probably, sed, grep, xargs and awk, would make a much bigger difference for most people. And there again you don't necessarily need to get very deep in order to get a lot out of it.


			
				estrabd said:
			
		

> Use rsync, even if the location is local.


I tend to use rdiff-backup for that sort of thing, seems to work fairly well.


----------



## Djn (Jan 7, 2009)

Or pax -r -w , which preserves more or less everything.


----------



## estrabd (Jan 13, 2009)

hedwards said:
			
		

> You really don't have to, but it depends upon what you're needing/wanting to do. It's not going to hurt if you do learn it, but probably, sed, grep, xargs and awk, would make a much bigger difference for most people. And there again you don't necessarily need to get very deep in order to get a lot out of it.



I agree that one doesn't need to learn Perl to be a good sysadmin, but it is a useful language to know once you've gotten familiar with the set of tools at your disposal and wish to start building tools that are not appropriate for shell scripting and the standard utilities.


----------

