How to run a batch file without connecting to virtual machine?

NP Data 20 Reputation points
2024-07-24T20:32:10.7066667+00:00

Hi All,

I have a batch file within azure windows virtual machine. When I'm connected to the VM using RDP I can use a task scheduler to run the batch file.
(For context, the .bat file runs various python and R files)

I want this batch file to run without user intervention. Let's say I'm not connected to the VM nor I am using my local system. Is there a way I can schedule this .bat file to run inside VM?
Also, after the batch file runs all the latest files are sync'd to Dropbox

This is how the .bat script looks like:

"%python%" "C:\Downloads\Test1.py" %*
"%R%" CMD BATCH --slave "C:\Downloads\Test1.R" NUL

"%python%" "C:\Downloads\Test2.py" %*
"%R%" CMD BATCH --slave "C:\Downloads\Test2.R" NUL

pause

Most of the scripts require internet access to get data using API automations

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,719 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 62,946 Reputation points
    2024-07-24T21:07:53.43+00:00

    you don't give the O/S of the vm. for windows you can use the task scheduler:

    https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page

    note: if you installed desktop experience you can use the task scheduler app otherwise use command line schtasks.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 106.5K Reputation points MVP
    2024-07-24T20:44:58.2666667+00:00

    Hi @NP Data ,

    to run a script inside an Azure VM you can use the Run command in Azure Portal: Azure Portal - Run command

    Or use Azure CLI: Azure CLI - Run command

    Or use PowerShell: PowerShell - Run command


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten


  2. Ryan Hill 27,451 Reputation points Microsoft Employee
    2024-07-25T14:32:26.07+00:00

    Hi @NP Data,

    If all your .bat file contains is a lines of python code and R files, have you considered using an App Service Web Job instead? You can create an app service, select your SKU size (I would start with S1) and then upload bat file to web job and configured as a scheduled triggered job.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.