Additional Scripts For User.Scripts Plugin


Recommended Posts

#!/bin/bash

DIR="/mnt/user/media/movies/MOVIE_FOLDER/"

find "$DIR" -type f -name '*.mkv' | while read filepath; do
docker exec MKVToolNix /usr/bin/mkvmerge -J "$filepath"
done

 

I am trying to write script that use mkvtoolnix container to process my movie files

 

in line: docker exec MKVToolNix /usr/bin/mkvmerge -J "$filepath" i get error

Quote

"The file '/mnt/user/media/movies/MOVIE_FOLDER/MOVIE_FILE.mkv' could not be opened for reading: open file error.\n"

i don't know why script can't read this file

Link to comment

I read https://docs.unraid.net/legacy/FAQ/shrink-array/ and followed the link for step 8 "Run the clear an array drive script" that took me to 

 the comment that has a download link for the "clear_array_drive" script.

I tried running it but got an error.

```

Found a marked and empty drive to clear:  Disk 3  ( /mnt/disk3 )
+ echo -e '* Disk 3 will be unmounted first.'
* Disk 3 will be unmounted first.
+ echo '* Then zeroes will be written to the entire drive.'
* Then zeroes will be written to the entire drive.
+ echo '* Parity will be preserved throughout.'
* Parity will be preserved throughout.
+ echo '* Clearing while updating Parity takes a VERY long time!'
* Clearing while updating Parity takes a VERY long time!
+ echo '* The progress of the clearing will not be visible until it'\''s done!'
* The progress of the clearing will not be visible until it's done!
+ echo '* When complete, Disk 3 will be ready for removal from array.'
* When complete, Disk 3 will be ready for removal from array.
+ echo -e '* Commands to be executed:\n***** \x1b[36;01m umount /mnt/disk3 \x1b[39;49;00m\n***** \x1b[36;01m dd bs=1M if=/dev/zero of=/dev/md3  \x1b[39;49;00m\n'
* Commands to be executed:
*****  umount /mnt/disk3
*****  dd bs=1M if=/dev/zero of=/dev/md3

+ '[' clear_array_drive == /tmp/user.scripts/ ']'
+ echo -n 'Press ! to proceed. Any other key aborts, with no changes made. '
Press ! to proceed. Any other key aborts, with no changes made. + ch=
+ read -n 1 ch
!+ echo -e -n '\r                                                                  \r'
+ '[' '!' '!=' '!' ']'
+ logger -tclear_array_drive 'Clear an unRAID array data drive  v1.4'
+ echo -e '\rUnmounting Disk 3 ...'
Unmounting Disk 3 ...
+ logger -tclear_array_drive 'Unmounting Disk 3  (command: umount /mnt/disk3 ) ...'
+ umount /mnt/disk3
+ echo -e 'Clearing   Disk 3 ...'
Clearing   Disk 3 ...
+ logger -tclear_array_drive 'Clearing Disk 3  (command: dd bs=1M if=/dev/zero of=/dev/md3  ) ...'
+ dd bs=1M if=/dev/zero of=/dev/md3
dd: error writing '/dev/md3': No space left on device
9+0 records in
8+0 records out
8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.00256501 s, 3.3 GB/s
+ logger -tclear_array_drive 'Clearing Disk 3 is complete'
+ echo -e '\nA message saying "error writing ... no space left" is expected, NOT an error.\n'

A message saying "error writing ... no space left" is expected, NOT an error.

+ echo -e 'Unless errors appeared, the drive is now cleared!'
Unless errors appeared, the drive is now cleared!
+ echo -e 'Because the drive is now unmountable, the array should be stopped,'
Because the drive is now unmountable, the array should be stopped,
+ echo -e 'and the drive removed (or reformatted).'
and the drive removed (or reformatted).
+ exit

```

I ran the script with `sh -x` so there's debug output. I see it uses `/dev/mdX` not `/dev/mdXp1`. Is that the issue? Are people using this script? Do I have an old version of the script? Here's the download link for the script from the comment by RobJ https://s3-us-west-2.amazonaws.com/upload.forums.unraid.net/live/monthly_2016_09/clear_an_array_drive_zip.80cc67c667b13547f490de09b702bf4b

I also searched this topic for "of=/dev/md" and I didn't see any references that included the "p1".

Link to comment
  • 2 weeks later...

I cannot get the script working anymore with Unraid 6.12.8.

