2

I made a bat file which restarts 2 services, and I have it run in task scheduler. If I run the bat file normally, I can see it logging in current directory as the bat file. But if I run it through task scheduler, I can see the bat runs, like in services window, I can see the services restarting, but it doesn't log anything.... Does anyone know what the issue is?

This is on windows server 2008 r2 64-bit.

Thanks

@echo off
SET waittimeseconds_sp_fix=15
SET logfilename_sp_fix="SPSearchFix.log"

echo %date% %time% - Restart starting >> %logfilename_sp_fix%


net stop SPTimerV4 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped timer service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Stopped timer service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

net stop osearch14 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Stopped search service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Stopped search service >> %logfilename_sp_fix%
    exit
)    

timeout %waittimeseconds_sp_fix%

net start SPTimerV4 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started timer service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Started timer service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

net start osearch14 >> %logfilename_sp_fix% 2>&1
if ERRORLEVEL 0 (
    echo %date% %time% - WORKED - Started search service >> %logfilename_sp_fix%
) ELSE (
    echo %date% %time% - FAILED - Started search service >> %logfilename_sp_fix%
    exit
)

timeout %waittimeseconds_sp_fix%

echo %date% %time% - Restart completed >> %logfilename_sp_fix%

echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
echo. >> %logfilename_sp_fix%
3
  • Try specifying an absolute path in your SET logfilename_sp_fix="SPSearchFix.log" line. E.g.: SET logfilename_sp_fix="c:\temp\SPSearchFix.log", and ensure all users have write access to that folder. Jan 26, 2016 at 17:09
  • I figured it out, it was logging to system32 folder for some reason, but putting absolute path worked.
    – omega
    Jan 26, 2016 at 17:11
  • That's what I figured, I'll post up an actual answer. ;) Jan 26, 2016 at 17:11

1 Answer 1

2

When you run things in the Task Scheduler, the working folder (by default) is %windri%\system32. So any files created by the task, that don't have a path specified, will be written there (or at least it will attempt to write them there).

To avoid this, specify an absolute path in your SET logfilename_sp_fix="SPSearchFix.log" line.

E.g.: SET logfilename_sp_fix="c:\temp\SPSearchFix.log

And ensure all users (or at least the user the task runs as) have write access to that chosen folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .