LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2466|回复: 8

请教crontab执行脚本的路径和次数问题

[复制链接]
发表于 2006-6-13 11:34:32 | 显示全部楼层 |阅读模式
我用crontab执行一个自动备份的脚本来备份日志,但奇怪的是,脚本总会同时在两个目录备份,详情如下:
在crontab中:
/#crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.20789 installed on Fri Jun  9 14:45:08 2006)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
30 04 * * 1 /logdata/Logs/auto_back.sh

在每周一4点半执行。

————————————————————
脚本内容:

/logdata/Logs#cat auto_back.sh
rm -rf wget-log*
wget -c -b -r -t 50 -T 120 -w 20 -x -nH ftp://user:passwords@211.123.11.35/./logs
tail -f wget-log

希望从211.123.11.35下载user的Logs/目录的内容到/logdata/Logs中。

脚本执行情况:
能够成功下载需要的文件到/logdata/Logs中。
问题:在将文件下载到/logdata/Logs中的同时也会在/root目录下下载同样的logs/目录的内容。
也就是这个脚本同时下载了两份文件在期望的目录/logdata/Logs以及不期望的目录/root中。
请问为什么会产生这种情况并如何修改。
ps:执行脚本的用户为root。
发表于 2006-6-13 13:43:59 | 显示全部楼层
you should specify the actual path, otherwise, the cmd will run under the default $HOME dir where the /etc/passwd shows.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-14 10:23:03 | 显示全部楼层
这个,他无论是在/root目录下下载(我可以认为这是默认运行在$HOME)中;
还是在logdata/中(我可以认为这是运行在脚本的相对路径);

但为什么同是在两个地方都产生?我怎样让他只下载在logdata/中。因为日志文件比较大,可能将/root所在的系统分区充满而导致系统不能启动,是比较郁闷的一件事情
回复 支持 反对

使用道具 举报

发表于 2006-6-14 23:17:40 | 显示全部楼层
In your script, cd to the path and run script from there should solve the problem.
回复 支持 反对

使用道具 举报

发表于 2006-6-15 10:54:38 | 显示全部楼层
也可以在wget中使用  -O  选项
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-27 16:22:49 | 显示全部楼层
谢谢,我想
在脚本中添加进入目录的命令应该可以解决
但是wget的 -O选项以前没用过,我先测试一下看看。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-27 18:14:40 | 显示全部楼层
这个用-O的参数好像不对啊,我man了一下,如下,是输出到一个文件阿。所以我觉得这个事不能成功的,测试也没有成功,我不知道是不是有其他的设置方法,我的是:
wget -c -b -r -t 50 -T 120 -w 20 -x -nH ftp://userasswords@211.123.11.35/./logs -O /logdata/Logs。错误为:Is a directory
如果指定一个文件,文件内容为:
Error detected while processing function <SNR>3_read:
line   19:
E20: Mark not set
line   24:
E20: Mark not set
line   27:
Can't open file /tmp/v406746/0

不知道上面的是什么意思,请那位解释一下。

接下来是wget -O的man:

       -O file
       --output-document=file
           The documents will not be written to the appropriate files, but all
           will be concatenated together and written to file.  If file already
           exists, it will be overwritten.  If the file is -, the documents
           will be written to standard output.  Including this option automat-
           ically sets the number of tries to 1.

虽然-O选项没有能够成功指定路径,不过觉得用法比较有趣,不知道需要怎样的指定才能指定路径。

yongjian 的方法是能够成功的,谢谢。
也谢谢luweinet的关注。
回复 支持 反对

使用道具 举报

发表于 2006-6-27 19:01:44 | 显示全部楼层
wget -P
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-28 01:10:01 | 显示全部楼层
yes,的确用-P就可以了,不好意思,的确是看文档的时候不仔细。用-P可以指定下载的目的目录。谢谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表