My apologies in advance for such a long first post, but I want to provide as much detail as I think this problem might need.
I use a set of nested VBS scripts to monitor the backup operations of several servers. The Master script is set to run as a scheduled task every day on one computer. The Master runs individual scripts for each independent server being monitored. Each individual script checks a specific dropbox folder for a flag file that indicates whether the nightly backup ran for that server. If the flag file is not found, a command line SMTP e-mail program is used to send a warning e-mail to an administrator.
Here is an excerpt of the Master Script:
And here is the relevant part of one of the individual scripts launched by the Master script:
The log file maintained by the Master and Individual scripts show that when the Master script is run manually, everything works as designed. When the Master script is run as a scheduled task, however, it does run and it properly launches all the individual script files, and they all run almost as expected, but the Shell.Run command that generates the e-mail appears not to execute. The diagnostic line seen in the code is written to the log file, so I know that the script is reaching and getting beyond the Shell.Run command.
I get the same behavior when I set up the individual script as a scheduled task, so it appears not to be a nesting issue.
I am capturing error codes from the Shell.Run command in the log file and when the script is run directly, the reported error code is 0, but when run as a scheduled task the error code is 1.
Finally, the command-line e-mail program generates its own error codes when there are problems and writes them to a secondary email log file. If I intentionally introduce an error (like not specifying a recipient) in the e-mail command line and run the script manually, then both the e-mail log file and my main log file show the e-mail program's error code (6), but when the script is run as a scheduled task then the e-mail log file shows no entry and the main log file shows an error code of 1 (which is NOT coming from the e-mail program).
What am I missing that might cause this problem? If I've left out relevant info, please let me know.
Any help would be appreciated.
Thanks,
Peter
I use a set of nested VBS scripts to monitor the backup operations of several servers. The Master script is set to run as a scheduled task every day on one computer. The Master runs individual scripts for each independent server being monitored. Each individual script checks a specific dropbox folder for a flag file that indicates whether the nightly backup ran for that server. If the flag file is not found, a command line SMTP e-mail program is used to send a warning e-mail to an administrator.
Here is an excerpt of the Master Script:
Code:
Dim objShell, objFSO, strLogFile, filetxt
Const ForReading=1, ForWriting=2, ForAppending=8
Set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
strLogFile="c:\BackupSystemsTests\BackCheck.log"
'Write entry to log file
Set filetxt = objFSO.OpenTextFile(strLogFile, ForAppending, True)
filetxt.WriteLine("======================================================")
filetxt.WriteLine("BackCheck.vbs now runs on: " & Now())
filetxt.Close
'Run the individual VBS scripts
'...
objShell.Run "c:\BackupSystemsTests\PGS-CHECK.VBS"
'...
Set objShell = Nothing
Set objFSO = Nothing
And here is the relevant part of one of the individual scripts launched by the Master script:
Code:
'If strMissing exists, then an expected backup job did not run
'so, format the string and send warning e-mail
If strMissing <> "" Then
If Left(strMissing,1)="," Then
strMissing= Right(strMissing,Len(strMissing)-2)
End if
'Send warning e-mail
strResult="No code received."
strCommandLine="fmail -cfg PSConAUTH.TXT -to pgsmick@XXXX.org -from pgsmick@XXXX.com -subj " & strOrgName & " did not run one or more backup jobs last night! -msg The following job(s) did not run: " & strMissing & vbCRLF & "Please investigate. (From PS-FS1) -log email.log "
[highlight #C4A000]strResult= objShell.Run(strCommandLine,1,True)
[/highlight] 'For Diagnostic use:
Set filetxt = objFSO.OpenTextFile(strLogFile, ForAppending, True)
filetxt.WriteLine(strOrgName & " Warning should have been sent on: " & Now() & "Result Code: " & strResult)
filetxt.Close
End If
The log file maintained by the Master and Individual scripts show that when the Master script is run manually, everything works as designed. When the Master script is run as a scheduled task, however, it does run and it properly launches all the individual script files, and they all run almost as expected, but the Shell.Run command that generates the e-mail appears not to execute. The diagnostic line seen in the code is written to the log file, so I know that the script is reaching and getting beyond the Shell.Run command.
I get the same behavior when I set up the individual script as a scheduled task, so it appears not to be a nesting issue.
I am capturing error codes from the Shell.Run command in the log file and when the script is run directly, the reported error code is 0, but when run as a scheduled task the error code is 1.
Finally, the command-line e-mail program generates its own error codes when there are problems and writes them to a secondary email log file. If I intentionally introduce an error (like not specifying a recipient) in the e-mail command line and run the script manually, then both the e-mail log file and my main log file show the e-mail program's error code (6), but when the script is run as a scheduled task then the e-mail log file shows no entry and the main log file shows an error code of 1 (which is NOT coming from the e-mail program).
What am I missing that might cause this problem? If I've left out relevant info, please let me know.
Any help would be appreciated.
Thanks,
Peter