Additional Scripts For User.Scripts Plugin


415 posts in this topic Last Reply

Recommended Posts

4 hours ago, Energen said:

Run it from the user scripts plugin page (from settings)

Hmmm I tried that! When I click on "Run Script", I receive the following error message:

Script location: /tmp/user.scripts/tmpScripts/dos2unix/script
Note that closing this window will abort the execution of this script
stat: cannot stat '': No such file or directory
stat: cannot stat '': No such file or directory
stat: cannot stat '': No such file or directory
cat: '': No such file or directory
mv: cannot move '.274082193' to '': No such file or directory
chown: cannot access '': No such file or directory
chmod: missing operand after ''
Try 'chmod --help' for more information.

 

Link to post
  • 1 month later...
  • Replies 414
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

NOTE: I do not have time to keep the table of contents up to date, so there are going to be other scripts within this thread that are not listed here.     Just a thread to contain any/a

Enable Hardware Decoding in Plex #!/bin/bash con="plex" echo "" echo "<font color='red'><b>Applying hardware decode patch...</b></font>" echo "<hr>" docker exec -i

Clear an unRAID array data drive  (for the Shrink array wiki page)   This script is for use in clearing a drive that you want to remove from the array, while maintaining parity protection.  I've a

Posted Images

I have made a script to delete all cached images in Plex's PhotoTranscoder folder that are older than 7 days. See below:

 

Quote

#!/bin/bash
echo "Searching for (and deleting) cached files"
find /mnt/user/appdata/plex/Library/Application\ Support/Plex\ Media\ Server/Cache/PhotoTranscoder/* -maxdepth 9999 -mtime +5 -exec rm -vf {} \; | wc -l
echo " files were deleted"

 

in the output the number of files deleted is on one line and then the "files were deleted" text is on the line under. I have tried to make the text appear directly after the count but can't seem to make it work. any ideas?

Link to post
51 minutes ago, aussie_huddo said:

I have tried to make the text appear directly after the count but can't seem to make it work. any ideas?

 

find * -maxdepth 9999 -mtime +5 -exec rm -vf {} \; -exec /bin/echo {} \; | wc -l | { read count; echo "Done. $count files deleted."; }

 

Grabbed this syntax from a thread on stackoverflow, works good. 

Link to post
On 7/23/2016 at 4:00 PM, Squid said:

Run mover at a certain threshold of cache drive utilization.

 

Adjust the value to move at within the script.  Really only makes sense to use this script as a scheduled operation, and would have to be set to a frequency (hourly?) more often than how often mover itself runs normally.

 

 



#!/usr/bin/php
<?PHP

$moveAt = 70;    # Adjust this value to suit.

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

if ( $percent > $moveAt ) {
  exec("/usr/local/sbin/mover");
}
?>
 

 

 

run_mover_at_threshold.zip 717 B · 130 downloads

Perhaps a bit... superfluous, but hereby the same script, but then in bash:

#!/bin/bash
thresh=70;

used=$(df --output=used /mnt/cache/ | awk '{print $1}' | tail -n 1);
size=$(df --output=size /mnt/cache/ | awk '{print $1}' | tail -n 1);
percent=$((100 * used / size));

if (( $percent > $thresh )); then
    sh /usr/local/sbin/mover;
fi

 

Edited by sgraaf
Fixed a small bug
Link to post
1 minute ago, sgraaf said:

Perhaps a bit... superfluous, but hereby the same script, but then in bash:


 

I'm too lazy to figure out stuff in bash that I can do in 2 seconds in php ;) 

Link to post
40 minutes ago, sgraaf said:

Perhaps a bit... superfluous, but hereby the same script, but then in bash:


#!/bin/bash
thresh=70;

used=$(df --output=used /mnt/cache/ | awk '{print $1}' | tail -n 1);
avail=$(df --output=avail /mnt/cache/ | awk '{print $1}' | tail -n 1);
percent=$((100 * used / avail));

if (( $percent > $thresh )); then
    sh /usr/local/sbin/mover;
fi

 

Would also be helpful to note that ( used / avail ) is not quite what you want as while used increases, avail decreases. You want used / size

#!/bin/bash
thresh=70
stats=( $( df --output=used,size /mnt/cache | tail -n 1) )
percent=$[ 100 * ${stats[0]} / ${stats[1]} ]
[ $percent >  $thresh ] && sh /usr/local/sbin/mover

 

Link to post
25 minutes ago, ken-ji said:

Would also be helpful to note that ( used / avail ) is not quite what you want as while used increases, avail decreases. You want used / size


#!/bin/bash
thresh=70
stats=( $( df --output=used,size /mnt/cache | tail -n 1) )
percent=$[ 100 * ${stats[0]} / ${stats[1]} ]
[ $percent >  $thresh ] && sh /usr/local/sbin/mover

 

Thanks; fixed it in my original post / reply.

Link to post

How can I make a script that dose not run if it is currently running?


 

if pgrep -x "/boot/config/plugins/user.scripts/scripts/scriptName/script" > /dev/null

   then

      echo "Running"

   else

      echo "Stopped"

fi

 

something like this?

Link to post

Easiest is to use a lockfile (or semaphore)

Near the start of the script

if [ -e /var/lock/script.lock ]; then
  echo "Still running"
  exit
fi
touch /var/lock/script.lock

Then at the end of your script

rm -f /var/lock/script.lock

 

Edited by ken-ji
Link to post

Regarding the the "Clear an unRAID array data drive" script. The script doesn't verify that the desired drive is unmounted, I tried running the script last night and realized this morning that it was still running. The 'sync' progress had a hold on the drive. Could be an easy validation step to add to the script.

Link to post
On 11/27/2017 at 6:07 PM, Squid said:

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 1.31 kB · 27 downloads

 

Hey @Squid - I couldn't find if this had already been addressed elsewhere or not (if so, my google-fu sucks):

 

As of at least 6.9, the top of the script needs a tiny edit, from:
 

require_once("/usr/local/emhttp/plugins/community.applications/include/xmlHelpers.php");

 

To:

require_once("/usr/local/emhttp/plugins/community.applications/include/helpers.php");

 

For anyone getting something about an error at line three, calling blah/blah/xmlHelpers.php when they run the plugin integrity check script, the above is the quick fix (hoping to catch some search keywords with this sentence to avoid repeat requests where possible 👍

Link to post
5 minutes ago, Squid said:

Yup.  That script was posted over 3 years ago and things have been re-organized within CA since then.

Totally understood! Moreso posting to try to help any others that might end up seeing issues and come in with such a question 👍

 

Would it be worthwhile to have an open access GitHub page or something where all of the 'known' scripts could be stored, then folks can just edit to update them as/when needed? Or is that something that'd be discouraged at this point?

Link to post
On 3/9/2021 at 11:07 AM, ken-ji said:

Easiest is to use a lockfile (or semaphore)

Near the start of the script


if [ -e /var/lock/scrip.lock ]; then
  echo "Still running"
  exit
fi
touch /var/lock/script.lock

Then at the end of your script


rm -f /var/lock/script.lock

 

 

could you explain this a little more. I do not understand what is happening? I just paste that exact code into the top of the script and the other at the end?

Link to post

This is just sample code, but it can go into your script at line 2 (first possible code line)

what the 1st line does is check if there exists a file /var/lock/script.lock (note the typo) and if it does, it prints "Still running" for the user reference and exits the script (lines 2 and 3)

If the script still keeps running beyond the check (ie the file doesn't exist) it will then create the file and the script can do whatever you want.

 

Then at the end of the script, the command I showed will forcibly delete any existing /var/lock/script.lock.

 

All in all this means that when the script starts up, it checks if the lock file exists and will abort if it exists. this means a previously running script is still running (or crashed/aborted) and the script will no longer run until the lock file has been deleted. When the script does run, the last thing it will do is delete the lock file, thus allowing the script to run again.

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.