Unable to run a windows task that makes https request under SYSTEM account - windows

I have created a windows cmd file that calls three independent bat files. I want to create a windows task that calls this cmd file and runs every 5 minutes. The problem is that this task runs perfectly fine only when I'm logged into the system. But I'm unable to make this task continue to run "whether I'm logged in or not".
I even asked my colleague to login to that machine and run this task under his account - it worked. I created a local admin user on that machine, logged in as that user, tried to run this task - it did not work - the script waits forever while post_results.bat. I even tried to schedule a jenkins job that basically does the same thing - it did not work - the jenkins job waits forever while post_results.bat (I killed the jenkins job after waiting for ~20 min).
Here is a summary of what these tasks are doing:
run_all.cmd
call "run_test.bat"
call "post_results.bat"
call "clean.bat"
run_test.bat - executes a jmeter script
C:\Users\Administrator\LS2\apache-jmeter-4.0\bin\jmeter -n -t api_strategy_synthetic_tests.jmx -JTestEnv=amer1 -l Result_log.jtl
post_results.bat - calls a python script that posts the jmeter test results to datadog
python post_jmeter_results_to_datadog.py Result_log.jtl
post_jmeter_results_to_datadog.py - uses the datadog python api to post metrics to datadog
#!/usr/bin/env python3
import sys
import pandas as pd
from datadog import initialize, api
options = {
'api_key': <API_KEY>,
'app_key': <APPLICATION_KEY>
}
initialize(**options)
jtl_file = sys.argv[1]
df = pd.read_csv(jtl_file)
for index, row in df.iterrows():
tag = "success:" + str(row['success'])
api.Metric.send(
metric=row['label'],
points=[(row['timeStamp']/1000,row['elapsed'])],
tags=[tag]
)
clean.bat - deletes the jmeter test result files
rmdir /s /q "errors"
del "jmeter.log"
del "Result_log.jtl"
All I need is to be able to run this task every 5 minutes. If anyone is able to see what I'm doing wrong and points that out... I'd be really grateful.

You can create one PowerShell script to execute your Batch scripts remotely.
And Even you can schedule your PowerShell script using Windows Task Scheduler which will run as per your settings.

Related

Task scheduler is not executing Batch call to VBS script but it works fine when executed manually

We are running a Batch script call "C:\My Scripts\Script.vbs" which when run manually, executes the vbscript perfectly. However when setting up a scheduled task, it works some times, but most times it never completes and we have set the task to forcibly stop after 4 hours - which does not seem to work either. The task is set to run with administrator privileges and we can see in the task history that the task is running when it is set to run but it does not seem to ever execute the script properly. Any recommendations and help you can provide are much appreciated.
Update: It will run when set to run when user is logged on but will not run when set to run where user is logged on or not

Windows Task Scheduler - Task Won't Die

I have a task scheduled to run daily that executes a .bat file and I have checked the options for ending the task after an hour and forcing it to stop if it does not end when requested to, but it runs indefinitely until I manually kill it. Any ideas? (I do not want to use pskill in my script). Script below:
sqlcmd -S MyServer -U username -P password _Q "BACKUP DATABASE x to y"
net use z: "\\server1\project"
cd C:\trial1
copy * "Z:\backups"
net use z: /delete
exit
Thanks to Hans Passant for the answer! See below:
Taking away 'net use' and just directly copying to the server cleared up some error that the task scheduler was getting stuck on.

Batch script that checks windows services and creates .csv output works when manually initiated, but not when initiated via Windows Task Scheduler?

My goal is to have a batch script that checks windows services to see if they're running and output a .csv report. I also want this batch script to run hourly via Windows Task Scheduler.
Here is a script I was given to and am using for the example:
type null > servicecheckupreport.csv
sc query "AdobeARMservice" >> servicecheckupreport.csv
sc query "aspnet_state" >> servicecheckupreport.csv
sc query "AdobeFlashPlayerUpdateSvc" >> servicecheckupreport.csv
I am checking three (example) services, AdobeARMservice, aspnet_state and AdobeFlashPlayerUpdateSvc.
The batch works fine when you manually execute it, however when I successfully connect it to Windows Task Scheduler using the "Create Basic Task" feature, the batch script runs, but doesn't generate the .csv report. I can see the command prompt come up for a little bit, goes away and then that's it.

running shell script with windows task scheduler

I currenty have a simple shell script that I created for a linux machine to be run using cron, but now I want to be able to run the file using windows task scheduler. I have tried to get it to work using cron for cygwin, but even after running cron-config successfully and ensuring that the shell script can be executed successfully, for some reason the cron task simply wasn't executing. So I decided to give in and use the windows task scheduler. In order to do this, I looked at the following posts about the issue:
Cgywin .sh file run as Windows Task Scheduler
http://www.davidjnice.com/cygwin_scheduled_tasks.html
in my case, the entry in the "actions" tab of the new task looks like this:
program/script: c:\cygwin64\bin\bash.exe
arguments: -l -c "/cygdrive/c/users/paul/bitcoinbot/download_all_data.sh >> cygdrive/c/users/paul/bitcoinbot/logfile.log 2>&1"
start in: c:\cygwin64\bin
Notice that I redirected the output of the shell script to a log file, so that I should be able to see there whether the program run. Other than that, I simply edited the "trigger" tab to run the task daily, and set the time to a couple of minutes in the fture to see whether it ran successfully.
Alas, when I look at the detailed event history for the task, nothing changes when the trigger time passes. And when I manually "run" the task, the event history seems to add a few different events, but the task is completed within seconds, whereas this task should take over an hour (and it does when the shell script is executed directly from the terminal). And when I look for the log file that should have been created, there is nothing.
Does anyone have any idea what might be the issue here? How can I get my task to run properly at the trigger time, and how can I make sure it does so?
Best,
Paul
EDIT:
here are the pictures showing event history, as per Ken White's request.
Please ignore the fact that it says there are 24 events. These are from multiple separate runs of the task. The events shown here are a complete list of the events triggered by a single run.
EDIT 2:
Regarding my attempts to get cron to work, I have run into the following problem when I try to start the cron service using cygrunsrv. First of all, I tried to start cron by typing
cygrunsrv -I cron -p /usr/sbin/cron.exe -a -D
Now when I type
$cygrunsrv -Q cron
Service: cron
Current State: stopped
Command: /usr/bin/cron.exe
Now, I tried to start the cron service by typing
cygrunsrv -S cron
Cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062:
The service has not been started.
Does anyone hae any idea what this error means? I tried googling it, but couldn't find any answers.

Task Scheduler: Run a Java program after a Python script finishes

I need to do two things every 10 mins or so:
1) Run a python script
2) Once the above script finishes to completion, run the Java program (JAR file)
I'm using Windows Task scheduler for this. I've come across these two links:
https://technet.microsoft.com/en-us/library/cc772785%28v=ws.10%29.aspx
https://technet.microsoft.com/en-us/library/cc755618%28v=ws.10%29.aspx
but I'm just not sure how to go ahead with this. Can I write some powershell script or something which can take care of this? Any help is extremely appreciated. Thanks.
You could do that with a powershell script. You can execute a programm and then wait until it has finished its taks like this:
While($True)
{
Start-Process $PythonPath -Wait
Start-Process $JavaPath -Wait
Start-Sleep -m 10
}
in a background task you can define several actions that would be processed one after the other. So I would just create a background task in the Windows Task Scheduler, set the trigger and create two actions, first your python script and then the execution of your java program. Unless the python script returns before it is completed, your two actions will be processed in sequence.

Resources