{"id":2657,"date":"2016-11-20T17:57:22","date_gmt":"2016-11-20T04:57:22","guid":{"rendered":"http:\/\/www.zoyinc.com\/?p=2657"},"modified":"2016-11-20T17:58:32","modified_gmt":"2016-11-20T04:58:32","slug":"scheduling-a-task-in-open-media-vault","status":"publish","type":"post","link":"http:\/\/www.zoyinc.com\/?p=2657","title":{"rendered":"Scheduling a task in Open Media Vault"},"content":{"rendered":"<p>I need to run some scripts every night to move some files around in OMV. I want something that simple and easy to maintain and more or less stock standard.<\/p>\n<p>There are probably many variations on how this could be done but this is how I chose to do it.<\/p>\n<p>Before we start it is worth noting I have my RAID mounted by OMV at:<\/p>\n<p style=\"padding-left: 30px;\">\/media\/f20b47a4-d207-40aa-a7e6-42ea82354455<\/p>\n<table class=\"zsteps\">\n<tbody>\n<tr>\n<td>1.<\/td>\n<td>Ensure you have enabled home directories for users. I created a shared folder called &#8220;\/home&#8221; and\u00a0 enable this in &#8220;Access Rights Management | Users | Settings&#8221;:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2661\" src=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks01.jpg\" alt=\"Users Settings\" width=\"250\" height=\"122\" srcset=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks01.jpg 250w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks01-150x73.jpg 150w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/td>\n<\/tr>\n<tr>\n<td>2.<\/td>\n<td>Create a user called &#8220;scheduledtasks&#8221; and make a member of the groups as all your other users. As a result this user should have a home directory along the lines of:<\/p>\n<p style=\"padding-left: 30px;\">\/media\/f20b47a4-d207-40aa-a7e6-42ea82354455\/home\/scheduledtasks<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>3.<\/td>\n<td>Create a shared folder called &#8220;scheduled_jobs&#8221;, I would also add this as a windows\/smb shared folder.<\/td>\n<\/tr>\n<tr>\n<td>4.<\/td>\n<td>In this folder create a simple shell script:<\/p>\n<pre class=\"crayon:false;\">#!\/bin\/sh\r\necho \"Running script \/scheduled_jobs\/test.sh\"<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td>5.<\/td>\n<td>Create a scheduled task with a command of:<\/p>\n<pre class=\"crayon:false;\">bash ~\/..\/..\/scheduled_jobs\/test.sh<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2662 size-full\" src=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks02.jpg\" alt=\"Scheduled task\" width=\"330\" height=\"178\" srcset=\"http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks02.jpg 330w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks02-150x81.jpg 150w, http:\/\/www.zoyinc.com\/wp-content\/uploads\/2016\/11\/OMVScheduledTasks02-300x162.jpg 300w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/td>\n<\/tr>\n<tr>\n<td>6.<\/td>\n<td>Once you have saved the task click on the &#8220;Run&#8221; button to show the dialog to &#8220;Execute cron job&#8221; &#8211; click on &#8220;Start&#8221;. It should return &#8220;Running script \/scheduled_jobs\/test.sh&#8221;, which is of course the echo command inside the script.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>When I setup a real task I found that for the types of task I wanted to do, including mounting SMB shares I needed to run it as root. This meant that I needed to specify the full path to my RAID drive. Thus my scripts started like:<\/p>\n<pre class=\"crayon:false; \">#!\/bin\/sh\r\n#\r\n# Script to archive appropriate folders\r\n# to the Archive folder.\r\n#\r\n# Tony Paterson\r\n# May 2007\r\n#\r\nRAIDRoot=\"<span style=\"background-color: #ffff00;\">\/media\/f20b47a4-d207-40aa-a7e6-42ea82354455<\/span>\"\r\n\r\n# Source function library.\r\nif [ -x \/etc\/rc.d\/init.d\/functions ]; then\r\n. \/etc\/rc.d\/init.d\/functions\r\nfi\r\n\r\n#\r\n# Get the date in the format \"Day of Week\" and time\r\n# This will mean that we will effectively keep a weeks backup\r\n#\r\nSHORTDATE=`date +%a`\r\n\r\n\r\n#\r\n# User config section\r\n#\r\nArchiveFolder=\"${RAIDRoot}\/backups\/daily\/essentials\"\r\nLogDir=\"${RAIDRoot}\/backups\/daily\/logs\"\r\nLOGFILE=\"${LogDir}\/backup_essentials.log\"\r\n\r\n#\r\n# archive folder exists\r\n#\r\necho \"Creating Backup Directory...\"\r\necho \"Creating Backup Directory...\" &gt;&gt; $LOGFILE\r\nsu - root -c\u00a0 \"rm -Rf ${ArchiveFolder}\"\r\nsu - root -c\u00a0 \"mkdir -p -v\u00a0 ${ArchiveFolder} \"<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I need to run some scripts every night to move some files around in OMV. I want something that simple and easy to maintain and more or less stock standard. There are probably many variations on how this could be done but this is how I chose to do it. Before we start it is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[312,313],"tags":[209,295,319,320,364],"class_list":["post-2657","post","type-post","status-publish","format-standard","hentry","category-debian","category-open-media-vault","tag-cron","tag-linux","tag-omv","tag-open-media-vault","tag-scheduled-task"],"_links":{"self":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/2657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2657"}],"version-history":[{"count":4,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions"}],"predecessor-version":[{"id":2664,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions\/2664"}],"wp:attachment":[{"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2657"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zoyinc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}