Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a powershell script I want to use to monitor the size of a file (at a certain interval) and send me an email alert if the file reaches a certain size. However, after it discovers that the file has reached that size, the powershell script exits.

Presently the script operates in a for loop, with the file-size check happening first, and if it hasn't passed the maximum size, it will wait for the given time-interval and check the file size again. But I'm thinking about changing this for loop to a do...while so that it waits the interval of time first and then checks the size of the file.

But the script will still exit when the email is sent.

Is there any way to ensure that the script will be re-run when it exits after the email is sent?

I read that there are processes in database systems that monitor other processes to make sure that they are running, and if they are not, the watching process re-spawns the process that died.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

It sounds like your email sending function is outside the loop, and is followed by either an exit statement or the end of the script.

Can you just put the email sending function within the loop? You'll probably need to add a counter that will establish a time or repetition-based hold so that it doesn't immediately get in a loop of re-emailing you, but that's not too hard.

If you do that, then the script won't exit the loop at all: it'll send and email and go back to checking for the file.

share|improve this answer
    
The email sending function is actually a separate commandline program called blat. –  leeand00 Aug 16 '12 at 15:44
    
I guess it doesn't matter if it's on the command line from powershell? –  leeand00 Aug 16 '12 at 15:51
1  
Why use blat when powershell can do what you want? Integrate e-mail code within the script and reduce the dependency for another file. –  DKNUCKLES Aug 16 '12 at 16:09
    
Okay I guess I'll try that. –  leeand00 Aug 17 '12 at 12:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.