Run several indexes as a service using fscrawler - batch-file

I have successfully created an index job using fscrawler and made it run as a service in windows as shown in the documentation:
set JAVA_HOME=c:\Program Files\Java\jdk15.0.1
set FS_JAVA_OPTS=-Xmx2g -Xms2g
/Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job1 >>
/Elastic/logs/fscrawler.log 2>&1
However, I have several jobs (like 10 of them) which I would like to run concurrently. I have tried adding the start command as below but it gives me errors:
set JAVA_HOME=c:\Program Files\Java\jdk15.0.1
set FS_JAVA_OPTS=-Xmx2g -Xms2g
start "" /Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job1 >>
/Elastic/logs/fscrawler.log 2>&1
start "" /Elastic/fscrawler/bin/fscrawler.bat --config_dir C:\Documents\Elasctic\fscrawler job2 >>
/Elastic/logs/fscrawler.log 2>&1
How do I add several index jobs to the batch file so that they all run simultaneously?

Related

Start several scripts at once but still have output

I'm trying to run several scripts at once and have them output to different files but I can't get my code to work.
Code:
#echo off
start "" EXECUTIONSCRIPT1 >> "DIRECTORY\run1.log"
start "" EXECUTIONSCRIPT2 >> "DIRECTORY\run2.log"
start "" EXECUTIONSCRIPT3 >> "DIRECTORY\run3.log"
The scripts themselves perform whatever they need to do just fine, however, I can't get them to output anything to their files even though it's specified in the code.
If I remove (start "") they all run one after the other and they all output to their log files but that defeats the whole purpose of having them all run at the same time.
Right now, the >> is taking the output of the start command. In order for the >s to get passed as an argument instead of being activated immediately, they need to be escaped.
#echo off
start "" EXECUTIONSCRIPT1 ^>^> "DIRECTORY\run1.log"
start "" EXECUTIONSCRIPT2 ^>^> "DIRECTORY\run2.log"
start "" EXECUTIONSCRIPT3 ^>^> "DIRECTORY\run3.log"

Batch file for executing set of commands to start an application

We have an application. To start that application 8 to 10 commands has to be executed from within a command prompt window. I want to create a batch file to run those ten commands. I tried the batch code below, but couldn't get it working. We use Ruby.
Here are my commands:
set PATH=D:\Installables\jruby-bin-1.7.20\jruby-1.7.20\bin;%PATH%
set PATH=D:\Installables\phantomjs-2.1.1-windows\bin;%PATH%
set http_proxy=http://:#xxx.xxx.xx.x:xxxx
cd /D "D:\Installables\ansi160\x64"
ansicon.exe
cd /D "D:\folder"
gem install bundler & rem takes few seconds to complete
bundle install & rem takes few seconds to complete
bundle exec rake db:migrate & rem takes few seconds to complete
bundle exec rails s & rem takes few seconds to complete
The batch file execution stops after running ansicon.exe.
yeah you are switching over to ansicon.exe instead of starting it, thus stopping the script. You either need to start it (start "" "ansicon.exe") or call it (call ansicon.exe) if you need what it does in your file.

Why the batch "call" command is not executed in Windows Task Scheduler?

I have the following two batch files, bat1.bat calls bat2.bat.
bat1.bat:
#echo off
echo bat1 start >> C:\battest\log.log
call bat2.bat
echo bat1 end >> C:\battest\log.log
bat2.bat:
#echo off
echo bat2 >> C:\battest\log.log
When I run bat1.bat directly in command line, the output is as expected as below:
bat1 start
bat2
bat1 end
However, when I create a task in Windows Task Scheduler to run bat1.bat, I only get this:
bat1 start
bat1 end
It seems the call bat2.bat has no effect. Why?
OK, I figured it out.
When I run it directly in command line, the working directory is C:\battest.
However, when it is executed by Windows Task Scheduler, the working directory is C:\windows\system32, but there isn't the file bat2.bat.
I need to specify the full path of bat2.bat as below:
call C:\battest\bat2.bat

Running batch file from scheduled task on windows server 2012 won't write to disc

I wrote a short batch file for restarting two services every night and write some lines to a txt-file in the same folder. According to the history of the scheduled task the task ran succesfully, but the txt-file is not created.
At first I thought this was beacause of permissions, but when I escalated the permissions of the user running the task to max on both the batch file and the folder, the result stayed the same.
If I run the batch-file manually it does what it's supposed to do.
What am I missing here?
Source:
#echo off
set now=%date:~6,4%%date:~3,2%%date:~0,2%
#echo. >>servicerestartlog.txt
#echo.%now% >>servicerestartlog.txt
net stop "IntegratorService"
IF ERRORLEVEL 0 #echo STOP INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo STOP INTEGRATOR FAILED>>servicerestartlog.txt
net stop "SchedulerService"
IF ERRORLEVEL 0 #echo STOP SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo STOP SCHEDULER FAILED>>servicerestartlog.txt
net start "IntegratorService"
IF ERRORLEVEL 0 #echo START INTEGRATOR SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo START INTEGRATOR FAILED>>servicerestartlog.txt
net start "SchedulerService"
IF ERRORLEVEL 0 #echo START SCHEDULER SUCCESS>>servicerestartlog.txt
IF NOT ERRORLEVEL 0 #echo START SCHEDULER FAILED>>servicerestartlog.txt
exit
Solution that worked for me:
In addition to the path to the script I wanted to run I had to add the folder the script was supposed to start in. This can be set in the Start in (optional) - textbox under edit action. Seems it's not so optional after all...

Start multiple console apps from a batch file

I'm trying to run some console application .exe files from a batch file in Windows.
However, when I run the following code it only starts the first of the apps:
"C:\Development\App\bin\Debug1\Application.exe"
timeout 5
"C:\Development\App\bin\Debug2\Application.exe"
timeout 5
"C:\Development\App\bin\Debug3\Application.exe"
timeout 5
"C:\Development\App\bin\Debug4\Application.exe"
timeout 5
"C:\Development\App\bin\Debug5\Application.exe"
timeout 5
(I've included the timeout to spread out the intial processing a bit)
Is there a way to get the script file to start the first application, then move on and start the others?
Ideally I would like the script file to start all applications in a subdirectory, so that if I had Debug\Applications\*.exe or similar it would start all applications of type .exe (and possibly waiting 5 seconds between each). Is this possible?
You can start applications in the background by using start:
start "C:\Development\App\bin\Debug1\Application.exe"
Use start /? from a command window to get further details.
For example,
start dir
will open a new command window and show you a directory listing, leaving it open when finsished.
The:
start cmd /c "ping 127.0.0.1 && exit"
command will open a new window, run a four-cycle ping on localhost then exit.
In both cases, the current window will await the next command immediately.
#echo off
for %%F in ("Debug\Applications\*.exe") do (
start "" "%%F"
timeout 5
)

Resources