Jump to content
Squid

Additional Scripts For User.Scripts Plugin

313 posts in this topic Last Reply

Recommended Posts

12 hours ago, Squid said:

#!/bin/bash
docker pause binhex-sonarr
docker pause binhex-radarr
docker pause binhex-delugevpn

 

Thanks squid. I notice the script in the zip file has windows CRLF line breaks. Is it supposed to?

Share this post


Link to post
2 hours ago, wgstarks said:

Thanks squid. I notice the script in the zip file has windows CRLF line breaks. Is it supposed to?

Anything user.scripts directly runs it automatically converts any CRLF to be CR.

 

Any script that the script itself may call will have to be CR only

Share this post


Link to post

Can't get it to work when I set the schedule to "array start". It locks up the webUI completely if I stop and then start the array. Also triggers an unclean shutdown warning from FCP.

 

User Scripts script-

#!/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   = "/boot/scripts/docker_start_stop_parity/docker_stop_parity.sh";       # The full path to the script to run when a parity check starts
$stopScript    = "/boot/scripts/docker_start_stop_parity/docker_start_parity.sh";  # 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);
  }  
}
?>

docker_stop_parity.sh-

#!/bin/bash
docker stop -t=45 binhex-radarr
docker stop -t=45 binhex-sonarr
docker stop -t=45 binhex-delugevpn

 

 

docker_start_ parity.sh-

#!/bin/bash
docker start binhex-delugevpn
docker start binhex-sonarr
docker start binhex-radarr

 

 

file path to scripts-

FinderScreenSnapz016.jpg.ee83bd9fd012cd193bfe845844a601b4.jpg

 

 

I checked the start/stop scripts from CLI and they work as expected. If I use the "background" button the User Scripts Plugin shows the script as "Running". Not sure what I'm missing here? I've attached a diagnostics as well.

 

brunnhilde-diagnostics-20170929-2108.zip

Share this post


Link to post

Been trying different options, but none seem to work. If this script is set to run at array start the array fails to start. It just hangs. Tried adding the background only option but no luck. The only way I can get the script to run is to manually launch it in the background.

Share this post


Link to post
20 minutes ago, wgstarks said:

Been trying different options, but none seem to work. If this script is set to run at array start the array fails to start. It just hangs. Tried adding the background only option but no luck. The only way I can get the script to run is to manually launch it in the background.

ok.  Can't test everything when I did the script itself.

 

Save that script on the flash drive in your scripts folder as parity_test.php (make sure that it's CR not CRLF)

 

Add a script to user scripts that is:

#!/bin/bash
/boot/scripts/docker_start_stop_parity/parity_test.php &

Setting it to run at array_start should now work

 

Share this post


Link to post
1 hour ago, Squid said:

make sure that it's CR not CRLF

 

Linux uses LF ...

Share this post


Link to post
Just now, bonienl said:

 

Linux uses LF ...

I just woke up...

Share this post


Link to post

Thanks squid. I think that worked. At least the launcher ran at array start. Guess I'll find out about the background docker start/stop script when my next parity check starts in a couple of days. Coming from you, I'm sure there won't be any issues with it either.  8)  :D

Share this post


Link to post

Check plugin integrity

 

Prior to inclusion in FCP, I'd like to get this script out to see if I'm just opening a can of worms and/or don't have a clue about what I'm doing  :D

 

This script will confirm the files downloaded by a plugin and stored on the flash drive actually match what the author intended (since unRaid only checks the files when they are actually downloaded, and upon a reboot it assumes that the file(s) stored on the flash are correct and does not confirm the checksums again when reinstalling at boot)

 

This script does require Community Applications to be installed, and if adding the script via Add Script in user.scripts, ensure you delete the opening #!/bin/bash that user scripts automatically pops into the script for you.

 

script

 

#!/usr/bin/php
<?
require_once("/usr/local/emhttp/plugins/community.applications/include/xmlHelpers.php");

$allPlugins = glob("/boot/config/plugins/*.plg");
foreach ($allPlugins as $plg) {
  $xml = file_get_contents($plg);
  $o = TypeConverter::xmlToArray($xml,TypeConverter::XML_GROUP);
  if ( ! $o ) {
    echo "<font color='red'>$plg is corrupted and is not a valid plugin file</font>\n";
    continue;
  }
  $plgName = str_replace(".plg","",basename($plg));
  $flag = false;
  foreach ($o['FILE'] as $file) {
    if ( !$file['@attributes']['Name'] || !$file['value']['MD5'] ) {
      continue;
    }
    if ( ! is_file($file['@attributes']['Name']) ) {
      echo "<font color='red'>$plgName: ".$file['@attributes']['Name']." included in plugin, but not present on flash drive\n";
      continue;
    }
    $flag = true;
    echo "$plgName: Testing {$file['@attributes']['Name']}... ";
    if ( md5_file($file['@attributes']['Name']) == $file['value']['MD5'] ) {
      echo "Passed\n";
    } else {
      echo "<font color='red'>Failed!</font> Calculated: ".md5_file($file['@attributes']['Name'])."   Should Be:".$file['value']['MD5']."\n";
      exec("/usr/local/emhttp/plugins/dynamix/scripts/notify -e '$plgName Failed Integrity Check' -i 'alert'");
    }
  }
  if ( ! $flag ) {
    echo "$plgName has no MD5's present\n";
  }
}
?>

 

 

Edited by Squid

Share this post


Link to post
3 hours ago, Squid said:

Check plugin integrity

 

This works really well, and seems like a really useful feature for FCP.

 

The only issue I see is for something like the speedtest plugin:
  https://github.com/dmacias72/unRAID-plugins/blob/master/plugins/speedtest.plg 
which installs different versions of python depending on the version of unRAID:

<FILE Name="&plgPATH;/python-2.7.14-x86_64-1.txz" Min="6.4" Run="upgradepkg --install-new">
<FILE Name="&plgPATH;/python-2.7.13a-x86_64-2.txz" Min="6.2" Max="6.3.99" Run="upgradepkg --install-new">
<FILE Name="&plgPATH;/python-2.7.9-x86_64-1.txz" Max="6.1.99" Run="/sbin/upgradepkg --install-new">

Currently this script tests all three of them:

speedtest: Testing /boot/config/plugins/speedtest/python-2.7.14-x86_64-1.txz... Passed
speedtest: Testing /boot/config/plugins/speedtest/python-2.7.13a-x86_64-2.txz... Passed
speedtest: /boot/config/plugins/speedtest/python-2.7.9-x86_64-1.txz included in plugin, but not present on flash drive

I wouldn't really want an FCP warning about a missing 6.1 package, can it evaluate the min/max attributes and only test the one that applies? I suppose it could potentially tell you to delete the older packages too.

Edited by ljm42

Share this post


Link to post
9 hours ago, ljm42 said:

I wouldn't really want an FCP warning about a missing 6.1 package, can it evaluate the min/max attributes and only test the one that applies? I suppose it could potentially tell you to delete the older packages too.

And that's why its a script at this time.

Share this post


Link to post

I LOVE this plugin along with UD for automated backups!  Thanks Squid :)

 