I finished with successfull after about 30 seconds, leaving the array with in a state with unmounted drive that prevents clean shutdown of the array and enforces a "unclean shutdown detected" parity check.

After reboot / array restart the drive is back with the clear-me folder inside.

Link to comment
On 10/29/2016 at 12:56 PM, Squid said:

Run A Custom Script At Parity Check / Rebuild Start And Stop

Use it to run a custom script to (as an example), shut down various docker applications, etc.  Adjust the variables within the script file.

 

Note that you either need to run this in the background or at array start.  Running this in the foreground will not work.

 

 

#!/usr/bin/php
<?PHP
# A simple script to allow you to run a custom script when a parity check starts or stops
# Adjust the following variables to suit:

$checkInterval = 300;                             # Number of seconds in between checks
$startScript   = "full path to the script";       # The full path to the script to run when a parity check starts
$stopScript    = "full path to the stop script";  # The full path to the script to run when a parity check stops

# Don't touch anything below

while (true) {
  $vars = parse_ini_file("/var/local/emhttp/var.ini");
  if ( $vars['mdState'] == "STOPPED" ) {
    break;
  }
  if ( ($vars['mdResyncPos'] != 0) && $vars ) {
    echo "Parity Check / Sync / Rebuild in progress.  Executing the start script ($startScript)";
    exec($startScript,$output);
    foreach ($output as $line) {
      echo $line."\n";
    }
    while (true) {
      $vars = parse_ini_file("var/local/emhttp/var.ini");
      if ( ($vars['mdResyncPos'] == 0) && $vars ) {
        echo "Parity Check / Sync / Rebuild finished.  Executing the stop script ($stopScript)";
        exec($stopScript,$output);
        foreach ($output as $line) {
          echo $line."\n";
        }
        break;
      } else {
        sleep($checkInterval);
      }
    }
  } else { 
    sleep($checkInterval);
  }  
}
?>
 

 

custom_script_parity_check_start_stop.zip 1010 B · 64 downloads

Is there a way to modify this script to consider a paused parity operation as stopped/finished?

Edited by Shomesomesho
Link to comment
17 hours ago, Shomesomesho said:

Is there a way to modify this script to consider a paused parity operation as stopped/finished?

What is it you actually want to do if the check is paused?   There may be a better way to achieve this.?

 

Also what is the Use Case you have for even running a script at start/end?    Just asking as if it is a good one I could consider adding support for this as a standard feature in the Parity Check Tuning plugin.

Link to comment
5 hours ago, itimpi said:

What is it you actually want to do if the check is paused?   There may be a better way to achieve this.?

 

Also what is the Use Case you have for even running a script at start/end?    Just asking as if it is a good one I could consider adding support for this as a standard feature in the Parity Check Tuning plugin.

https://old.reddit.com/r/unRAID/comments/1byaqxn/scripts_to_pause_torrents_during_parity/

 

Seeding torrents from the array slows down a parity operation. I'd rather pause the seeding than slow down the parity operation. I don't want to close the torrent client completely, as that stops downloads to the cache. And without pause being recognized as a stop/end, and using the Increments feature of Parity Check Tuning plugin means the torrent docker would remain shut down for days until the parity operation is finished.

Edited by Shomesomesho
Link to comment
Just now, Shomesomesho said:

https://old.reddit.com/r/unRAID/comments/1byaqxn/scripts_to_pause_torrents_during_parity/

 

Seeding torrents from the array slows down parity operation. I'd rather pause the seeding than slow down the parity operation. I don't want to close the torrent client completely, as that stops downloads to the cache. And without pause being recognized as a stop/end, and using the Increments feature of Parity Check Tuning plugin means the torrent docker would remain shut down for days until the parity operation is finished.


from an earlier request I have been working on an option to pause (rather than stop) user specified  docker containers during parity operations and resume them when an increment ends.   Sounds like that might satisfy this need without the need for a script?

Link to comment
1 minute ago, itimpi said:


from an earlier request I have been working on an option to pause (rather than stop) user specified  docker containers during parity operations and resume them when an increment ends.   Sounds like that might satisfy this need without the need for a script?

Unfortunately that would prevent being able to download to a cache pool during an increment.

Link to comment
13 hours ago, Shomesomesho said:

Unfortunately that would prevent being able to download to a cache pool during an increment.

 

Some people use separate containers for downloading and seeding, could be a solution.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.