473,797 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Feed a directory listing to a script

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.
Aug 8 '05 #1
8 6672
Shabam <ch*****@yoma ma-nospam.com> 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.c om, 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.
Aug 8 '05 #2
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.
Aug 8 '05 #3
> > 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?
Aug 9 '05 #4
"Shabam" <ch*****@yoma ma-nospam.com> 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_scri pt "$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
Aug 9 '05 #5
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
Aug 10 '05 #6
On 2005-08-10, Joe Smith <jo*@inwap.co m> 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.
Aug 10 '05 #7
good
how do i know that ?
and this is a test..

--
?????????
?!
??????????????? ??
??************* *********@baidu .com
???????????????
"Joe Smith" <jo*@inwap.co m> ???? news:Cr******** ************@co mcast.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

Aug 23 '05 #8
"Shabam" <ch*****@yoma ma-nospam.com> 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!
Sep 25 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2530
by: Kim Jensen | last post by:
I'd like to make a directory listing where instead of the entire filename I need it to show the filename minus the extention and get the value of charname= in the file itself. I've been told that I had to turn the directory listing into an array and then use "foreach (array as item)" to go through and open each file but I've tried several different approaches and I just can't get it to work. I've been able to make it list the directory...
2
8930
by: Matt | last post by:
Hello, I am writing a script that opens needs to get a listing of files in a directory, print that listing to a file and use that file as a quasi ftp control file. My problem is that when I print the filenames found via the readdir I also get the . and .. (current directory and parent directory) written in the ftp control file which causes my script to stop since you can't ftp . nor .. Here's my logic ....
2
17642
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan all the files in the directory and select the one with the highest week number then display in the browser window. A brief search hasn't revealed any code to do this so I just want to know if it is possible and what the function names are that...
19
3317
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing = os.listdir(directory)
8
6954
by: dougawells | last post by:
Hi - I'm hoping for help with the auto-generation of a hyperlinked listing of all files in a directory. The server I use does not auto-generate this. So, when someone comes to this directory and thus opens index.htm, I want that file to show a listing of all files in the directory with hyperlinks to them. Thanks for the help, Doug
1
1396
by: kernelsanders | last post by:
Hi, I'm still new to perl and have to figure out how to feed a complete directory listing as parameters into another perl script. I've looked around online and found command examples that use words like "cat" "find" "name".....where can I go to learn more about using these and any other command line arguments in the Windows environment? So far, every time I google the combination of cat and perl I find that cat is a Unix variable. Thanks.
4
3251
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir variable set to this: --- $dir = getcwd() . "\\" . $nav; --- but for some reason the script does not actually display the contents of the directory if you change from the directory the script is located in. Here is my code if someone is willing...
1
5674
by: Steve | last post by:
My site is hosted on a Godaddy reseller site. Godaddy only allows the use of Curl to access remote sites. What is the method for listing a directory after connecting to the site with Curl? I've already tested my code for connecting but how do I list whats in the directory. The purpose is to compare the list to the filenames in my database.
1
2176
by: mocolvin | last post by:
I am looking for a Perl script that will do a cleaner job of listing the contents of a directory than what Apache does on its own. I would like the script to create a list of links to enable files in a given directory to be downloaded. The PHP utility that I had been using for that purpose had a security hole that was exploited by hackers.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.