[plug] need a little help with our old friend Linux....
Matt Kemner
zombie at networx.net.au
Fri Mar 5 09:23:04 WST 1999
On Thu, 4 Mar 1999, Pavel Franger wrote:
> I'm a student and trying to battle the average problems which a normal
^^^^^^^
> users should be able to do with Linux.
> If anyone can help me out it would be greatly thanked....
These scripts you are trying to write, don't have anything to do with your
current curriculum does it?
Sorry if I'm on the wrong track here, but these questions sound very much
like a "first project" in a unix shell course, in which case I really
don't think you should be asking for help here.
On the other hand if I'm wrong, please let me know and I'll give you a
hand with the scripts
> 1.By using find,I want to write a script that copies all .c files that
> have not been changed for 3 days from my home account to a directory
> called oldprog in my home account.I want to use the -ok switch instead
> of the -exec switch so that the user is prompted before each file is
> copied.
The thing that raised my suspicion is the fact you specify what utilities
you wish to use (in this case find) when there are a number of
alternatives available to you.
Eg. you could do the above very easily in perl rather than find:
#!/usr/bin/perl
$home=$ENV{HOME};
$now=time;
$threedays=(60 * 60* 24 * 3);
$threedaysago=($now-$threedays);
@FILES = glob "*\.c";
FILE:foreach $file (@FILES) {
@stat=(stat($file));
$mtime=$stat[9];
if ($mtime <= $threedaysago) {
print "About to move $file to oldprog, proceed? ";
$verify=<STDIN>;
chomp $verify;
$vrfy=substr($verify,0,1);
print "VRFY=$vrfy.\n";
next FILE unless $vrfy eq 'y' or $vrfy eq 'Y';
rename ("$file", "$home/oldprog/$file");
}
}
Problem solved.
Unless, of course, the question came from a school/uni exercise and you
had to use find, in which case the man page is your best friend. :)
On the other hand, if you can show us what you have come up with so far
and are stuck on one minor detail, I'm sure any of us would be more than
willing to give you a pointer.
- Matt
P.S. sorry for the preaching nature of this email, but I feel you really
should learn to do things like this for yourself, otherwise what's the
point of doing the course?
P.P.S. again, if I'm on a totally wrong track, I'm sorry. I blame my
overworked paranoia on the fact I'm a SysAdmin. :)
More information about the plug
mailing list