{"id":1409,"date":"2021-10-26T13:25:21","date_gmt":"2021-10-26T11:25:21","guid":{"rendered":"https:\/\/www.web-workers.ch\/?p=1409"},"modified":"2021-10-26T13:25:21","modified_gmt":"2021-10-26T11:25:21","slug":"how-to-add-custom-scripts-on-qnap-nas-devices","status":"publish","type":"post","link":"https:\/\/www.web-workers.ch\/index.php\/2021\/10\/26\/how-to-add-custom-scripts-on-qnap-nas-devices\/","title":{"rendered":"How to add custom scripts on QNAP NAS devices"},"content":{"rendered":"<p>You can add custom scripts to the crontab on your QNAP NAS box. I&#8217;ll use it to create a timestamp file in a directory that will be synchronized in real time to a off-site NAS. I&#8217;ll check at the off-site NAS if the file is periodically updated to be sure the synchronization is working.<\/p>\r\n<h5>List your crontab contents<\/h5>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>crontab -l<\/code><\/pre>\r\n<\/div>\r\n<h5>Adding entries via command-line<\/h5>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>echo \"1 4 * * * \/share\/custom\/scripts\/custom1.sh\" &gt;&gt; \/etc\/config\/crontab\r\necho \"40 5 * * * \/share\/custom\/scripts\/custom2.sh\" &gt;&gt; \/etc\/config\/crontab<\/code><\/pre>\r\n<\/div>\r\n<p>Create the required crontab timeformat here: <a href=\"https:\/\/crontab.guru\/\">https:\/\/crontab.guru<\/a><\/p>\r\n<h5>Modifying entries<\/h5>\r\n<p>Do NOT edit crontab the usual way! On a desktop or server distribution, you would edit a user&#8217;s crontab with:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>crontab -e<\/code><\/pre>\r\n<\/div>\r\n<p>However, due to the way the QNAP firmware updates crontab, it will be overwritten on the next reboot. Obviously, you want your automation to survive reboots, so edit the crontab file directly with your text editor:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>vi \/etc\/config\/crontab<\/code><\/pre>\r\n<\/div>\r\n<p>or<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>nano \/etc\/config\/crontab<\/code><\/pre>\r\n<\/div>\r\n<h5>Restart the daemon<\/h5>\r\n<p>When you&#8217;re done, reload the crontab file and restart the cron daemon:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>crontab \/etc\/config\/crontab &amp;&amp; \/etc\/init.d\/crond.sh restart<\/code><\/pre>\r\n<\/div>\r\n<h5>Example of timestamp file for monitoring purposes<\/h5>\r\n<p>This sample prints the current timestamp to a file. We&#8217;ll monitor off-site the last change date of the file.<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code>*\/30 * * * * echo $(date -u) &gt; \/share\/CACHEDEV1_DATA\/allgemein\/timestamp.txt 2&gt;&amp;1<\/code><\/pre>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>You can add custom scripts to the crontab on your QNAP NAS box. I&#8217;ll use it to create a timestamp file in a directory that will be synchronized in real [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1413,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,147],"tags":[149,10,148,150],"class_list":["post-1409","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-qnap","tag-crontab","tag-linux","tag-qnap","tag-qts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2021\/10\/QNAP-Oberflache-1024x4891-1.jpg?fit=1024%2C489&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8sxjX-mJ","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":5,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"predecessor-version":[{"id":1416,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1409\/revisions\/1416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media\/1413"}],"wp:attachment":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}