Gossamer Forum
Home : General : Perl Programming :

Zipping directory and emailing it

Quote Reply
Zipping directory and emailing it
Thinking of a way I can use a cronjob and script to zip an entire directory and email it to myself every night.

I'm new to Perl, so if anyone has a script like this, please post it here.

- coolj.


Quote Reply
Re: Zipping directory and emailing it In reply to
It is possible to do it to just certain files, but I'm not aware of a command that would work for a whole directory.

To do just one file you would use;

`gzip -c file.html > file.tar.gz`;

so to do a directory I suppose you could use something like;

$path = "/path/to/the/folder/you/want/";
`gzip -c $path > file.tar.gz`;

I doubt very much this will work, as I'm pretty sure there is either no command to ZIP folders, or it is done another way Wink

All I know is that the code I provided first works on a single file.

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Zipping directory and emailing it In reply to
I'm not sure if this is the best way but try.....
Code:
opendir(DIR, "/path/to/dir") || die "Can't open /path/to/dir : $!";
@files = grep { !/^\.+$/ } readdir(DIR);
closedir(DIR);
Code:
my $list = join(" ", @files);

Code:
my $result = `tar cvf - $list | gzip > file.tar.gz`;
I'm not sure if that will work but it was just a quick idea.

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Zipping directory and emailing it In reply to
Take a look here:

http://lithos.gat.com/docview/tar_gzip.html

May help too...

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/