2012-08-24 33 views
0
tail /mnt/mysqld_log/mysql_error_log.err | grep -e `date +'%y%m%d' --date='4 hour ago'` | more 

120824 11:25:06 [ERROR] /usr/libexec/mysqld: Table '.zone_assoc' is marked as crashed and should be repaired 
120824 18:03:23 [ERROR] /usr/libexec/mysqld: Incorrect key file for table '.ad_zone_assoc.MYI'; try to repair it 
120824 18:08:38 [ERROR] /usr/libexec/mysqld: Incorrect key file for table '.ad_zone_assoc.MYI'; try to repair it 

上述工作正如預期的那樣,顯示了今天的日期結果。但以下情況不起作用。grep中的轉義空格

tail /mnt/mysqld_log/mysql_error_log.err | grep -e `date +'%y%m%d %k' --date='4 hour ago'` | more 

grep: 18: No such file or directory 

我試圖逃脫空間,並沒有工作。

tail /mnt/mysqld_log/mysql_error_log.err | grep -e `date +'%y%m%d\ %k' --date='4 hour ago'` | more 

grep: Trailing backslash 

回答

2

你需要用引號包住date命令:

tail /mnt/mysqld_log/mysql_error_log.err | grep -e "`date +'%y%m%d %k' --date='4 hour ago'`" | more 

的空間被解釋爲你嘗試讀取該文件,通過在引號包圍它,這將不會發生。

+0

什麼是確切的cron命令?你可能需要把它放在一個包裝腳本中,才能按預期工作,但給我一個cron,我會看看我能做什麼。 – Eugene

+0

cron條目在轉義%符號後正在工作。感謝您的快速幫助。 – shantanuo