Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Task Scheduler - Log Files, Output, etc.

19 Aug 2014   #1
Ilya

Windows 7 Ultimate 64-Bit
 
 
Task Scheduler - Log Files, Output, etc.

Hi guys and gals,

I'm trying to accomplish something at work and need some help.

Here is the situation:

1) There is a scheduled task setup to run an 'import' for my companies software. This task runs a .bat file which runs a program with a few switches (application 1). I have edited the .bat file to output to a log file.
2) However, after the program starts and does it's thing, it closes and launches another application (application 2) and does some more work on the newly imported data (actually integrates it into the database). BUT, because application 1 closed, the task considers itself closed and closes the .bat file and marks itself complete.

My issue is:

How do I write a .bat file or reprogram my scheduled task so my output file/log file includes the entire process? My goal is to keep an eye on how long the process runs from start to finish. Because they run in the middle of the night, I'm not around to monitor. The 'history' tab in Task Scheduler only shows the start/stop time of the initial program, not the second one.

This runs on Server 2008, but 2008 is very similar to W7, so your solutions should apply to both.

Thanks for any help you can give me!

EDIT:

Solution: See post #3.


My System SpecsSystem Spec
.
21 Aug 2014   #2
Ilya

Windows 7 Ultimate 64-Bit
 
 

Anyone? Please?
My System SpecsSystem Spec
29 Aug 2014   #3
Ilya

Windows 7 Ultimate 64-Bit
 
 

Since no one helped, I worked on it and got my own solution. Sharing this for anyone else who comes across this, because I'm nice.

Again...here is a brief explanation of what is going on:
  1. Scheduled task kicks off Program 1
  2. After Program 1 is done running, it automatically kicks off Program 2. HOWEVER, after Program 1 closes, task scheduler thinks the process is complete when it actually isn't. Thus, logging/history in the Task Scheduler is not accurate.
  3. Program 2 runs. My method monitors for Program 2 to close, and then ends the log file...thus providing me a way to see the entire process from beginning to end.

Code:
:: Setting the time and date - ** DO NOT CHANGE **
set tday=%date:~-4%%date:~4,2%%date:~7,2%

:: Setting the company name - replace with the company name
set company=Sample

:: Setting the log file folder location - Shouldn't need to change
set logfilefolder=C:\log\%company%

:: Creating above folder if it doesn't exist - ** DO NOT CHANGE **
IF NOT EXIST "%logfilefolder%" MKDIR "%logfilefolder%

:: Setting the log file name - replace with company name
set logfilename=Logname_%tday%.txt

:: Setting the location of PROGRAM1.exe - shouldn't change
set ProAdminLoc=C:\PROGRAM1.exe

:: Setting the name of the Auto INI - replace with correct INI filename
set autoini=TFSampleAuto.ini

:: Setting the switches to use (archive, import, export, etc.) - replace as needed
set switches=/autoarchive /autoimport



echo ************************************************************************************************** > "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo   **** %company% Auto Archive and Auto Import/Export Process Started: %DATE% %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo ************************************************************************************************** >> "%logfilefolder%\%logfilename%"

echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  // company Name: %company% // >> "%logfilefolder%\%logfilename%"
echo  // Auto INI Name: %autoini% // >> "%logfilefolder%\%logfilename%"

echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Availability Check] Checking to see if a previous archive or import is running before starting a new process **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Checking to see if a previous import is running before starting a new process

:: Checking for another instance of PROGRAM1.exe

:PRVARCHSTART
tasklist /FI "IMAGENAME eq PROGRAM1.exe" | find /I "PROGRAM1.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another archive process is not running...checking for an import/export process... **** >> "%logfilefolder%\%logfilename%"
goto PRVARCHEND
) ELSE (
echo        **** %TIME% - Another archive is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto PRVARCHSTART
)
:PRVARCHEND

:: Checking for another instance of PROGRAM2.exe

:PRVIMPSTART
tasklist /FI "IMAGENAME eq PROGRAM2.exe" | find /I "PROGRAM2.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another import/export process is not running...starting archive process... **** >> "%logfilefolder%\%logfilename%"
goto PRVIMPEND
) ELSE (
echo        **** %TIME% - Another import/export is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto PRVIMPSTART
)
:PRVIMPEND

echo     **** Step completed at: %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Archive] Running PROGRAM1.exe with following switches: %switches% **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Running PROGRAM1.exe with necessary switches

"%ProAdminLoc%" %autoini% %switches% >> "%logfilefolder%\%logfilename%"

:ARCHSTART
tasklist /FI "IMAGENAME eq PROGRAM1.exe" | find /I "PROGRAM1.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another archive process is not running...starting import/export process... **** >> "%logfilefolder%\%logfilename%"
goto ARCHEND
) ELSE (
echo        **** %TIME% - Another archive is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto ARCHSTART
)
:ARCHEND

echo     **** Step completed at: %TIME% **** >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo. >> "%logfilefolder%\%logfilename%"
echo  **** [Import/Export] PROGRAM2.exe launching...monitoring PROGRAM2.exe for completion **** >> "%logfilefolder%\%logfilename%"
echo     **** Step started at: %TIME% **** >> "%logfilefolder%\%logfilename%"

:: Checking to see if PROGRAM2.exe is running

:IMPEXPSTART
tasklist /FI "IMAGENAME eq PROGRAM2.exe" | find /I "PROGRAM2.exe" >nul
IF ERRORLEVEL 1 (
echo        **** %TIME% - Another import/export process is not running...ending auto archive/import/export process... **** >> "%logfilefolder%\%logfilename%"
goto IMPEXPEND
) ELSE (
echo        **** %TIME% - Import/export is running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%"
PING 1.1.1.1 -n 1 -w 10000 >nul
goto IMPEXPSTART
)
:IMPEXPEND

end
BOOMSHAKALAKA!
My System SpecsSystem Spec
.

Reply

 Task Scheduler - Log Files, Output, etc.




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
A way to edit Notepad files with Task Scheduler?
I need a way to change a Notepad file with Task Scheduler, or anyway really. Heres an example: I edit a Notepad file, and save it. At 1 PM I want the Notepad file to automatically change to what I want. So when I open that Notepad file after 1 PM, it looks the same as it did before I edited...
General Discussion
Need default Task Scheduler files
never mind
Performance & Maintenance
Need help creating a task scheduler task to move files over a network.
Hello everyone, I need to have a task run that will move the contents of a folder from one computer to another over my home LAN. Files get downloaded during the night on one computer and then need to be transfered to another. Usually I am doing this by hand, but then though maybe I could get...
General Discussion
Task scheduler unable to load task status/active tasks at startup.
My task manager is unable to load task status/active tasks at startup. I get the message: "The selected task "{0}" no longer exists. To see the current tasks, click Refresh." When I refresh I get the same message. I checked and found that under Microsoft the problem was in the defrag...
Performance & Maintenance
Task Scheduler failing to start task with merged network locations
I have two routers I usually connect to (work and home) and each have wireless access. That means there are essentially 4 network locations I have listed. I have merged each respective network location (wired and wireless) into their own singular network location - "Work" and "Home". I also...
General Discussion
Console output window shown by task scheduler
Hello... I had a task (a php script) running periodically on Windows Vista to change my network routes automatically (because OSPF support have been dropped by MS) and it was working fine... Now I am trying to run the very same script on a Windows 7 system... It runs fine, but on every run it...
Performance & Maintenance


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 22:00.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App