{"id":2970,"date":"2014-03-30T17:26:51","date_gmt":"2014-03-30T09:26:51","guid":{"rendered":"http:\/\/rmohan.com\/?p=2970"},"modified":"2014-03-30T17:26:51","modified_gmt":"2014-03-30T09:26:51","slug":"how-to-create-or-edit-a-crontab-file","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2970","title":{"rendered":"How to Create or Edit a crontab File"},"content":{"rendered":"<p><b>Before You Begin<\/b><\/p>\n<p>If you are creating or editing a <tt>crontab<\/tt> file that belongs to <tt>root<\/tt> or another user you must become root.<\/p>\n<p>You do not need to become <tt>root<\/tt> to edit your own <tt>crontab<\/tt> file.<\/p>\n<ol>\n<li><a name=\"SYSADV1SYSADV1sysrescron-step-7\"><\/a><a name=\"SYSADV1sysrescron-step-7\"><\/a><a name=\"SYSADV1sysrescron-step-7\"><\/a><a name=\"sysrescron-step-7\"><\/a><b>Create a new <tt>crontab<\/tt> file, or edit an existing file. <\/b>\n<pre># <b>crontab -e<\/b> [<var>username<\/var>]<\/pre>\n<p>where <var>username<\/var> specifies the name of the user&#8217;s account for which you want to create or edit a <tt>crontab<\/tt> file. You can create your own <tt>crontab<\/tt> file without superuser privileges, but you must have superuser privileges to creating or edit a <tt>crontab<\/tt> file for <tt>root<\/tt> or another user.<\/p>\n<div>\n<hr \/>\n<table>\n<tbody>\n<tr>\n<td><img decoding=\"async\" title=\"Caution\" alt=\"Caution\" src=\"http:\/\/docs.oracle.com\/cd\/E23824_01\/html\/821-1451\/graphics\/caution.gif\" border=\"0\" \/><\/td>\n<td><b>Caution &#8211; <\/b><a name=\"SYSADV1SYSADV1sysrescron-ix2537\"><\/a><a name=\"SYSADV1sysrescron-ix2537\"><\/a><a name=\"SYSADV1sysrescron-ix2537\"><\/a><a name=\"sysrescron-ix2537\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2538\"><\/a><a name=\"SYSADV1sysrescron-ix2538\"><\/a><a name=\"SYSADV1sysrescron-ix2538\"><\/a><a name=\"sysrescron-ix2538\"><\/a>If you accidentally type the <tt>crontab<\/tt> command with no option, press the interrupt character for your editor. This character allows you to quit without saving changes. If you instead saved changes and exited the file, the existing <tt>crontab<\/tt> file would be overwritten with an empty file.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<\/div>\n<\/li>\n<li><a name=\"SYSADV1SYSADV1sysrescron-step-8\"><\/a><a name=\"SYSADV1sysrescron-step-8\"><\/a><a name=\"SYSADV1sysrescron-step-8\"><\/a><a name=\"sysrescron-step-8\"><\/a><b>Add command lines to the <tt>crontab<\/tt> file.<\/b>Follow the syntax described in <a href=\"http:\/\/docs.oracle.com\/cd\/E23824_01\/html\/821-1451\/sysrescron-1.html#sysrescron-62861\">Syntax of <tt>crontab<\/tt> File Entries<\/a>. The <tt>crontab<\/tt> file will be placed in the <tt>\/var\/spool\/cron\/crontabs<\/tt> directory.<\/li>\n<li><a name=\"SYSADV1SYSADV1sysrescron-step-57\"><\/a><a name=\"SYSADV1sysrescron-step-57\"><\/a><a name=\"SYSADV1sysrescron-step-57\"><\/a><a name=\"sysrescron-step-57\"><\/a><b>Verify your <tt>crontab<\/tt> file changes.<\/b>\n<pre># <b>crontab -l<\/b> [<var>username<\/var>]<\/pre>\n<\/li>\n<\/ol>\n<p><a name=\"SYSADV1SYSADV1emjfd\"><\/a><a name=\"SYSADV1emjfd\"><\/a><a name=\"SYSADV1emjfd\"><\/a><a name=\"emjfd\"><\/a><\/p>\n<p><b>Example\u00a014-1 Creating a <tt>crontab<\/tt> File<\/b><\/p>\n<p>The following example shows how to create a <tt>crontab<\/tt> file for another user.<\/p>\n<pre># <b>crontab -e jones<\/b><\/pre>\n<p><a name=\"SYSADV1SYSADV1sysrescron-ix2542\"><\/a><a name=\"SYSADV1sysrescron-ix2542\"><\/a><a name=\"SYSADV1sysrescron-ix2542\"><\/a><a name=\"sysrescron-ix2542\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2544\"><\/a><a name=\"SYSADV1sysrescron-ix2544\"><\/a><a name=\"SYSADV1sysrescron-ix2544\"><\/a><a name=\"sysrescron-ix2544\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2547\"><\/a><a name=\"SYSADV1sysrescron-ix2547\"><\/a><a name=\"SYSADV1sysrescron-ix2547\"><\/a><a name=\"sysrescron-ix2547\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2549\"><\/a><a name=\"SYSADV1sysrescron-ix2549\"><\/a><a name=\"SYSADV1sysrescron-ix2549\"><\/a><a name=\"sysrescron-ix2549\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2550\"><\/a><a name=\"SYSADV1sysrescron-ix2550\"><\/a><a name=\"SYSADV1sysrescron-ix2550\"><\/a><a name=\"sysrescron-ix2550\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2551\"><\/a><a name=\"SYSADV1sysrescron-ix2551\"><\/a><a name=\"SYSADV1sysrescron-ix2551\"><\/a><a name=\"sysrescron-ix2551\"><\/a><a name=\"SYSADV1SYSADV1sysrescron-ix2552\"><\/a><a name=\"SYSADV1sysrescron-ix2552\"><\/a><a name=\"SYSADV1sysrescron-ix2552\"><\/a><a name=\"sysrescron-ix2552\"><\/a>The following command entry added to a new <tt>crontab<\/tt> file automatically removes any log files from the user&#8217;s home directory at 1:00 a.m. every Sunday morning. Because the command entry does not redirect output, redirect characters are added to the command line after <tt>*.log<\/tt>. Doing so ensures that the command executes properly.<\/p>\n<pre># This command helps clean up user accounts.\r\n1 0 * * 0 rm \/home\/jones\/*.log &gt; \/dev\/null 2&gt;&amp;1<\/pre>\n<p><a name=\"SYSADV1SYSADV1enmxc\"><\/a><a name=\"SYSADV1enmxc\"><\/a><a name=\"SYSADV1enmxc\"><\/a><a name=\"enmxc\"><\/a><\/p>\n<h2>How to Verify That a <tt>crontab<\/tt> File Exists<\/h2>\n<p><b>To verify that a <tt>crontab<\/tt> file exists for a user, use the <tt>ls -l<\/tt> command in the <tt>\/var\/spool\/cron\/crontabs<\/tt> directory. For example, the following output shows that <tt>crontab<\/tt> files exist for users <tt>jones<\/tt> and <tt>smith<\/tt>. <\/b><\/p>\n<pre>$ <b>ls -l \/var\/spool\/cron\/crontabs<\/b><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Before You Begin<\/p>\n<p>If you are creating or editing a crontab file that belongs to root or another user you must become root.<\/p>\n<p>You do not need to become root to edit your own crontab file.<\/p>\n<p> Create a new crontab file, or edit an existing file. # crontab -e [username] <\/p>\n<p>where username specifies the name [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2970"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2970"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2970\/revisions"}],"predecessor-version":[{"id":2971,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2970\/revisions\/2971"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}