Solved Batch file code snippet to run multiple tasks

November 8, 2017 at 03:00:06
Specs: Windows 10
Hi,
I have a set of tasks to be run at different times of a day & at different days. I wanted to schedule it using a batch file which reads the date, time and file path from excel file and run the tasks also send emails after the task is completed or any failures have occurred
Can anyone suggest any code snippet?

See More: Batch file code snippet to run multiple tasks

Reply ↓  Report •

✔ Best Answer
November 12, 2017 at 19:00:18
Welp, no response, but that doesn't affect the part that interests me. I'm just looking to play with the task scheduler from Win10's PowerShell.
$taskSettings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel
gc .\some.csv | 
select -skip 1 |
ConvertFrom-Csv -Header 'File','Path','Dates','Times','Email' |
ForEach-Object{
  $action =  New-ScheduledTaskAction "powershell" ("-NonInteractive -ExecutionPolicy Bypass " +
   "-Command `"& 'C:\PSScripts\processYXMD.ps1' '$($_.Path)' '$($_.Email)'`"")
  $triggers = @()
  foreach ($d in ($_.Dates -split ',')) { 
    foreach ($t in ($_.Times -split ',')) {
      $triggers += New-ScheduledTaskTrigger -Once -At ([datetime]$d + [timespan]$t)
    }
  }
  Register-ScheduledTask -TaskName $_.File -TaskPath "PSScripts" -Action $action `
   -Trigger $triggers -Settings $taskSettings
}

How To Ask Questions The Smart Way



#1
November 8, 2017 at 03:08:53
can be done, but you have to safe the excel file as a text file(& en do this for every update) in order for the .bat to read it.

could you give me some example data, or upload your excel file somewhere

i5-6600K@4.6GHz/4.2GHz cache@1.305v | 2x4GB Crucial-DDR4-2133@ 14-14-14-30 1T 2800MHz@1.34v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI Radeon RX 570 ARMOR 4GB@1275cc&2050mem | Corsair CX450 450W

message edited by hidde663


Reply ↓  Report •

#2
November 8, 2017 at 03:23:59
Sure, I'm writing the sample below of the excel file

File name|| File Path|| Date ||Timing|| Email Id
abc || C:\Projects\expensesworkflow.yxmd|| 8nov2017,10Nov2017,17Nov2017|| 16:30, 17:10, 20:05|| xyz@gmail.com
bcdf || C:\Projects\censusworkflow.yxmd|| 9nov2017,11Nov2017,15Nov2017|| 12:30, 14:05, 19:05|| sgfc@gmail.com
fghi || C:\Projects\profitworkflow.yxmd|| 17nov2017,11Nov2017,15Nov2017|| 12:30, 14:05, 19:05|| sgfc@gmail.com


Reply ↓  Report •

#3
November 8, 2017 at 04:35:53
I will need some further explaning:

abc || C:\Projects\expensesworkflow.yxmd|| 8nov2017,10Nov2017,17Nov2017|| 16:30, 17:10, 20:05|| xyz@gmail.com

From this line you want to run "abc" at these times/dates & send email afterwards to C:\Projects\expensesworkflow.yxmd?:

8Nov2017, 16:30 + 17:10 + 20:05
&
10Nov2017,16:30 + 17:10 + 20:05
&
17Nov2017, 16:30 + 17:10 + 20:05

abc is a file with no extension? also what does it contain?

Could you explain what the .bat has to do for you step by step?

also you might have to wait for someone else to join this discussion, since I am unfamiliar with sending emails from with .bat, however it is possible with powershell

i5-6600K@4.6GHz/4.2GHz cache@1.305v | 2x4GB Crucial-DDR4-2133@ 14-14-14-30 1T 2800MHz@1.34v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI Radeon RX 570 ARMOR 4GB@1275cc&2050mem | Corsair CX450 450W


Reply ↓  Report •

Related Solutions

#4
November 8, 2017 at 05:42:09
okay let me explain how I'm expecting the bat to read the data given in the excel file and execute files by comparing the date in excel with the system date and on match compare time with the system time and on match execute/ run the file abc.yxmd and send mails to xyz@gmail.com after the task is completed

also I've the sample edited

File name|| File Path|| Date ||Timing|| Email Id
abc || C:\Projects\abc.yxmd|| 8nov2017,10Nov2017,17Nov2017|| 16:30, 17:10, 20:05|| xyz@gmail.com
bcdf || C:\Projects\bcdf.yxmd|| 9nov2017,11Nov2017,15Nov2017|| 12:30, 14:05, 19:05|| sgfc@gmail.com
fghi || C:\Projects\fghi.yxmd|| 17nov2017,11Nov2017,15Nov2017|| 12:30, 14:05, 19:05|| sgfc@gmail.com


yes for a given date it has to run for the following timings

8Nov2017, 16:30 + 17:10 + 20:05
&
10Nov2017,16:30 + 17:10 + 20:05
&
17Nov2017, 16:30 + 17:10 + 20:05


Reply ↓  Report •

#5
November 8, 2017 at 07:18:00
If all the info needed is in an Excel spreadsheet, wouldn't VBA be a better choice?

MIKE

http://www.skeptic.com/


Reply ↓  Report •

#6
November 8, 2017 at 08:10:55
RE #5 Agreed, i will continue in batch soon if you havnt taking over by then

i5-6600K@4.6GHz/4.2GHz cache@1.305v | 2x4GB Crucial-DDR4-2133@ 14-14-14-30 1T 2800MHz@1.34v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI Radeon RX 570 ARMOR 4GB@1275cc&2050mem | Corsair CX450 450W

message edited by hidde663


Reply ↓  Report •

#7
November 8, 2017 at 08:28:19
hidden663:

if you havnt taking over by then

My VBA skills are just above nil, but if the OP posts his question in the Office Software forum
there are several members who are very good.

MIKE

http://www.skeptic.com/


Reply ↓  Report •

#8
November 8, 2017 at 10:45:13
It . . . depends on a lot of considerations not addressed here. From the sounds of it, you're looking at interfacing with Task Scheduler to have it kick off a generic script that'll run some sort of data analytics program against the specified .yxmd file and send an email afterwards at a specified time. VBA's suited to the first half of that. The second half would be done better with an actual Windows scripting language. So it's six of one and half a dozen of the other. Unless you're doing the Office 365 thing, in which case things change.

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

#9
November 9, 2017 at 02:06:27
But I've no clue about VBA. If its possible to do with that, can I get some suggestions on the method to be followed using also would be great to have some code snippets.

Reply ↓  Report •

#10
November 9, 2017 at 02:10:12
I can make a csv file which will have all the data but I need a method which could be linked with batch file to execute all the tasks required to be done.

Reply ↓  Report •

#11
November 9, 2017 at 08:34:16
Suhail_07, post your request in the Office Software forum. There are members who are skilled at using VBA, also search the site for previous request that are similar to what you are asking.

MIKE

http://www.skeptic.com/


Reply ↓  Report •

#12
November 9, 2017 at 15:34:10
Okay, assuming we're going the .csv route, how does one "run" a .yxmd file, from the context of a script? How does one know it's done? How do you intend to send this email message? Do you have an internal SMTP server you intend to use?

How To Ask Questions The Smart Way


Reply ↓  Report •

#13
November 12, 2017 at 19:00:18
✔ Best Answer
Welp, no response, but that doesn't affect the part that interests me. I'm just looking to play with the task scheduler from Win10's PowerShell.
$taskSettings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel
gc .\some.csv | 
select -skip 1 |
ConvertFrom-Csv -Header 'File','Path','Dates','Times','Email' |
ForEach-Object{
  $action =  New-ScheduledTaskAction "powershell" ("-NonInteractive -ExecutionPolicy Bypass " +
   "-Command `"& 'C:\PSScripts\processYXMD.ps1' '$($_.Path)' '$($_.Email)'`"")
  $triggers = @()
  foreach ($d in ($_.Dates -split ',')) { 
    foreach ($t in ($_.Times -split ',')) {
      $triggers += New-ScheduledTaskTrigger -Once -At ([datetime]$d + [timespan]$t)
    }
  }
  Register-ScheduledTask -TaskName $_.File -TaskPath "PSScripts" -Action $action `
   -Trigger $triggers -Settings $taskSettings
}

How To Ask Questions The Smart Way


Reply ↓  Report •

Ask Question