TOWER is the primary storage device with SMB shares, some private

TOWER2 is a backup of TOWER, with no SMB/NFS shares.  This also happens to be a lowly D525!

 

All on TOWER2

Use the Unassigned Devices Plugin to Mount a SMB share to your unRAID Source machine for each source to be backed up.  Set Unassigned Devices settings page SMB share to yes, hidden, fully private.

 

Use the User Scripts Plugin and add 2 scripts which can then be scheduled or run on demand from the plugin 


#Backup script to write once, never update
rsync -r -v --progress --ignore-existing -s /mnt/disks/TOWER_Media/Movies/ /mnt/user/Media/Movies
rsync -r -v --progress --ignore-existing -s /mnt/disks/TOWER_Media/Music/ /mnt/user/Media/Music

 

#Backup to sync all

rsync -av --progress --delete-before /mnt/disks/TOWER_Work/ /mnt/user/Work

rsync -av --progress --delete-before /mnt/disks/TOWER_Docs/ /mnt/user/Docs

 

(note that my write once, never update are local files only as the physical media is all in my crawl - my sync all have historical snapshots captured via the crashplan pro docker on TOWER)

Edited by landS

Share this post


Link to post
On 7/16/2016 at 9:02 PM, Squid said:

delete.DS_Store Files


#!/bin/bash
echo "Searching for (and deleting) .DS_Store Files"
echo "This may take a awhile"
find /mnt/user -maxdepth 9999 -noleaf -type f -name ".DS_Store" -exec rm "{}" \;

 

can this script be duplicated for removing other items?

for example if i replace ".DS_Store" with ".trash-1000" will it remove the .trash-1000 folder and all subfolders/subfiles on each disk when present?

 

as the .trash-1000 ends up in the root of any given share, can the maxdepth be set to 1?

 

Thanks!

Share this post


Link to post

Im running the script from the post:

 

following the "Shrink Array" wiki page.. but the clear script is reporting that it's clearing at 1.2MB/s... surely it shouldn't be that slow?

Edited by wishie
Realised I have referenced the wrong post.

Share this post


Link to post
4 hours ago, wishie said:

but the clear script is reporting that it's clearing at 1.2MB/s... surely it shouldn't be that slow?

No it shouldn't, but I also believe the script is not working correctly with latest unRAID, if you want to do that best to do it manually, see here:

 

https://forums.lime-technology.com/topic/61614-shrink-array-question/?tab=comments#comment-606335

 

Share this post


