CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Running a script in DOS/Win at periodic intervals

 



brownjenkin
stranger

May 10, 2001, 1:55 PM

Post #1 of 7 (1166 views)
Running a script in DOS/Win at periodic intervals Can't Post

Okay, so now I know how to get the amount of free space on a drive and I finished my script, but I need to be able to periodically get this info, ie: run that part of my script every 10 or 15 minutes...or whatever amount of time.

Currently, this part of my script looks like this:

$freec = (Win32::DriveInfo::DriveSpace('c:\\'))[6];
print "free bytes on (C:/): $freec\n";

until ($freec < 1000000000) {
$freec = (Win32::DriveInfo::DriveSpace('c:\\'))[6];
}

When the amount of free space on C:\ is reduced to less than 1,000,000,000 Bytes (1GB), the rest of my script kicks in, which is what I want. Here's the big but though: the script keeps running until this happens which isn't very efficient.

How can I get this part of my script to check free space on C:\ periodically? Can this be done?

BTW, the script worked as is...here's how I tested it:

First of all, I only have about 2 GB free on my C:\ drive - this helps. So I ran the script. While it was running (ie continually checking C:\) I made a copy of a 500 MB file three times on other directories on C:\ ..once Windows figured that the three copies would leave it with whatever amount of space, the script found that C:\ had less than 1 GB free and the rest of the script kicked in.

Incidentally, the rest of the script moves files over to another drive when C:\ gets too small...

Anyway, as always, any input is highly appreciated.

Pete



freddo
User

May 10, 2001, 2:14 PM

Post #2 of 7 (1161 views)
Re: Running a script in DOS/Win at periodic intervals [In reply to] Can't Post

Hi Pete,

You might want to use the sleep function in something like:

Code
... 
loop:
movefiles() if (Win32::DriveInfo::DriveSpace('c:\\'))[6] < 1_000_000_000);
sleep 600; # wait 10 minutes
goto loop;

In win98 i know there's a scheduler (look for it in the explorer) and you can tell him to run you script when you wish. I suspect that the tasks are written in the registry, and you could try to search for them. Else i'll have access to a win98 machine in 72 hours max, and i'll tell you how you can do that.

until then, i hope it helps;
freddo;

;---
Real programmers don't eat cache.


freddo
User

May 10, 2001, 2:18 PM

Post #3 of 7 (1160 views)
Re: Running a script in DOS/Win at periodic intervals [In reply to] Can't Post

Btw, if you are using ActiveState perl, consider using .wsf files instead of .pl, it can look more professional and be really great, you can see examples in C:\Perl\eg\Windows Script Host (if you installed perl in c:\perl).

;---
Real programmers don't eat cache.


brownjenkin
stranger

May 11, 2001, 9:05 AM

Post #4 of 7 (1150 views)
Re: Running a script in DOS/Win at periodic intervals [In reply to] Can't Post

Thanks again, Freddo!

I used this code:

while (1)
{
print "sleeping...next check in 15 minutes.\n";
sleep (60*15); # wait 15 minutes
$freec = (Win32::DriveInfo::DriveSpace('c:\\'))[6];
print "free bytes on (C:/): $freec\n";
if ($freec > 1000000000)
{

}
else
{
&movewaves;
}

}

...and it works perfectly!

Pete



rjoseph
Novice

May 11, 2001, 2:10 PM

Post #5 of 7 (1145 views)
Re: Running a script in DOS/Win at periodic interv [In reply to] Can't Post

If I might ask, what exaclty do you use this script for? It is actually a pretty interesting idea that you have here, and I was just wondering what you are using that idea for!!

Thanks!

r j o s e p h
"Violence is a last resort of the incompetent" - Foundation


freddo
User

May 12, 2001, 6:11 AM

Post #6 of 7 (1141 views)
Re: Running a script in DOS/Win at periodic intervals [In reply to] Can't Post

Happy to have helped you Pete,

I was wrong about the task scheduler, it doesnt use the registry, it puts some strange .job files in c:\windows\tasks\ anyway, it could be the other way of making your script running on a regular basis.

bye bye
freddo

;---
Real programmers don't eat cache.


brownjenkin
stranger

May 14, 2001, 6:28 AM

Post #7 of 7 (1133 views)
Re: Running a script in DOS/Win at periodic interv [In reply to] Can't Post

Hello...

Since you asked so nicely, I'll tell you what the script is for and ask another question that might help me finish it for good:

The script I'm working on is part of a CD-ripping operation where the computer has a 100 CD Jukebox to continually rip and FTP to a big array of drives. My script is a failsafe in that it checks the C:\ drive for free space - if C:\ gets below 1 GB, there's probably been an FTP problem, so it reads .wav files out of a directory and moves them to D:\ ...once on D:\ it checks to make sure the files are the same size, then deletes the old file on C:\, thus freeing space for more ripping.

My problem now is that the program is still always on, though it sleeps most of the time, thus making my call to report the "how long since modified" (-M) of a file pretty much moot. As I understand it, Perl references this number to the time when the program started, so now I have to figure out how to report the age of a file outside of the script.

Is there any way to run an external perl script and read the info obtained from that into my main script? Actually, I know how I could swap the data, but how would I get my main script to launch another script?

Any info will help me lots!
Pete

don't panic...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives