nolongthin Posted April 17, 2012 Author Posted April 17, 2012 Am writing a program that its meant for a pet clinic management system its an assignment, once the detailed are entered its saves to a log file and then it sends the log to the email and the program need to run continuously, and the logs need to be sent continuously
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 @kylomas, how do i tell it to wait for some minutes and then send it (continuously)
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) Okay, forgive me for being suspicious. I haven't used _InetSmtpMail, so I'm not entirely sure what the best solution to this would be. It seems there are three processes all trying to access the file at the same time. A simple solution would be to create a copy of the file and rename it. You could also include a timestamp in the name. Send the renamed copy. That way you don't need to worry about other processes accessing the main log file. Check out FileCopy in the help file. Edited April 17, 2012 by czardas operator64 ArrayWorkshop
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 How do i automatically create a copy of the file.
kylomas Posted April 17, 2012 Posted April 17, 2012 nolongthin, You do NOT want to send an email "continuously". I need to no more about what you are doing to propose a reasonable solution. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) Create a file called Current.log and a folder called Updates in the same directory as the script. Then edit the Currrent log file with notepad. When you run the code below a copy is created even though the file is being used by, and edited in, notepad (don't forget to save). I tested it and it works.FileCopy ( "Current.log", "Updates/updated.log", 1)oops forgot to include code. I'm still not entirely sure if this will work as it is. I need to think a little while.Okay the following method should also work with your email script. The new file created is the one you need to send.$filePath = "Updates/" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".log" FileCopy ( "Current.log", $filePath)One more change added so you can create a new file every second if you wish (you only need an update every half hour). Please realise that you will need to clear out the folder with all these updated log files at some point. That's also something to think about. I think this method is acceptable because you don't want to have to exit the main program used by the clinic in order to send an email. Edited April 25, 2012 by czardas operator64 ArrayWorkshop
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 @ czardasi implemented the file copy (thanks) now when i use this it send the file in 30 minute but continues, i want it to send the file every 30 minutes then wait for another 30minutes
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 $iMinutes = 1 $hTimer = TimerInit() While 1 If TimerDiff($hTimer) > ($iMinutes * 60000) Then _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) Wend
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) It took me a while to find the for the code you are using. Please post links to any code you find in the Example Forum if you are using it.Combining water's code with my own:AdlibRegister("SendAttachment", 30 * 60 * 1000) ; Call this function every half hour. While 1 Sleep(1000) ; reduces cpu usage. WEnd Func SendAttachment() ; You need to create the file inside this function - which is called every half hour. ; Also all the other required variables need to be included somehow. $AttachFiles = "Updates/" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".log" FileCopy ( "Current.log", $AttachFiles) _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) EndFunc ;==>TimerYou can declare the rest of the variables such as $FromName, $FromAddress etc inside the function SendAttachment() or you can declare them globally, which you probably are doing already anyway.. I also modified water's code so that the function kicks in every half an hour. You could integrate the rest of your code using this as a template.Your (alternative) method is also acceptable and perhaps a little easier to implement, but you need to reset the timer every half an hour.$hTimer = TimerInit() While 1 If TimerDiff($hTimer) > (30 * 60000) Then $AttachFiles = "Updates/" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".log" FileCopy ( "Current.log", $AttachFiles) _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) $hTimer = TimerInit() ; reset the timer every half an hour. EndIf Wend Edited April 17, 2012 by czardas operator64 ArrayWorkshop
nolongthin Posted April 17, 2012 Author Posted April 17, 2012 FileCopy ( "Current.log", $AttachFiles) If i put this in the while 1 as it the log is written there it automatically saves it to the $AttachFiles
czardas Posted April 17, 2012 Posted April 17, 2012 (edited) Sorry I edited my previous post quite a bit. FileCopy ( "Current.log", $AttachFiles) If i put this in the while 1 as it the log is written there it automatically saves it to the $AttachFiles Actually no. If you look at my second example above, the declaration takes place before the file has been created. The next line of code (which you posted) creates the file in the directory. In this case I called the directory Updates. Then the next line looks for the file in that directory and sends it by email. (in theory - since I haven't tried it) Edited April 17, 2012 by czardas operator64 ArrayWorkshop
nolongthin Posted April 24, 2012 Author Posted April 24, 2012 Thanks czardas it worked. Is there a way to impose a limit that once the logs reach lets say 10MB it sends and then deletes repeatedly?
czardas Posted April 25, 2012 Posted April 25, 2012 Yes, check out FileGetSize, DirGetSize and FileDelete. You could also delete anything older than a certain date. operator64 ArrayWorkshop
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now