Lest I reinvent the wheel .... again:
Is there a python interface, API or module for the standard linux "at" task scheduler? I have tried searching the internet but searching for the word "at" is a tad bit useless :-)
My intention is to have a python script process same data and construct a shell file. Then use a subprocess call to have "at" schedule the job file for a specific date and time. I will have a similar function using "Schtasks.exe" if python detects it is running on windows. Lastly the python script exits ... leaving system scheduler the responsibility of running the job file.
update 1 July 2019:
Found an interesting "at" quirk.
The file called on the "at" command line (i.e. the script or shell file) does not need to be marked as "executable" in order to be run by "at".
For the record: I am running Linux Mint 19.1
You can achieve this with different approach:
Write your python script.
Call this script with a bash file.
Schedule bash file with a crontab task.
Related
I was wondering if there is a python module that essentially allows for checking whether your python script has been accessed/copied (and which user has done it) from a shared resource. More of a curiosity as most google searches have shown results relating to 'checking if a file copy is complete' and not necessarily 'if a file has been accessed/copied' and by who
Thank you!
As #Kris told System log files controlled by OS...There is an way you can get this...Simply follow steps..
1)Create a PowerShell script that will access system log files..Follow below link.
Link: Powershell script refrence
Next
run that powershell script using python
Link: Running powershell script within python script, how to make python print the powershell output while it is running
I stumbled on an answer for basically the exact same question, but either I am implementing the solution wrong, the solution is no longer accurate, or some other issue is at play.
Run a python script in virtual environment from windows task scheduler
I used the code from above link, edited for my directories, and copied directly into the task scheduler program/script prompt.
C:\Users\I511843\myenv\activate.bat && python C:\Users\I511843\Desktop\Atom_scripts\test.py
I then set the program to run every time I unlocked the machine. The program simply writes a text file called test.txt containing the text "success!"
The text file populates in the correct directory when I run from the command line, however, the program doe snot execute from the task scheduler.
Did you try putting the commands in a batch file and executing the batch file from task scheduler? Something like below:
C:\Users\I511843\myenv\activate.bat && python C:\Users\I511843\Desktop\Atom_scripts\test.py goes into task.bat file.
In task scheduler, run task.bat from cmd.
Through an application I have made with Tkinter, I'm trying to add a command to run a script every week. When the program is closed the command should be in forever place.
I've sifted through the documentation on cron, but there doesn't seem to be a way to edit the crontab without using the shell. Also I've looked through the 'at' command, but that only seems to run once.
My question is - How can one create a weekly recurring task by issuing a single command in Python on Unix?
If not with only 1 command, can I use multiple?
In most modern Linux distros like Debian or Ubuntu, you can add an executable file (like a shell script or a symlink to one) into /etc/cron.weekly and it will be automatically run once a week for you. This is using the anacron command, which is fairly common these days.
I am looking for a way to execute ABAQUS (a program) automatically from a python script with certain conditions. In Linux's command (terminal) line I type in
abq683 cae script=XX.py
and it will have ABAQUS run the script. I am aware of the python module 'subprocess' and it can run the basic program, which is the 'abq683' part of the command, however I cannot seem to find a way to have the other conditions run with it.
I am wondering if there is a way to run the full abq683 cae script=XX.py command automatically from a python text file.
Perhaps there is a way to print characters to the terminal window's active line and run them?
I am using Python2.6 on a linux machine
Thank you for any help you may offer.
import subprocess
retcode = subprocess.call(['abq684', 'cae', 'script=XX.py'])
When I try to use cron to execute my python script in a future time, I found there is a command at, AFAIK, the cron is for periodically execute, but what my scenario is only execute for once in specified time.
and my question is how to add python script to at command,
also it there some python package for control the at command
My dev os is ubuntu 10.04 lucid,and my product server is ubuntu-server 10.04 lucid version.
in fact, I want through python script add python script tasks to at command, which file's change can effect at command add or remove new jobs
This works on my linux box:
echo python myscript | at 10:15
Edit: stupid quoting...
As the man page says, at (as opposed to cron for example) doesn't respect shebang (the #!/usr/bin/env python line). It always uses /bin/sh to run the file.
So in order to run a python script you have to use either
echo python myscript.py | at 10:15
as suggested by #bstpierre or create an additional file
myscript.sh:
python myscript.py
and then
at -f myscript.sh at 10:15
Shebangs are not necessary this way (but wouldn't hurt either).
type man at, it will explain how to use it. Usage will slighty differ from system to system, so there's no use to tell you here exactly.
Just do
python FILE | at TIME > app.log
replace:
FILE - Your .py file (include the shebang)
TIME - Your time