Feed a directory listing to a script
Feed a directory listing to a script
am 08.08.2005 02:24:20 von Shabam
I have a command script that backs up a user account. This involves moving
files from different directories into an archive.
Now, I need that script to back up all user accounts on the system, by going
through the directory structure and running the backup script on each one.
Can someone show me how this can be done? I'm not a perl programmer and
have only dabbled a bit in it.
My directory structure is like this:
/Users/0/
/Users/1/
/Users/2/
/Users/3/
.... so on...
User account names reside in those folders, so user jason would be in
"Users/j/jason".
Please don't tell me to just tar/gz the /Users/ directory. That will not
work for this because it will be greater than 4GBs, and it won't allow me to
restore accounts individually.
Thanks for any help.
Re: Feed a directory listing to a script
am 08.08.2005 11:51:05 von anno4000
Shabam wrote in comp.lang.perl.misc:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
>
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
So what have you tried so far, and how does it fail?
> Please don't tell me to just tar/gz the /Users/ directory. That will not
> work for this because it will be greater than 4GBs,
So?
> and it won't allow me to
> restore accounts individually.
Ah, but it does. The problem is, you'd have to read through the entire
tar file, but you can restore any selection of files you want.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Re: Feed a directory listing to a script
am 08.08.2005 11:51:05 von anno4000
Shabam wrote in comp.lang.perl.misc:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
>
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
So what have you tried so far, and how does it fail?
> Please don't tell me to just tar/gz the /Users/ directory. That will not
> work for this because it will be greater than 4GBs,
So?
> and it won't allow me to
> restore accounts individually.
Ah, but it does. The problem is, you'd have to read through the entire
tar file, but you can restore any selection of files you want.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Re: Feed a directory listing to a script
am 08.08.2005 22:00:54 von Joe Smith
Shabam wrote:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
Here is a hint:
perl -le 'while(($user,$pw,$uid,$gid,$q,$c,$name,$home)=getpwent){pri nt
"~$user = $home for $name" if $uid > 100}'
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
OK, here's another hint. Replace the print() part with this:
system "tar cvf $user.tar $home >$user.dir 2>>error.log";
-Joe
P.S. Next time, do not include comp.lang.perl; it has been replaced
by the comp.lang.perl.misc newsgroup.
Re: Feed a directory listing to a script
am 08.08.2005 22:00:54 von Joe Smith
Shabam wrote:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
Here is a hint:
perl -le 'while(($user,$pw,$uid,$gid,$q,$c,$name,$home)=getpwent){pri nt
"~$user = $home for $name" if $uid > 100}'
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
OK, here's another hint. Replace the print() part with this:
system "tar cvf $user.tar $home >$user.dir 2>>error.log";
-Joe
P.S. Next time, do not include comp.lang.perl; it has been replaced
by the comp.lang.perl.misc newsgroup.
Re: Feed a directory listing to a script
am 09.08.2005 05:57:44 von Shabam
> > Please don't tell me to just tar/gz the /Users/ directory. That will
not
> > work for this because it will be greater than 4GBs,
>
> So?
You don't get it do you?
Re: Feed a directory listing to a script
am 09.08.2005 05:57:44 von Shabam
> > Please don't tell me to just tar/gz the /Users/ directory. That will
not
> > work for this because it will be greater than 4GBs,
>
> So?
You don't get it do you?
Re: Feed a directory listing to a script
am 09.08.2005 22:00:34 von anno4000
[newsgroups trimmed]
Shabam wrote in comp.lang.perl.misc:
> > > Please don't tell me to just tar/gz the /Users/ directory. That will
> not
> > > work for this because it will be greater than 4GBs,
> >
> > So?
>
> You don't get it do you?
What don't I get? Some file systems have a size limit (usually at 2 GB,
not 4), but others don't. I have built and used backups that were much
larger.
As for your original question, you visit each home directory and run your
backup script on it with an individual output file. That's what thousands
of sysadmins are doing. What's the problem?
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Re: Feed a directory listing to a script
am 09.08.2005 22:37:43 von Matthew King
"Shabam" writes:
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
You don't even need to use perl, you can do this directly in bash:
for k in /Users/*/*/; do run_backup_script "$k"; done
The perl equivalent would look similar but IIRC be a bit mor involved.
Matthew
--
I must take issue with the term "a mere child," for it has been my
invariable experience that the company of a mere child is infinitely
preferable to that of a mere adult.
-- Fran Lebowitz
Re: Feed a directory listing to a script
am 09.08.2005 22:37:43 von Matthew King
"Shabam" writes:
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
You don't even need to use perl, you can do this directly in bash:
for k in /Users/*/*/; do run_backup_script "$k"; done
The perl equivalent would look similar but IIRC be a bit mor involved.
Matthew
--
I must take issue with the term "a mere child," for it has been my
invariable experience that the company of a mere child is infinitely
preferable to that of a mere adult.
-- Fran Lebowitz
Re: Feed a directory listing to a script
am 10.08.2005 08:42:24 von Joe Smith
Shabam wrote:
>>> Please don't tell me to just tar/gz the /Users/ directory.
>>> That will not work for this because it will be greater than 4GBs,
>>
>>So?
>
> You don't get it do you?
Get what? Modern versions of tar can create archive files of
greater than 2 or 4 gigabytes.
linux% ls -l 5gigabyte.zip
-rw-r--r-- 1 jms jms 5751592946 May 3 19:37 5gigabyte.zip
linux% tar cf 5gb.tar 2005-03-01.zip
linux% ls -l 5gb.tar
-rw-r--r-- 1 jms jms 5751603200 Aug 9 22:30 5gb.tar
So why do you say 4GB wont work?
-Joe
Re: Feed a directory listing to a script
am 10.08.2005 08:42:24 von Joe Smith
Shabam wrote:
>>> Please don't tell me to just tar/gz the /Users/ directory.
>>> That will not work for this because it will be greater than 4GBs,
>>
>>So?
>
> You don't get it do you?
Get what? Modern versions of tar can create archive files of
greater than 2 or 4 gigabytes.
linux% ls -l 5gigabyte.zip
-rw-r--r-- 1 jms jms 5751592946 May 3 19:37 5gigabyte.zip
linux% tar cf 5gb.tar 2005-03-01.zip
linux% ls -l 5gb.tar
-rw-r--r-- 1 jms jms 5751603200 Aug 9 22:30 5gb.tar
So why do you say 4GB wont work?
-Joe
Re: Feed a directory listing to a script
am 10.08.2005 20:24:35 von Justin C
On 2005-08-10, Joe Smith wrote:
> Shabam wrote:
>>>> Please don't tell me to just tar/gz the /Users/ directory.
>>>> That will not work for this because it will be greater than 4GBs,
>>>
>>>So?
>>
>> You don't get it do you?
>
> Get what? Modern versions of tar can create archive files of
> greater than 2 or 4 gigabytes.
Maybe the OP has a DAT drive that doesn't support tapes bigger than
2/4GB?
Justin.
--
Justin C, by the sea.
Re: Feed a directory listing to a script
am 10.08.2005 20:24:35 von Justin C
On 2005-08-10, Joe Smith wrote:
> Shabam wrote:
>>>> Please don't tell me to just tar/gz the /Users/ directory.
>>>> That will not work for this because it will be greater than 4GBs,
>>>
>>>So?
>>
>> You don't get it do you?
>
> Get what? Modern versions of tar can create archive files of
> greater than 2 or 4 gigabytes.
Maybe the OP has a DAT drive that doesn't support tapes bigger than
2/4GB?
Justin.
--
Justin C, by the sea.
Re: Feed a directory listing to a script
am 23.08.2005 11:39:14 von sunjingwei
good
how do i know that ?
and this is a test..
--
?????????
?!
?????????????????
??????????????sunjingwei@baidu.com
???????????????
"Joe Smith" ???? news:CrOdneBuO7hEPGTfRVn-2A@comcast.com...
> Shabam wrote:
> >>> Please don't tell me to just tar/gz the /Users/ directory.
> >>> That will not work for this because it will be greater than 4GBs,
> >>
> >>So?
> >
> > You don't get it do you?
>
> Get what? Modern versions of tar can create archive files of
> greater than 2 or 4 gigabytes.
>
> linux% ls -l 5gigabyte.zip
> -rw-r--r-- 1 jms jms 5751592946 May 3 19:37 5gigabyte.zip
> linux% tar cf 5gb.tar 2005-03-01.zip
> linux% ls -l 5gb.tar
> -rw-r--r-- 1 jms jms 5751603200 Aug 9 22:30 5gb.tar
>
> So why do you say 4GB wont work?
>
> -Joe
Re: Feed a directory listing to a script
am 23.08.2005 11:39:14 von sunjingwei
good
how do i know that ?
and this is a test..
--
?????????
?!
?????????????????
??????????????sunjingwei@baidu.com
???????????????
"Joe Smith" ???? news:CrOdneBuO7hEPGTfRVn-2A@comcast.com...
> Shabam wrote:
> >>> Please don't tell me to just tar/gz the /Users/ directory.
> >>> That will not work for this because it will be greater than 4GBs,
> >>
> >>So?
> >
> > You don't get it do you?
>
> Get what? Modern versions of tar can create archive files of
> greater than 2 or 4 gigabytes.
>
> linux% ls -l 5gigabyte.zip
> -rw-r--r-- 1 jms jms 5751592946 May 3 19:37 5gigabyte.zip
> linux% tar cf 5gb.tar 2005-03-01.zip
> linux% ls -l 5gb.tar
> -rw-r--r-- 1 jms jms 5751603200 Aug 9 22:30 5gb.tar
>
> So why do you say 4GB wont work?
>
> -Joe
Re: Feed a directory listing to a script
am 25.09.2005 14:37:52 von Tim X
"Shabam" writes:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
>
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
>
> Please don't tell me to just tar/gz the /Users/ directory. That will not
> work for this because it will be greater than 4GBs, and it won't allow me to
> restore accounts individually.
>
Firstly, if your not a perl programmer, why do you plan to use perl
for this task? This could easily be done with just a bash script.
Secondly, your statement about not being able to extract individual
account data from a single tar file is incorrect. You can extract
individual files or groups of files from a tar archive.
The basic building blocks for your script are two loops. The outer
loop goes through the outer list of directories and for each of those,
the inner loop goes through the user accounts in each directory and
processes them in whatever way you want.
The perl functions you probably want are opendir and readdir. Try
perldoc -f readdir, but to be honest, if your not a perl programmer,
save yourself time and just use bash (unless you want to learn perl).
Tim
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!
Re: Feed a directory listing to a script
am 25.09.2005 14:37:52 von Tim X
"Shabam" writes:
> I have a command script that backs up a user account. This involves moving
> files from different directories into an archive.
>
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
> Can someone show me how this can be done? I'm not a perl programmer and
> have only dabbled a bit in it.
>
> My directory structure is like this:
>
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
>
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
>
> Please don't tell me to just tar/gz the /Users/ directory. That will not
> work for this because it will be greater than 4GBs, and it won't allow me to
> restore accounts individually.
>
Firstly, if your not a perl programmer, why do you plan to use perl
for this task? This could easily be done with just a bash script.
Secondly, your statement about not being able to extract individual
account data from a single tar file is incorrect. You can extract
individual files or groups of files from a tar archive.
The basic building blocks for your script are two loops. The outer
loop goes through the outer list of directories and for each of those,
the inner loop goes through the user accounts in each directory and
processes them in whatever way you want.
The perl functions you probably want are opendir and readdir. Try
perldoc -f readdir, but to be honest, if your not a perl programmer,
save yourself time and just use bash (unless you want to learn perl).
Tim
--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!