使用cygwin安排`at`工作 [英] Schedule `at` jobs with cygwin

查看:193
本文介绍了使用cygwin安排`at`工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个(非等效的)客户端计算机上运行一系列模拟。为了确保每个模拟只运行一次,客户端连接到并调度linux服务器上的任务。 linux服务器运行计划任务, ssh 回到客户端,并计划运行下一个模拟运行。



由于一些客户端运行Windows XP(运行cygwin),客户端调度脚本的一部分检查客户端是否运行linux或cygwin,并使用相应的命令(cygwin的命令使用 WinXP at 命令,不同的语法)。



我能够在Windows客户端上成功调度,调用运行模拟的脚本。然而,我发现,虽然计划的任务被执行,模拟永远不会运行。

但是如果我从命令行调用模拟(复制粘贴计划命令),那么它工作正常。 / p>

任何人都可以帮我解决这个问题。



更多技术细节

模拟是一个位于客户端文件系统中的python脚本

如果我启动 cmd ,它开始于 H:\> ,这就是为什么我的脚本的一部分以 c:&& c $ c>

计划脚本是一个python脚本
正确的python可执行文件是windows路径的一部分,以及 $ PATH variable in cygwin



我的预定脚本(相关部分):

  import subprocess 
import sys
import smtplib

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

homedir ='myUserName'
如果IP ==137.122.88.124:
homedir ='myOtherUserName'

子流程。 check_call(c:&&& cd \c:\\cygwin\\home\\%(home)s\\\\\\\\\\\\scenario%(方案)s \\p %(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm%(mutprob)s \& pythonc:\\cygwin\\home\\%(home)s\\\\\\\\\\scenario%(场景)s \\p% s%{'home':homedir,'scenario','s' :scenario,'popsize':p,'height':h,'tournsize':t,'crossprob':c,'mutprob':m,'run':run},shell = True)

为了清楚起见,下面是我在上面 subprocess.check_call 以换行符分隔:

  c:& 
cd \c:\\ cygwin \\home\\%(home)s \\ project \\ dir \\scenario%(场景)s \\p%(popsize)sh%(height)st %s(%s)(%s)(%)(%)(%s) \\\project \\dir\\scenario%(方案)s \\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm% \\\GP%(run)s.py

编辑1



为了测试调度脚本是否被调用,我在脚本的顶部添加了以下行:

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

因此,如果脚本在python下运行,它将留下一个碎片文件,以确认它已运行。



调度程序显示作业已执行后,碎片文件丢失。



编辑2



调度程序可能在cygwin环境中运行该命令,我将碎片文件路径更改为 /home/user/somesimfile.txt



仍然没有创建碎片文件。



我只能得出结论,即使任务已安排,它也不会运行。

认为这可能是一个权限问题,我检查,所有我的模拟脚本hav 755 权限。



strong> EDIT 3



这也不是我的登录权限的限制。我可以直接在 cmd 上调度任务,并使用我的登录获取结果。仍然,我无法直接从 cmd

解决方案

问题是,即使python的路径在系统路径中,当调度任务时,此路径不生效。因此,需要显式提供 python.exe 的路径。因此,替换

  pythonc:\\cygwin\\home\\% \\project \\dir\\scenario%(方案)s \\p%(popsize)sh%(height)st%(tournsize)sc%(crossprob)sm% \\GP%(run)s.py

 c:\\python27\python.exec:\\cygwin\\home\\%家庭)s \\project\\\\\\\\\\\\\\\scenario%(f场景)s \\p% mutprob)s\\GP%(run)s.py

修复问题


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. 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.

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).

I am able to successfully schedule on the windows client, the script that calls runs the simulation. 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
If I start cmd, it starts out in H:\>, which is why part of my script starts with 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

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:

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:

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.

After the scheduler showed that the job has executed, the debris file was missing. Thus, the script was never run.

EDIT 2:

Thinking that the scheduler might run the command within the cygwin environment, I altered the debris filepath to /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.

EDIT 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. Still, I am unable to schedule this simulation (or any other python script for that matter) directly from cmd

解决方案

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. Therefore, the path to python.exe needs to be explicitly supplied. 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

这篇关于使用cygwin安排`at`工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