Looking for an answer on the following scenario:
I have a Python Script running, which i have plugged in my Windows Task Scheduler. Task runs successfully but does not do the work. Actually this script is supposed to download a file from SFTP Location Decrypt the file and converted csv file is being uploaded into the SQL Server.
Above Script is running fine when i run from the command line. however same script does not work when running from the Scheduler.
I have tried following approach to solve:
Task is running with the highest privilege
Task does not require user to log in, without login also task is running.
Other than above 2 options, I have no idea what needs to be done.
PS: From the task scheduler's history, I can see that there is no access denied error coming
Related
I need to run a batch script on my windows server machine. I am running that using WMIC command from my local system like this wmic /node:ipaddress /user:\username /password:password process call create "E:\Hello\start.bat" this gives me process ID and status.
That batch file will run a service in the server machine, and I can access the service from my local system. so once the operations on my local system are done. I will have to press Q on that batch file to generate report. But I have to enter button Q on my server from my local Using PID.
Is there a way to do that. I will have to execute these two commands using python script to automate the process.
Thanks in advance
I tried providing input to WMIC process using subprocess.PIPE.stdin("Q"). but did not work.
The two commands are : 1) wmic /node:ipaddress /user:\username /password:password process call create "E:\Hello\start.bat", this command will give me process id and status. 2) a command to enter key "Q" on the same process ID, returned from first command. If there is another solution also to do this that is also fine for me, but the problem is that, the server is windows 2016 and communicating that server from python code is little difficult.
I'm trying to create a task on Unix similar to a task of Task Scheduler in Windows which will run at specific times of the day and even gets triggered after server restarts. Aim of this job is to execute a python file.
My question is two parts:
1). How to write a job which I can schedule at multiple times of the day. I tried to write cron job using crontab command but it gives You <user> are not allowed to access to (crontab) because of pam configuration. I would like to know a way where I can schedule the triggering of python script without needing root/admin rights.
2). How can I schedule a job whose scheduling stays in effect even after the server is restarted. While going through various resources, I found systemd, using which we can use to start and stop the services. For example, https://linuxconfig.org/how-to-write-a-simple-systemd-service#:~:text=%20How%20To%20Write%20A%20Simple%20Systemd%20Service,section%20that%20you%20need%20to%20w...%20More%20
.But I'm unable to find how i can write a service script which will run my python script.
Can someone please guide on how can I run a job which executes my python script a some specific times of day and keeps working even after server bounce.
First PAM error say you do not have permissions so check /etc/security/access.conf and add line
+ : youruser : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6
For exec cron job on boot add in cron line like this:
#reboot /path/to/your_program
I have written some Python code to automate a task. Then I scheduled the Python script to execute twice a week using windows task scheduler. The task runs but there are two issues.
The console prints some error. It is strange because when I run the script manually after opening command prompt everything works as expected. This is what I do manually.
cd directory
directory>script.py
Inside the task scheduler I have directly specified the location of the script to run as C:\full\path\to\script.py
Second issue is that I can't even diagnose the error because the console closes as soon as it executes the script. This is despite the fact that I have added a dummy input command at the end of script like this:
All my Python code
input('Press any key to exit')
I also tried to keep the console open by using time.sleep(60) after importing the time module.
Can anyone tell me how can I keep the console open. Let me repeat that I am running the script using windows task scheduler. Running the script manually generates no error.
Thanks.
I'm a noobie to python and have over the past few days tested and created a .PY file that runs perfectly from the command prompt either with the D:\Python34 or just as
Its pretty basic. Gets info from web and places it in a spreadsheet - I import requests, BeautifulSoup and openpyxl. The last statement is to save the workbook. I'm figuring that Python closes itself as does the workbook.
I wish to run it daily. So I used the Windows Task Scheduler on my Windows 7 Ultimate. I have it running only when I am logged in.
I have tried the following:
1) using python directly with complete paths
2) using only the full path and the
3) using a batch file that does #1 above and has an EXIT
4) using a batch file that does #2 above and has an EXIT
When running the batch from the command file OR Task Scheduler, the command window opens, it does its thing and the command window closes.
The problem is when I run it via the Task Scheduler in any of the above ways, it does its thing, but continues to say "RUNNING" in the scheduler.
I have tried to run the Windows Process Monitor using some filters I found on the web, however nothing shows up.
Extremely frustrating --Any suggestions would be appreciated.
Jerry
While I had the Task Scheduler open, the screen was showing "running". After I closed the screen and let it run the next day, everything worked fine. It must be something to do with the refresh on the task scheduler.
So my solution was to close the Task Scheduler and let it run as scheduled.
I have created a simple cron job under windows to run a very simple python scrape:
scrape webpage
store data into csv file
close file
Cron job under Windows worked fine-without any probs. All of sudden, that cron job stopped working, my output file is not getting updated. When I run the scrape manually (double click on python file or via python IDE) I would typically get my debug output "everything ok" in a windows dialog window and the target file gets updated. During the cron job I can see that debug output window popping up and printing the same "everything ok" debug, but the file is just not getting updated.
I tried rebooting my machine, close/open all program. Created a new task in the scheduler, it still wouldn't work. Any suggestions?
Thanks
Peter
After playing around with all potential settings in windows and many wasted hours I found a workaround.
My initial setup in the task manager was calling the python.exe and my python.py file was passed as an argument. Just as described here: http://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/. The difference at the end that made my cron job work again was that I deleted passing the python file as an argument and now calling python file directly. Not sure why the initial setup stopped working - but this has helped. Hope you don't get into the same time wasting situation.