Link to post
On 03/08/2016 at 2:28 AM, Squid said:

A slightly enhanced version of the run mover at a certain threshold script.  This script additionally will skip running mover (optional) if a parity check / rebuild has already been started.

 

Only makes sense to run this script on a schedule, and disable the built-in schedule by editing the config/share.cfg file on the flash drive.  Look for a like that says something like:

 


shareMoverSchedule="0 4 * * *"
 

 

and change it to:


shareMoverSchedule="#0 4 * * *"
 

 

 

Followed by a reboot.  Note that any changes to global share settings ( or mover settings ) is probably going to wind up re-enabling the mover schedule

 

 

 


#!/usr/bin/php
<?PHP
$moveAt = 0;                 # Adjust this value to suit (% cache drive full to move at)
$runDuringCheck = false;     # change to true to run mover during a parity check / rebuild

$diskTotal = disk_total_space("/mnt/cache");
$diskFree = disk_free_space("/mnt/cache");
$percent = ($diskTotal - $diskFree) / $diskTotal * 100;

if ( $percent > $moveAt ) {
  if ( ! $runDuringCheck ) {
    $vars = parse_ini_file("/var/local/emhttp/var.ini");
    if ( $vars['mdResync'] ) {
      echo "Parity Check / Rebuild Running - Not executing mover\n";
      exec("logger Parity Check / Rebuild Running - Not executing mover");
    } else {
      exec("/usr/local/sbin/mover");
    }
  } else {
    exec("/usr/local/sbin/mover");
  }
}
?>
 

 

 

run_mover_at_threshold_enhanced.zip

@Squid does it matter if I just change the built-in schedule to Monthly rather than changing the share.cfg file?

 

Share this post


Link to post
24 minutes ago, leejbarker said:

does it matter if I just change the built-in schedule to Monthly rather than changing the share.cfg file?

Doesn't matter.  But at the monthly schedule, mover will move all the files.  By manually editing that file, then the script is in charge and will only move the files once the threshold is reached.

Share this post


Link to post
23 hours ago, Squid said:

Doesn't matter.  But at the monthly schedule, mover will move all the files.  By manually editing that file, then the script is in charge and will only move the files once the threshold is reached.

So if I'm understanding correctly, I can set this script to 75% and have shareMoverSchedule set to daily, and mover will run at 75% AND daily?

Share this post


Link to post
So if I'm understanding correctly, I can set this script to 75% and have shareMoverSchedule set to daily, and mover will run at 75% AND daily?
It'll run at 75% whenever you set the schedule for the script to run and move all the files whenever you have the mover schedule set to run. Setting them both to the same schedule is pointless

Sent from my SM-T560NU using Tapatalk

Share this post


Link to post
8 hours ago, Squid said:

It'll run at 75% whenever you set the schedule for the script to run and move all the files whenever you have the mover schedule set to run. Setting them both to the same schedule is pointless

Sent from my SM-T560NU using Tapatalk
 

Great. My cache is a little on the small side and sometimes can fill pretty fast. Was running mover 4 x daily just in case there was something to move. Now I can just run the script every 15 minutes. I’ll still run mover daily just so the files aren’t sitting unprotected for too long.

Share this post


Link to post

Looking for a script to reset my cable modem if the internet goes down as I've had some issues recently with the net going down when I reset my routers on their schedule. 

 

I found this link in my search and I downloaded the user scripts plugin but I'm not sure how I can get the logging script to trigger the restart script if they are in the userscripts plugin. 

 

Additionally I believe this script could be a huge hit with the community!

 

Thanks for any help you can provide.

Share this post


Link to post
On 1/7/2018 at 4:24 AM, Squid said:

It'll run at 75% whenever you set the schedule for the script to run and move all the files whenever you have the mover schedule set to run. Setting them both to the same schedule is pointless

Sent from my SM-T560NU using Tapatalk
 

Hi @Squid - sorry to resurrect this, but I have the same requirement.  Are you sure running both would be pointless (I could have missed the point)?

 

I sometimes hit 75% cache capacity quickly, and want to trigger the mover.  However, other times there's not a lot of activity.  During these quiet times, I'm guessing that anything on the cache could stay there a while - I'd still want to periodically trigger the mover to prevent anything staying cache-only for, long periods (could be a month).

 

At the same time, I don't want the two to interfere with each other by running concurrently (if they would, I don't know).  Is there any way the script could be amended to only run if the mover is not already running?

Share this post


Link to post

Regarding the clearing an array drive script - why is it so slow (even with reconstruct write on?)

 

Doing dd bs=4M if=/dev/zero of=test to a mounted disk = max disk speed (~130MB/sec)

 

dd bs=1M if=/dev/zero of=/dev/md7 results in ~2MB/sec.

 

There should be no difference?

 

Take years to clear 2TB drive at 2MB/sec!

Share this post


Link to post

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.