Setting more than one trigger with SCHTASKS command - azure-pipelines-build-task

I want to add multiple triggers for the task I'm creating through windows command line interface. I went through the documentation for schtasks create here but it doesn't specify how we can do this, or even if we can or not at all.
An example of how I create a task with one trigger, specifically for Every day at 23:00:
SCHTASKS /CREATE /SC DAILY /ST 23:00 /TN "TaskName" /TR "D:\TaskDir\TaskName.exe taskArgument" /NP
I also want to set two additional triggers for 09:00 and 16:00.
How can I achieve this?

To schedule the .eve task program, if for regular hours schedule in a day like for to run every 7 hours, for 24 hours total, according to the doc: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks-create#examples-1 , type:
SCHTASKS /CREATE /SC DAILY /ST 09:00 /TN "TaskName" /TR "D:\TaskDir\TaskName.exe taskArgument" /NP/sc hourly /mo 7 /st 00:00 /du 0024:00
Then, if for random time points, it cannot be achieved in a single script, it should be divided into three scripts like below:
SCHTASKS /CREATE /SC DAILY /ST 09:00 /TN "TaskName" /TR "D:\TaskDir\TaskName.exe taskArgument" /NP
SCHTASKS /CREATE /SC DAILY /ST xx:00 /TN "TaskName2" /TR "D:\TaskDir\TaskName.exe taskArgument" /NP
SCHTASKS /CREATE /SC DAILY /ST xx:00 /TN "TaskName3" /TR "D:\TaskDir\TaskName.exe taskArgument" /NP

Related

Cron job periods

I would like to run the cron job every 20 minutes between 9 AM and 11 PM and once an hour after 11 PM until 9 AM.
cron job settings
I created 2 cron jobs for the same script to achieve my goal. Did I do it correctly?
Thank you.
Not really. There are two issues:
you run the script also on 23:20 and 23:40
you run the script twice from 09:00 till 23:00 every hour.
The way to do it is:
*/20 9-22 * * * command
0 0-8,23 * * * command
You can validate this using crontab guru

How to setup to use local time in cron schedule?

Cron by default uses UTC time zone. How to set it up to use Local time (say CST) in the cron expression (for cron schedule).
You can set your system's time zone to the intended time zone and then state the time for that zone in the cron job:
sudo timedatectl set-timezone America/New_York
and confirm typing timedatectl, or do
sudo dpkg-reconfigure tzdata
After changing the time zone, make sure to restart cron:
sudo service cron restart
Cron job:
30 5 * * * echo "run at half past 5" >> ~/logfile.log 2>&1
Cron doesn't care about time zone. It compares the current time to the cron string and executes the job if they match.

I want the cron job to run the script weekly basis

I am trying to setup a cron job on a Ubuntu server. I want the cron job to run the script on weekly basis. Problem is - It should be a working day, If im mentioning it with time interval, it fails during weekoffs - Need an Schedular Exp which has to work weekly only on working days at office hours.(9am to 9pm)max.
Want to Execute the script every week #6 pm during the weekdays. It Can be Mon to Fri.
Step1
sudo apt-get install cron
systemctl status cron
Step2
Configure the cron job:
crontab -e
Select an editor of your choice
0 0 * * 0 /path/to/command
Syntax: minute hour day-of-month month day-of-week command.
Day-of-week goes from 0-6 where 0 is Sunday.
Save it.

How to run Shell script through crontab or cron job on windows

I want to Do the Backup and restore with automated Process. I am looking for MongoDB native features as it takes very less time to do the backup and restores as compare to Other NPM Modules.
So for that, I have created the Shell script which is as follow:
#!/bin/sh
DIR=`date +%m%d%y`
DEST=/db_backups/$DIR
mkdir $DEST
mongodump -h 127.0.0.1:27017 -d mydbname -o $DEST
Now I want to Run this script through cron. What is the best approach for doing this?
I am on nodejs Windows Environment. Any help is really appreciated.
For that we have to open CMD and create the Job which can be run according to your reqirement.
Code will be on CMD is
schtasks /create /tn "mongodb_automated_job" /tr "location/mongo.sh" /sc minute /mo 1
It will run every minute.

Azure startup tasks not always firing

Working with a WorkerRole, I have two startup tasks that are defined. In the first one, firewall rules, cygwin download and install and calling powershell scripts is executed from a .cmd file.
The problem I am seeing, is that "sometimes", it is not executed. I can run a deployment, and it will work, then another it will not. The logs are not providing any help.
I have tried ensuring file encoding is correct, but there does not seem to be any consistency to the problem.
The .cmd file is as follows:
netsh advfirewall firewall add rule name="SSH" dir=in action=allow service=any enable=yes profile=any localport=22 protocol=tcp
IF EXIST C:\alreadySetup\NUL GOTO ALREADYSETUP
mkdir c:\alreadySetup
mkdir e:\approot\uploads
set remoteuser=user
set remotepassword=password
net user %remoteuser% %remotepassword% /add
net localgroup Administrators %remoteuser% /add
.\Startup\ntrights.exe +r SeServiceLogonRight -u "%remoteuser%"
.\Startup\ntrights.exe +r SeServiceLogonRight -u "Administrators"
netsh advfirewall firewall add rule name="SSH" dir=in action=allow service=any enable=yes profile=any localport=22 protocol=tcp
powershell -executionpolicy unrestricted -file .\Startup\DownloadBlob.ps1
c:\cygwin\bin\dos2unix.exe e:\approot\Startup\startSSHd.sh
schtasks /CREATE /TN "StartSSHd" /SC ONCE /SD 01/01/2020 /ST 00:00:00 /RL HIGHEST /RU %remoteuser% /RP %remotepassword% /TR "c:\cygwin\bin\bash --login /cygdrive/e/approot/startup/startSSHd.sh" /F
icacls d:\windows\system32\tasks\StartSSHd /grant:r Administrators:(RX)
schtasks /RUN /TN "StartSSHd"
schtasks /CREATE /TN "CopyAndCleanupSFTPFiles" /SC MINUTE /SD 01/01/2000 /ST 00:00:00 /RL HIGHEST /RU %remoteuser% /RP %remotepassword% /TR "e:\approot\Startup\CopyAndCleanupSFTPFiles.cmd" /F
schtasks /RUN /TN "CopyAndCleanupSFTPFiles"
:ALREADYSETUP
Of note, is that when it doesn't run, the alreadySetup folder is not even created, which is the first part of the script.
Do not use drive letter E: in the script. Deployments sometimes use E:, sometimes F:. I think this is why your script crashes/fails.

Resources