{"id":14263,"date":"2024-02-18T20:13:35","date_gmt":"2024-02-18T19:13:35","guid":{"rendered":"https:\/\/linux-bibel.at\/?p=14263"},"modified":"2024-02-18T20:13:37","modified_gmt":"2024-02-18T19:13:37","slug":"cron-scripte-unter-etc-cron-unter-linux","status":"publish","type":"post","link":"https:\/\/linux-bibel.at\/index.php\/2024\/02\/18\/cron-scripte-unter-etc-cron-unter-linux\/","title":{"rendered":"Cron-Scripte unter \/etc\/cron. unter Linux"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Mit <a href=\"https:\/\/linux-bibel.at\/index.php\/2023\/09\/09\/aufgaben-mit-cron-unter-linux-automatisieren\/\" data-type=\"post\" data-id=\"1662\">Cron<\/a> l\u00e4sst sich unter Linux so gut wie alles automatisieren &#8211; als normaler Benutzer nutzt man dabei seine eigene Crontab:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Als root gelingt dies nat\u00fcrlich auch &#8211; l\u00e4ngere Befehle mit vielen Optionen k\u00f6nnen in der Crontab aber recht un\u00fcbersichtlich sein. Ein Script mit der Crontab zu starten, ist so gesehen eigentlich auch etwas umst\u00e4ndlich. Ganze Scripte legt man am einfachsten als root unter &#8222;<em>\/etc\/cron.x<\/em>&#8220; ab:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\/etc\/cron.daily<\/strong> &#8211; Scripte in diesem Verzeichnis werden einmal t\u00e4glich ausgef\u00fchrt.<\/li>\n\n\n\n<li><strong>\/etc\/cron.hourly<\/strong> &#8211; Scripte in diesem Verzeichnis werden einmal st\u00fcndlich ausgef\u00fchrt.<\/li>\n\n\n\n<li><strong>\/etc\/cron.monthly<\/strong> &#8211; Scripte in diesem Verzeichnis werden einmal im Monat ausgef\u00fchrt.<\/li>\n\n\n\n<li><strong>\/etc\/cron.weekly<\/strong> &#8211; Scripte in diesem Verzeichnis werden einmal in der Woche ausgef\u00fchrt.<\/li>\n\n\n\n<li><strong>\/etc\/cron.yearly<\/strong> &#8211; Scripte in diesem Verzeichnis werden einmal im Jahr ausgef\u00fchrt.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Sie k\u00f6nnen hier ganz normale Scripte ablegen, wie Sie diese auch sonst erstellen und benutzen &#8211; etwas \u00fcber das ich gestolpert bin, die Dateien d\u00fcrfen jedoch keine Dateiendung haben. Ein normales Bash-Script w\u00fcrde ich etwa so nennen &#8211; &#8222;<strong>dateiname.sh<\/strong>&#8222;, ein solches Script w\u00fcrde jedoch nicht ausgef\u00fchrt werden. Sie m\u00fcssen die Endung weglassen &#8211; im Beispiel also &#8222;<strong>dateiname<\/strong>&#8222;, dies gilt f\u00fcr Bash-Scripte, f\u00fcr Python-Scripte, Perl-Scripte, f\u00fcr alle Arten von Scripts, welche auch immer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ob ein Script auch wirklich ausgef\u00fchrt wird, pr\u00fcfen Sie mit folgendem Befehl &#8211; im Beispiel die Scripte unter &#8222;<em>\/etc\/cron.daily<\/em>&#8220; (<em>nat\u00fcrlich als root<\/em>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>run-parts --report --test \/etc\/cron.daily\/<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron.jpeg\" rel=\"lightbox-0\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"595\" src=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-1024x595.jpeg\" alt=\"\" class=\"wp-image-14264\" srcset=\"https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-1024x595.jpeg 1024w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-1536x893.jpeg 1536w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-2048x1191.jpeg 2048w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-150x87.jpeg 150w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-300x174.jpeg 300w, https:\/\/linux-bibel.at\/wp-content\/uploads\/2024\/02\/cron-768x447.jpeg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Ein Script das hier nicht aufgelistet wird, wird auch nicht ausgef\u00fchrt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mit Cron l\u00e4sst sich unter Linux so gut wie alles automatisieren &#8211; als normaler Benutzer nutzt man dabei seine eigene Crontab: Als root gelingt dies nat\u00fcrlich auch &#8211; l\u00e4ngere Befehle mit vielen Optionen k\u00f6nnen in der Crontab aber recht un\u00fcbersichtlich sein. Ein Script mit der Crontab zu starten, ist so gesehen eigentlich auch etwas umst\u00e4ndlich. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14264,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[15],"class_list":["post-14263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system","tag-system"],"_links":{"self":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/14263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/comments?post=14263"}],"version-history":[{"count":1,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/14263\/revisions"}],"predecessor-version":[{"id":14265,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/posts\/14263\/revisions\/14265"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media\/14264"}],"wp:attachment":[{"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/media?parent=14263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/categories?post=14263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux-bibel.at\/index.php\/wp-json\/wp\/v2\/tags?post=14263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}