View Full Version : Shell Scripting for Beginner
Just_Johnny
January 7th, 2009, 02:29
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
January 7th, 2009, 03:27
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
January 7th, 2009, 06:00
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
January 7th, 2009, 06:45
No you don't. What prevents you from simply copying all the home directories at once?
Just_Johnny
January 7th, 2009, 07:45
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
January 7th, 2009, 08:41
Use tar as shown above, cp will screw up any hard and softlinks.
lme@
January 7th, 2009, 11:57
Also, for keeping the permissions when using cp, you should use "cp -a".
estrabd
January 7th, 2009, 14:37
Use rsync, even if the location is local.
hedwards
January 7th, 2009, 19:43
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.
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
January 7th, 2009, 23:51
Or pax -r -w , which preserves more or less everything.
estrabd
January 13th, 2009, 15:15
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.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.