Jump to content

My script restarts on it's own - WHY?


Recommended Posts

Hi everyone

I run this script continuously on a server with TAS Books on it. Everything seems to work with a little teething problems. :mellow:

email.au3 is just a scriptlet that sends an email from me gmail account.

The _Restart function only runs when it detects an updated script in a shared folder.

Over the last few nights, it has sent me a "TASbackup has restarted" email at times after I have left work (so it's not me updating the script). 2 days ago it restarted at 21:14 and last night at 02:56.

Can someone look at my script and tell me why? also if i'm doing something wrong or long-winded, please advise me.

Here is the script.

Opt("WinWaitDelay", 850) ;250 milliseconds
Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
Opt("SendKeyDelay", 50)          ;50 milliseconds
Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown
#include <email.au3>
#Include <Date.au3>

$ScriptTime = FileGetTime(@ScriptFullPath, 0, 1)
$gettime = FileGetTime(@ScriptFullPath)
$gettime = $gettime[3] & ":" & $gettime[4] & " " & $gettime[2] & "/" & $gettime[1] & "/" & $gettime[0]
$title = " " & $gettime
TraySetIcon("E:\TAS BOOKS 2\TAS.ico")
Global $hTray_Show_Item = TrayCreateItem($gettime & " TAS Backup")
TrayCreateItem("")
Global $hTray_Show_Item = TrayCreateItem("Run Now")
TrayItemSetOnEvent(-1, "runme")
TrayCreateItem("")
Global $hTray_Exit_Item = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")
MsgBox(0, "WAIT" & $title, "TASBackup now running", 15)

$Subject = "TasBackUp"
$sfile = "E:\TAS_Backup\"
$file = $sfile & "*.TSB"
$TCM = "TASBooks Company Manager"
$CBA = "Company Backup Assistant"
$NCA = "New Company Assistant"
AdlibRegister("MyAdlib")
While 1
    If @HOUR = 18 And @MIN = 45 Then runme()
    $ScriptTime2 = FileGetTime(@ScriptFullPath, 0, 1)
    If $ScriptTime <> $ScriptTime2 Then
        MsgBox(0, $ScriptTime, $ScriptTime2,5)
        _Restart()
    EndIf
    Sleep(30000)
WEnd

Func runme()
    $begin = TimerInit()
    MsgBox(0, "TONY'S SCRIPTS" & $title, "TASBackup is about to take place", 20)
    Run(@SystemDir & "\rundll32.exe user32.dll,LockWorkStation")
    Sleep(5000)
    RunWait(@WindowsDir & "\Logon.exe -p ******")
    Run("E:\TAS BOOKS 2\TBLaunch.exe")
    WinWait($TCM)
    Sleep(2000)
    WinMove($TCM, "", 1,1)
    sleep(1000)
    WinActivate($TCM)
    Send("!f{DOWN}{ENTER}")
    Sleep(5000)
    WinWait($CBA, "",20)
    If Not WinExists($CBA) Then 
        MsgBox(0, "AUTOIT" & $title, "Problem " & $CBA & " doesn't exist",120)
        emailerror($CBA)
    EndIf
    WinMove($CBA,"",1,1)
    Sleep(1000)
    
    WinActivate($CBA)
    MouseClick("left",583,328)
    Sleep(1000)
    WinActivate($CBA)
    MouseClick("left",583,328)
    Sleep(1000)
    WinActivate($CBA)
    MouseClick("left",231,136)
    WinActivate($CBA)
    Send("******{TAB}")
    Sleep(1000)
    WinActivate($CBA)
    Send("******{ENTER}")
    Sleep(2000)
    WinActivate($CBA)
    MouseClick("left",583,328)
    Sleep(20000)
    WinWait($CBA,"Close",30)
    Sleep(5000)
    If WinExists($CBA, "Close") Then
        WinActivate($CBA)
        Sleep(5000)
        WinActivate($CBA)
        WinMove($CBA,"",1,1)
        Sleep(1000)
        WinActivate($CBA)
        MouseClick("left",583,328)
        Sleep(5000)
        WinActivate($CBA)
        Send("!f{UP}{ENTER}")
        WinWaitClose($TCM)
    EndIf
    MsgBox(0,"autoit" & $title,"starting moves",5)

    If @MDAY = 31 And @MON = 8 Then
        FileMove($file, $sfile & "Yearly\TasBackup " & @YEAR & ".TSB", 1)
    EndIf

    If FileExists($file) Then
        If @MDAY = 1 Then
            FileMove($file, $sfile & "Monthly\TasBackup " & @MON & ".TSB", 1)
        EndIf
    EndIf

    If FileExists($file) Then
        If @WDAY = 1 Then
            FileMove($file, $sfile & "Weekly\TasBackup " & Floor(@YDAY/7) & ".TSB", 1)
        EndIf
    EndIf

    If FileExists($file) Then
        FileMove($file, $sfile & "Daily\TasBackup " & @WDAY & ".TSB", 1)
    EndIf
    MsgBox(0, "TASBackup" & $title, "TASBACKUP is complete.", 10)
    $dif = Floor(TimerDiff($begin) / 10) / 100 & " seconds"
    emailerror("TASBACKUP is complete. Time to complete is " & $dif)
    Run(@SystemDir & "\rundll32.exe user32.dll,LockWorkStation")
EndFunc

Exit
Func On_Exit()
    Exit
EndFunc

Func MyAdlib()
    If WinExists($NCA) Then
        emailerror($NCA)
        MsgBox(0,"autoit" & $title,"Ooppss",5)
        ProcessClose("TBLaunch.exe")
        Sleep(50000)
        If WinExists($TCM) Then MsgBox(0, "AUTOIT", "Problem " & $TCM & " still running")
    EndIf
    If WinExists($CBA, "Close") Then
        WinActivate($CBA)
        Sleep(5000)
        MsgBox(0,"autoit" & $title,"Ooppss 2",5)
        WinActivate($CBA)
        WinMove($CBA,"",1,1)
        Sleep(1000)
        WinActivate($CBA)
        MouseClick("left",583,328)
        Sleep(5000)
        WinActivate($CBA)
        Send("!f{UP}{ENTER}")
        WinWaitClose($TCM)
        Sleep(50000)
    EndIf
    If WinExists("Overwrite") Then
        WinActivate("Overwrite")
        Send("!y")
    EndIf
    If WinExists("Cancel Assistant") Then
        WinActivate("Cancel Assistant")
        Send("!y")
        Exit
    EndIf
EndFunc

Func _Restart()
    emailerror("TASbackup has restarted")
    MsgBox(0, @ScriptFullPath, "RESTARTING", 30)
    Run(@AutoItExe & " /AutoIt3ExecuteScript " & @ScriptFullPath)
    Exit
EndFunc   ;==>_Restart
Link to comment
Share on other sites

You probably didn't narrow the time down enough. It could be completing the process and restarting while still within the time bounds.

If @HOUR = 18 And @MIN = 45 AND @SEC < 5 Then runme();;  You can change the 5 to any valid number but try to keep it low

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You probably didn't narrow the time down enough. It could be completing the process and restarting while still within the time bounds.

If @HOUR = 18 And @MIN = 45 AND @SEC < 5 Then runme();;  You can change the 5 to any valid number but try to keep it low

Thank you for your reply, but the script takes between 165 and 210 seconds to complete so shouldn't need seconds as a trigger point.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...