{"id":398,"date":"2010-01-07T15:04:05","date_gmt":"2010-01-07T09:34:05","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=398"},"modified":"2011-09-20T12:44:54","modified_gmt":"2011-09-20T12:44:54","slug":"crontab-not-working-with-dynamic-filename-rhel-linux","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/crontab-not-working-with-dynamic-filename-rhel-linux","title":{"rendered":"crontab not working with dynamic date filename &#8211; rhel linux"},"content":{"rendered":"<p>I have done it for so many times, setting a cronjob.<br \/>\nToday I was tring to set a simple cronjob which will output the log file with timestamp attached filename.<\/p>\n<p>Hourly running cron entry was:<\/p>\n<p><code>0 * * * * perl demo.pl &gt; demo-out_`date \"+%Y-%m-%d_%H-%M\"`.log<\/code><\/p>\n<p>Running the same command on shell prompt was working fine. Execute permissions and path were proper.\u00a0But it kept on failing to create the proper log!!<\/p>\n<p>I changed the crontab as follows, added \\ before % to escape and voila!!<\/p>\n<p>Things worked !!<\/p>\n<p><code>0 * * * * perl test.pl &gt; test-out_`date \"+\\%Y-\\%m-\\%d_\\%H-\\%M\"`.log<\/code><\/p>\n<p>A quick lesson.<\/p>\n<p>Good to note some of the date changers in linux for finding yesterdays and tomorrows and so on:<br \/>\ndate &#8211;date=&#8221;1 days ago&#8221;<br \/>\ndate &#8211;date=&#8221;yesterday&#8221;<br \/>\ndate &#8211;date=&#8221;next day&#8221;<br \/>\ndate &#8211;date=&#8221;-1 day&#8221;<br \/>\ndate &#8211;date=&#8217;tomorrow&#8217;<br \/>\ndate &#8211;date=&#8217;1 day&#8217;<br \/>\ndate &#8211;date=&#8217;10 day&#8217;<br \/>\ndate &#8211;date=&#8217;10 week&#8217;<br \/>\ndate &#8211;date=&#8217;10 month&#8217;<br \/>\ndate &#8211;date=&#8217;10 year&#8217;<br \/>\ndate  &#8211;date=&#8221;next Friday&#8221;<br \/>\n<em>To escape problems you should learn to escape &#8220;special characters&#8221; &#8211; Krex<\/em><br \/>\nP.S.:This works in real life as well \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"I have done it for so many times, setting a cronjob. Today I was tring to set a simple cronjob which will output the log file with timestamp attached filename.&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[219,217,59,426,218],"class_list":{"0":"post-398","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-technical","7":"tag-date","8":"tag-find-yesterday-in-linux","9":"tag-linux","10":"tag-technical","11":"tag-tomorrow"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":2,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":1581,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/398\/revisions\/1581"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}