简体   繁体   English

为什么cygwin ls可以使cygwin cron找不到文件?

[英]why cygwin cron cannot find a file when cygwin ls can?

I got a cron job scheduled by using cygrunsrv and vixie's cron for cygwin. 通过使用cygrunsrv和vixie的cron进行cygwin,我得到了一份cron计划的工作。 The job is a shell script that copies files from one directory to another and renames them. 作业是一个Shell脚本,它将文件从一个目录复制到另一个目录并重命名它们。

The script is in /home/martin/my/script/copy_files.sh. 该脚本位于/home/martin/my/script/copy_files.sh中。 And the permission for the path is: 路径的权限为:

drwxrwxrwt+ 1 martin root         0 2010-06-02 17:36 home
drwxr-xr-x+ 1 martin Domain Users 0 2010-06-03 16:19 martin
drwxrwxrwt+ 1 martin Domain Users 0 2010-06-02 16:47 my
drwxrwxrwt+ 1 martin Domain Users 0 2010-06-04 16:31 script
-rwxr-xr-x  1 martin Domain Users 439 2010-06-02 18:10 copy_files.sh

When I ls -l, the source file is: 当我ls -l时,源文件是:

-rwxrw-rw-  1 martin Domain Users 13856 2010-06-04 10:05 .bash_history

But when the job runs, the cp command failed due to 但是当作业运行时,由于以下原因,cp命令失败

cp: /home/martin/.bash_history: The system cannot find the path specified.

So what is wrong? 那怎么了? How can I fix it? 我该如何解决?

Thank you. 谢谢。

I have not looked at cygwin for a few so my details in this are going to be few. 我没有看过cygwin几个,所以我在这方面的细节将很少。

Your problem is the directory tree. 您的问题是目录树。 You need to set the cwd (use cd) to /home/martin before you copy. 复制之前,您需要将cwd(使用cd)设置为/ home / martin。 The trick is knowing where /home is located, relative to the place where cron logs in. I frankly don't remember, but I do remember that I could not find it in the docset. 诀窍是知道/ home相对于cron登录的位置。坦率地说,我不记得了,但是我确实记得我在文档集中找不到它。

Let's assume the time is 15:28. 假设时间是15:28。 go into crontab -e add this: 进入crontab -e添加此:

30 * * * *  /usr/bin/echo "current dir= $(pwd)  $PATH" 2&>1 > ./19191919.log

wait until 15:31, go into crontab -e and remove that entry. 等到15:31,进入crontab -e并删除该条目。 We dont' want it anymore 我们不再想要它了

find / -type f -name 19191919.log  -exec /usr/bin/cat {} \;

This will tell you what you need to know. 这将告诉您您需要了解的内容。 about both the PATH and where login directory turns out to be. 关于PATH以及登录目录所在的位置。 My experience with vixie was that it WAS NOT the home directory in /etc/passwd 我对vixie的经验是它不是/ etc / passwd中的主目录

There was some .conf file that overrode /etc/passwd. 有一些.conf文件覆盖了/ etc / passwd。

This was long ago, so sorry if things turn out different. 这是很久以前的事了,如果情况有所不同,非常抱歉。

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

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