{"id":375,"date":"2010-02-08T20:41:29","date_gmt":"2010-02-09T01:41:29","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=375"},"modified":"2010-02-08T20:41:29","modified_gmt":"2010-02-09T01:41:29","slug":"the-whole-crontab-thingy","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/the-whole-crontab-thingy\/","title":{"rendered":"The whole crontab thingy"},"content":{"rendered":"<p>The other day I needed to have a job run daily. My two efforts at solving this problem failed. These were:<\/p>\n<p>1. Ask the six people hanging around for no particular reason how to do it. All vaguely remembered learning that at some point and had forgotten specifically how to do it.<\/p>\n<p>2. Using Google to see if I could find exactly how to do it in five minutes or less which was the amount of time I was willing to stick around after the end of an annoying day.<\/p>\n<p>There are man pages but I have never been able to read a man page without wanting to find the people who wrote it and slap them.<\/p>\n<blockquote><p><em>&#8220;NAME<br \/>\ncrontab &#8211; maintain crontab files for individual users (ISC Cron V4.1)<\/p>\n<p>SYNOPSIS<br \/>\ncrontab [-u user] file<br \/>\ncrontab [-u user] [-l | -r | -e] [-i] [-s]<\/p>\n<p>DESCRIPTION<br \/>\nCrontab\u00a0 is\u00a0 the\u00a0 program\u00a0 used to install, deinstall or list the tables used to drive the cron(8) daemon in ISC Cron.\u00a0 Each user can have their own crontab, and though these are files in \/var\/spool\/ , they are\u00a0 not\u00a0 intended to\u00a0 be\u00a0 edited\u00a0 directly.\u00a0 For\u00a0 SELinux\u00a0 in\u00a0 mls\u00a0 mode\u00a0 can be even more crontabs &#8211; for each range. For more see selinux(8).<\/p>\n<p>If the cron.allow file exists, then you must be listed therein in order to be allowed to use this\u00a0 command.\u00a0\u00a0 If the\u00a0 cron.allow\u00a0 file\u00a0 does\u00a0 not\u00a0 exist\u00a0 but\u00a0 the\u00a0 cron.deny file does exist, then you must not be listed in the cron.deny file in order to use this command.\u00a0 If neither of these files exists, only\u00a0 the\u00a0 super\u00a0 user\u00a0 will\u00a0 be allowed to use this command.<\/p>\n<p>OPTIONS<br \/>\n-u\u00a0\u00a0\u00a0\u00a0 It\u00a0 specifies\u00a0 the name of the user whose crontab is to be tweaked.\u00a0 If this option is not given, crontab examines &#8220;your&#8221; crontab, i.e., the crontab of the person executing the command.\u00a0 Note that su(8) can confuse crontab and that if you are running inside of su(8) you should always use the -u option for safety&#8217;s sake.\u00a0 The first form of this command is used to install a new crontab from some named file\u00a0 or\u00a0 standard input if the pseudo-filename &#8220;-&#8221; is given.&#8221;<\/em><\/p><\/blockquote>\n<p>I mean, seriously, if that kind of thing is clear to you, you were raised by aliens. Joe, the sysadmin who was standing here five minutes ago disagrees. You know that means? It means Joe is wrong.<\/p>\n<p><strong>What a cron job is &amp; how to see what cron jobs you have<\/strong><\/p>\n<p>A cron job is simply a job that runs at a certain time. A crontab is a table listing all the cron jobs.<\/p>\n<p>To see the list of cron jobs in your account, log in and type<\/p>\n<p>crontab -l<\/p>\n<p>You should see something that looks like this:<\/p>\n<p>00 08 * * *\u00a0 \/usr\/joeblow\/sas\/default\/bin\/sas dir1\/dir2\/joesdayjob.sas<br \/>\n30 07 * * 1\u00a0 \/usr\/joeblow\/sas\/default\/bin\/sas dir1\/sub1\/joesweekend.sas<br \/>\n31 07 1 * *\u00a0 \/usr\/usc\/sas\/default\/bin\/sas dir2\/sub1\/monthlything.sas<br \/>\n20 08 * * * mail -s\u00a0 ademars@usc.edu &lt; dir1\/dir2\/things.txt<\/p>\n<p>There are six fields in a cron job. The first one is minutes, the second is hours. Hours are on a 24-hour clock. The third field is day of the month, the fourth is month and the fifth is day of the week. Day of the week is 1= Monday through 7= Sunday. The last field is the command you want executed.<\/p>\n<p>So, the first job above runs at 8 a.m. every day. It runs a job called joesdayjob.sas<\/p>\n<p>The second job runs at 7:30 a.m. every Monday. It runs a job called joesweekend.sas<\/p>\n<p>The third job runs at 7:31 a.m. on the first day of every month. It runs a job called monthlything.sas<\/p>\n<p>The final job runs at 8:20 a.m. each day. It mails a file to me that is created at the end of the daily job just to tell me how frigging awesome I am. At the end of the daily job, SAS creates a file called things.txt . When everything is working it will send a message that says:<\/p>\n<p><em>You are just unbelievably awesome. <\/em><\/p>\n<p>If the job does not run successfully, I will get an error message and be sad, also, not awesome.<\/p>\n<p>To change the recipient of the message, because, say, I go on vacation or get hit by a truck or something, a person could just change the email in the last line of the crontab.<\/p>\n<p><strong>How to edit your cron job<\/strong><\/p>\n<p><em>Please don&#8217;t do this unless you know what you are doing because if you delete the crontab, which is the table of cron jobs, and they all stop running, if some of them were my\u00a0 jobs I would be most annoyed.<br \/>\n<\/em><\/p>\n<p>crontab -e<\/p>\n<p>This will bring up the emacs editor. Add your job at the bottom. That way, if it has an error, the other jobs should run and only yours will be messed up, and so you have only caused trouble for yourself and not other people.<\/p>\n<p>Save the file. That&#8217;s it.<\/p>\n<p>Now, next time I google this I will find it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I needed to have a job run daily. My two efforts at solving this problem failed. These were: 1. Ask the six people hanging around for no particular reason how to do it. All vaguely remembered learning that at some point and had forgotten specifically how to do it. 2. Using Google&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-375","post","type-post","status-publish","format-standard","hentry","category-technology"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":2,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}