For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2007 > Newb needs help with perl script in linux









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newb needs help with perl script in linux
Romz169@gmail.com

2007-01-06, 7:04 pm

i have a script that does backups of a system. It names the files with
that date on it.

DATE=% (/bin/date +%m-%d-%Y)

tar zcvf /data /backup/%DATE.backup.tgz


Now that works fine, but what i need to do now is put some logic into
it.

if (du -h /backup/"file for yesterday" > "10G")
then
rm /backup/"file for 3 days ago"
fi

Basicly i dont know how to write it at all and i need help. I want it
to look at the file from yesterday and see if it is larger then 10 gig.
If it is i want it to delete the backup from 3 days ago.

Thanks for the help

Jim Gibson

2007-01-06, 7:04 pm

In article <1167857568.664368.28160@s34g2000cwa.googlegroups.com>,
<"Romz169@gmail.com"> wrote:

> i have a script that does backups of a system. It names the files with
> that date on it.
>
> DATE=% (/bin/date +%m-%d-%Y)
>
> tar zcvf /data /backup/%DATE.backup.tgz
>
>
> Now that works fine, but what i need to do now is put some logic into
> it.
>
> if (du -h /backup/"file for yesterday" > "10G")
> then
> rm /backup/"file for 3 days ago"
> fi
>
> Basicly i dont know how to write it at all and i need help. I want it
> to look at the file from yesterday and see if it is larger then 10 gig.
> If it is i want it to delete the backup from 3 days ago.


You are asking your question in a Perl group, but it doesn't appear as
if you are using Perl. Are you asking how to do this job in Perl? I
would consider using the file test operator -s to get the size of the
file, the -M file test operator to get the age of the file in days, and
the File::Find module to find all relevant files.

If you are using a shell program, the find command can look for files
by size (-size) and age (-mtime). Unfortunately, the -size test looks
for a specific size, not a size-greater-than.

What language do you want to use?

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Romz169@gmail.com

2007-01-06, 7:04 pm

good point. i never looked at it that closely, I did not write the
script and the guy that did is a perl programer but it turns out it is
written in as a shell script. I am not to good with programming at all.
The person who did this work left and i happen to be the most
knowledgeable in linux so i have to support our linux boxes. The script
indicated here requires constant manintance due to disk space. The
backups are very large and take up alot of space. Im just trying to put
some logic in the script so i dont have to do it manualy.

I have posted it in a different group now, but if you have any
information that would help id apprecate it.

Jim Gibson wrote:
> In article <1167857568.664368.28160@s34g2000cwa.googlegroups.com>,
> <"Romz169@gmail.com"> wrote:
>
>
> You are asking your question in a Perl group, but it doesn't appear as
> if you are using Perl. Are you asking how to do this job in Perl? I
> would consider using the file test operator -s to get the size of the
> file, the -M file test operator to get the age of the file in days, and
> the File::Find module to find all relevant files.
>
> If you are using a shell program, the find command can look for files
> by size (-size) and age (-mtime). Unfortunately, the -size test looks
> for a specific size, not a size-greater-than.
>
> What language do you want to use?
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com


Joe Smith

2007-01-06, 7:04 pm

Jim Gibson wrote:

> If you are using a shell program, the find command can look for files
> by size (-size) and age (-mtime). Unfortunately, the -size test looks
> for a specific size, not a size-greater-than.


Not true.

find . -size -10G -print > less-than-10.0000G
find . -size 10G -print > 10.0000G-to-10.9999G
find . -size +10G -print > more-than-10.9999G
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com