简体   繁体   English

安排cygwin的at工作

[英]Schedule `at` jobs with cygwin

I am running a bunch of simulations on several (non-equivalent) client machines. 我正在几台(非等效)客户端计算机上运行大量模拟。 In order to ensure that each simulation is run only once, the clients connect to and schedule a task on a linux server. 为了确保每个模拟仅运行一次,客户端连接到Linux服务器并在Linux服务器上安排任务。 The linux server runs the scheduled task, which ssh 's back into the client and schedules a run of the next simulation to be run. linux服务器运行计划的任务,该任务将ssh返回客户端,并计划要运行的下一个模拟的运行。

Since some of the clients run windows XP (running cygwin), part of the scheduling script on the client side checks if the client is running linux or cygwin and schedules the run of the simulation with the corresponding at command (cygwin's at command uses the WinXP at command , which has a different syntax). 由于某些客户端运行Windows XP(正在运行cygwin),因此客户端上的部分调度脚本会检查客户端是否正在运行linux或cygwin,并使用相应的at命令来调度仿真的运行(cygwin的at命令使用WinXP at command ,其语法不同。

I am able to successfully schedule on the windows client, the script that calls runs the simulation. 我能够在Windows客户端上成功调度,调用的脚本运行模拟。 However, I find that though the scheduled task is executed, the simulation is never run. 但是,我发现尽管执行了计划任务,但模拟从未运行。
But if I call the simulation from the commandline (copy-paste the scheduled command), then it works just fine. 但是,如果我从命令行调用模拟(复制并粘贴计划的命令),那么它就可以正常工作。

Can anyone help me figure this out? 谁能帮我解决这个问题?

More technical details : 更多技术细节

The simulation is a python script, which is located in the client filesystem 模拟是一个python脚本,位于客户端文件系统中
If I start cmd , it starts out in H:\\> , which is why part of my script starts with c: && 如果我启动cmd ,它从H:\\> ,这就是为什么我的脚本的一部分以c: &&开头
The scheduled script is a python script The correct python executable is part of the windows path as well as the $PATH variable in cygwin 计划的脚本是python脚本正确的python可执行文件是Windows路径以及cygwin中的$PATH变量的一部分

My scheduled script (the relevant part): 我的预定脚本 (相关部分):

import subprocess
import sys
import smtplib

scenario, p,h,t,c,m,run, IP = sys.argv[1:]

homedir = 'myUserName'
if IP == "137.122.88.124":
    homedir = 'myOtherUserName'

subprocess.check_call("""c: && cd \"c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\" && python "c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\\GP%(run)s.py" """ %{'home':homedir, 'scenario':scenario, 'popsize':p, 'height':h, 'tournsize':t, 'crossprob':c, 'mutprob':m, 'run':run}, shell=True)

For clarity, following are the commands that I call in the above subprocess.check_call separated by newlines: 为了清楚起见,以下是我在上述subprocess.check_call调用的命令,以换行符分隔:

c: &&
cd \"c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\" &&
python "c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\\GP%(run)s.py"

EDIT 1 : 编辑1

To test whether the scheduled script was even being called, I added the following lines to the top of the script: 为了测试调度脚本是否被调用,我在脚本顶部添加了以下几行:

f = open("C:\\Documents and Settings\\user\\Desktop\\somesimfile.txt", 'w')
f.write('I actually ran')
f.close()

Thus, if the script was run under python, it would leave a debris file that would confirm that it has run. 因此,如果脚本是在python下运行的,它将留下一个碎片文件,该文件将确认该脚本已运行。

After the scheduler showed that the job has executed, the debris file was missing. 调度程序显示作业已执行后,碎片文件丢失。 Thus, the script was never run. 因此,该脚本从未运行过。

EDIT 2 : 编辑2

Thinking that the scheduler might run the command within the cygwin environment, I altered the debris filepath to /home/user/somesimfile.txt 考虑到调度程序可能会在cygwin环境中运行命令,我将碎片文件路径更改为/home/user/somesimfile.txt

Still, no debris file was created. 仍然没有创建碎片文件。

I can only conclude that even though the task is scheduled, it's not being run. 我只能得出一个结论,即使任务已安排好,也没有在运行。
Thinking that this might be a permission issue, I checked, and all my simulation scripts hav 755 permissions. 我检查认为这可能是权限问题,并且我所有的模拟脚本都具有755权限。

EDIT 3 : 编辑3

This also does not appear to be a limitation of my login's privileges. 这似乎也不是我的登录权限的限制。 I am able to schedule tasks directly on cmd and get results for it, using my login. 我可以使用登录名直接在cmd上安排任务并获得结果。 Still, I am unable to schedule this simulation (or any other python script for that matter) directly from cmd 不过,我无法直接从cmd安排此模拟(或其他任何与此相关的python脚本)

The problem is that even though the path to python is in the system path, when a task is scheduled, this path does not take effect. 问题是,即使python的路径在系统路径中,当计划任务时,该路径也不会生效。 Therefore, the path to python.exe needs to be explicitly supplied. 因此,需要显式提供python.exe的路径。 Therefore, replacing 因此,更换

python "c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\\GP%(run)s.py"

with

"c:\\python27\python.exe" "c:\\cygwin\\home\\%(home)s\\project\\dir\\scenario%(scenario)s\\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s\\GP%(run)s.py"

fixes the problem 解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM