Additional Scripts For User.Scripts Plugin


Recommended Posts

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

Link to comment

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

Link to comment
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

 

Link to comment
  • 1 month later...

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
Link to comment
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
Link to comment
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.

Link to comment

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
Link to comment
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!

Link to comment
  • 4 weeks later...
  • 2 weeks later...
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?

 

Link to comment
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.

  • Upvote 1
Link to comment
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?

Link to comment
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

Link to comment
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.

Link to comment
  • 3 weeks later...

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.

Link to comment
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?

Link to comment
  • 2 weeks later...

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.