我已经设置了一个cron任务,我想将输出保存到一个文件中。 该文件应该具有基于cron执行时间的名称(例如:20110317-113051.txt)。
我的实际cron命令如下所示:
lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txt我希望textfile被某种独特的时间戳取代。
我试过了
lynx -dump http://somesite/script.php > $(date).txt 但是我收到一条命令不明确的错误。谢谢你的帮助!
索林
I have set up a cron task and I want to save the output to a file. The file should have the name based on the time at which the cron was executed (eg.: 20110317-113051.txt).
My actual cron command is as follows:
lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txtI want the textfile to be replaced by some sort of unique time stamp.
I've tried
lynx -dump http://somesite/script.php > $(date).txt but I receive an error that the command is ambiguous.Thanks for your help!
Sorin
最满意答案
date命令可以给出一个格式来确定它生成日期的确切格式。它看起来好像你想要$(date +%Y%m%d-%H%M%S).txt 。 使用这种格式, date的输出应该没有空格,括号等,否则可能会混淆shell或lynx命令。
有关date命令和http://developer.apple.com/library/的文档,请参见http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/date.1.html 。 mac /#documentation / Darwin / Reference / ManPages / man3 / strftime.3.html以获得格式字符串的文档,这与标准库中的strftime函数相同。
The date command can be given a format to determine exactly what form it generates dates in. It looks as if you want $(date +%Y%m%d-%H%M%S).txt. With this format, the output of date should be free of spaces, parentheses, etc., which might otherwise confuse the shell or the lynx command.
See http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/date.1.html for documentation of the date command and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strftime.3.html for documentation of the format string, which is the same as for the strftime function in the standard library.
更多推荐
发布评论