Share via

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.

0 comments No comments
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 83,501 Reputation points Volunteer Moderator
    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. Ryan Hill 30,331 Reputation points Microsoft Employee Moderator
    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

  2. Andreas Baumgarten 130.9K Reputation points MVP Volunteer Moderator
    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


Your answer

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