2012-12-20 30 views
1

在我能夠做帶日期後綴的cron命令?

cp htlog.out test.$(date '+%m%d%Y')

但命令行,當我嘗試的crontab像這樣:

37 17 * * 1-5 cd the/dir && cp htlog.out test.$(date "+%m%d%Y") 

它無法從cron守護程序以下消息:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `"' 
/bin/sh: -c: line 1: syntax error: unexpected end of file 

而且我在命令後面有endlines。那個crontab條目有什麼問題?

回答

3

%crontab有特殊的含義,它應該是反斜線,所以:

37 17 * * 1-5 cd the/dir && cp htlog.out test.$(date "+\%m\%d\%Y") 

man 5 crontab:在命令

A 「%」 字符,除非有逃脫反斜槓 *()將被改爲換行符,並且第一個%之後的所有數據將作爲標準輸入發送到該命令。