Calling Python script from salt scheduler - scheduler

I have written a salt scheduler and and the scheduler is running every minute. I want to call a Python script from the scheduler.
Any working example would be of a great help.

If you want to call a python script from a schedule you could use cmd.script. Here is a schedule state file as an example:
job3:
schedule.present:
- function: cmd.script
- job_args:
- salt://test.py
- seconds: 3600
- splay: 10

Related

Processing used in scheduled powershell scripts

I want a powershell script to run hourly. Am I best to run the script all day at startup and use sleep to run the code hourly or am I best to use a Windows scheduled task to execute and then close the script?
Which is better for not slowing the PC down?

Schedule a Perl script run in Ubuntu. Not looking at cron

I've got this Perl script on Ubuntu that I need to run at a particular time in the future. I don't need it to run at that time more than once or basically what I'm trying to say is that it does not need a cron.
I need to schedule a run at a future time to run once and that's it. Any idea how to go about it? I've googled a bit but every time the concept of cron comes up so not really helpful.
I do have some code. The user clicks on a button (say "Schedule") on the GUI and a process starts in the background which schedules the run after (say) N hours.
I'm ready with the GUI and the connection to the backend Perl script. The N hours is predetermined. But I don't know how to code the scheduling concept in the Perl script.
One way is that your Perl scripting will just sleep(seconds) and then execute the action. In case you don't want to have this you need to tell some other service that it should invoke a program at a specific time. In UNIX this is usually done with the at command.
Use the at command:
echo 'perl foo.pl' | at now + 3 hours

How to prevent the crontab job execution, when it is already running

I want to schedule a job to run every 5 minutes. but the question is that
Is there a way (like creating a crontab) to prevent a job from running, when the previous job has not been completed?
You can write a shell script to start the job only when the job is not already running. Configure the shell script in crontab every 5 minutes. this will ensure that the execution happens only when there is no instance of the job running already. This is how i have done for my cron jobs
Note : make use of ps -ef | grep commands in your shell script to identify if there is a process already running

Edit triggers for a Windows Task Scheduler Task

We currently have several hundred tasks scheduled in Windows Task Scheduler on our server 2008 box. There are a number of tasks that are running every half hour indefinitely. Is there any way to use a script to change the triggers on those tasks so that they will only run every half hour M-F?
Yes, if you use the TaskService COM object. For some example scripts that use this object, see the following:
Rename Scheduled Tasks in Windows 7, Windows Server 2008, and Windows Vista
How-To: Use PowerShell to Report on Scheduled Tasks
Updating a Scheduled Task's Credentials
Script: https://gist.github.com/Bill-Stewart/363fdf761499a071439c8ac0c18dcd54
Using the schtasks.exe utility is rather limited past Windows XP/Server 2003.
Here are the allowed options for /SC:
/SC allows for the following frequency schedules:
MINUTE: 1 - 1439 minutes.
HOURLY: 1 - 23 hours.
DAILY: 1 - 365 days.
WEEKLY: weeks 1 - 52. (/D MON,TUE,WED,THU,FRI,SAT,SUN)
ONCE: No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE: No modifiers.
MONTHLY: 1 - 12, or FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.**
I keep editing this because I'm not happy with my findings...
I have looked into the SCHTASKS and noticed that you cannot CHANGE for the schedule through CMD.
From technet.microsoft
Changes one or more of the following properties of a task.
The program that the task runs (/tr).
The user account under which the task runs (/ru).
The password for the user account (/rp).
I am going to continue to do some research on this, and hopefully will edit this answer with a workable solution.
EDIT
If you look in C:\windows\system32\tasks you will find all of your scheduled tasks
They're not listed as XML, but they are indeed XML
What I think should be done is using either; VBS or C# application dig to each of the following Nodes
//Task/Triggers/CalendarTrigger to delete /ScheduleByDay and it's child node /DaysInterval
//Task/Triggers/CalendarTrigger to create the following:
<?xml version="1.0" encoding="UTF-16"?>
-<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.2">
+<RegistrationInfo>
-<Triggers>
-<CalendarTrigger>
<StartBoundary>2013-03-13T15:20:00</StartBoundary>
<Enabled>true</Enabled>
-<ScheduleByWeek>
-<DaysOfWeek>
<Monday/>
<Tuesday/>
<Wednesday/>
<Thursday/>
<Friday/>
</DaysOfWeek>
<WeeksInterval>1</WeeksInterval>
</ScheduleByWeek>
</CalendarTrigger>
</Triggers>
If anyone can pick up and run with this - I don't think I'll be able to do much with this in the next week.
I found that if you use SCHTASKS /Create and use the same /TN name with a different /SC and /ST options it will overwrite the existing scheduled task with the updated schedule

simple command prompt one line into exe

I have a perl script that I run from the command prompt: 3 times a day, the problem is now I need to run it every two hours. Im not going to be on an episode of lost so I need some help. Here is the command:
Perl C:/test/scripts/edi.pl
Does anyone know how this above one line command can be made into an executable (.exe) file so I can use the task scheduler to run?
If there is another way to do this with the task scheduler to run once every two hours every day then I could do that as well.
Thanks for your time.
Can you not simply create a batch file that runs the script, and set that batch file to run every two hours? I know from a quick test there that I can schedule a batch file to run from Task Scheduler on Windows XP at least.
You can actually use the task scheduler to run that exact command without a batch.
The task scheduler should allow you to pass some arguments to the script without a problem (I have done this on a few Windows servers in order to have them run PHP scripts)