Additional Scripts For User.Scripts Plugin


Recommended Posts

8 hours ago, MowMdown said:

 There is a bug in your new code specifically:

 


command="/usr/lib/plexmediaserver/plex-nvdec-patch.sh"
if [ "$codec_arguments" ]; then
        #This line is recursive, it duplicates the codecs in the Plex Transcoder file (we don't need it)
        #command+="${codec_arguments}" 
	docker exec -i "$con" /bin/sh -c "${command}${codec_arguments}"
else
	docker exec -i "$con" /bin/sh -c "${command}"
fi

What ends up happening is that in the "Plex Transcoder" file, you end up with 

 


ALLOWED_CODECS=("h264" "hevc" "h264" "hevc")

Removing that line of code fixes the issue. You don't need to concatenate the "command+="${codec_arguments}" because it's already being taken care of at the next line where the docker exec code is taking place.

HAHAHA I can't believe I left that in there. Originally, I was using /bin/bash -c which resulted in a bashism making the concatenation cause the script in the container to error out with "invalid codec: vp9" even though it was totally valid. Switching for sh -c fixed it but I left my concat workaround in there.
Thanks for the fix :D

EDIT:
I have moved wget to the HOST side in the latest revision of the script. neither curl or wget is guaranteed to be present inside the docker, since this script was written for unraid, and unraid ships with wget stock - we're using that. I could add a pure bash download function - but that seems unnecessarily complicated.

Edited by Xaero
  • Upvote 1
Link to comment
  • 3 weeks later...

Is there a way to trigger a notification to be sent from unraid's notification system?

 

I have sonarr move TV episodes it replaces to a .deletedBySonarr folder and over time they can get pretty big if I don't catch it. I'd like to make a script that checks the size of that folder and if it's larger than X GBs send me a notification.

 

Link to comment

Hi folks. I was attempting to run the "clear an array drive" script in preparation for removing some smaller drives. I marked one 2TB drive with `clear-me` folder and launched the script. Just checked the status of it the next day and i see a "No space left on device" error is shown in script output. Has anyone seen this before with this script? Not clear on what this means but im assuming the script was not successful :P

 

Here is the full script output:

Script location: /tmp/user.scripts/tmpScripts/clear an array drive/script
Note that closing this window will abort the execution of this script
*** Clear an unRAID array data drive *** v1.4

Checking all array data drives (may need to spin them up) ... 

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

You have 60 seconds to cancel this script (click the red X, top right)

Unmounting Disk 3 ...
Clearing Disk 3 ...
2000357949440 bytes (2.0 TB, 1.8 TiB) copied, 36837 s, 54.3 MB/s
dd: error writing '/dev/md3': No space left on device

 

Link to comment

Thanks for the reply @johnnie.black. I guess the thing that trips me up is the fact the done logs from script were not output. I looked in the syslog and don't see any signs of them there either. Seems like the script just died after 'dd' command completed. Anyway given that 'dd' completed i guess I can assume it did what needs to be done since i see no other meaningful commands after that. Guess i'll try this with the other drives i plan to remove and see how they go.

 

Btw, i hadn't looked at the done messages in script until after i sent my first message. I see it specifically calls out the fact that "no space left on device" error may occur and that it is not an issue (ie. is expected).

Link to comment

Currently I have a Script which starts letsencrypt docker (which just gets a cert from LE via DNS Challenge) then copies the cert to my usb device so my unraid  has a green lock.

 

But it feels kinda rocky, anyone has a Idea how to improve this script?

 

#!/bin/bash
echo "Starting Docker"
docker start letsencrypt-server
echo "Wait for 60s"
sleep 10
echo "Wait for 50s"
sleep 10
echo "Wait for 40s"
sleep 10
echo "Wait for 30s"
sleep 10
echo "Wait for 20s"
sleep 10
echo "Wait for 10s"
sleep 10
echo "Copy Files"
cp /mnt/user/appdata/letsencrypt/keys/letsencrypt/priv-fullchain-bundle.pem /boot/config/ssl/certs/Columbus_unraid_bundle.pem
echo "Stopping docker letsencrypt-server"
docker stop letsencrypt-server
echo "Wait for 10s"
sleep 10
echo "Done"

 

Link to comment

The 'Schedule' exact times used by User scripts, where do I set and find them?

Are they simply crontab tasks of the unraid slackware, or what?

I would like 'Daily' to be Nightly at 5:45 CET. And yes, I see there's a 'corntab' option (it's actually spelled wrong there) but totally unclear what the syntax is.

Edited by fluisterben
Link to comment
3 minutes ago, fluisterben said:

The 'Schedule' exact times used by User scripts, where do I set and find them?

Are they simply crontab tasks of the unraid slackware, or what?

I would like 'Daily' to be Nightly at 5:45 CET. And yes, I see there's a 'corntab' option (it's actually spelled wrong there) but totally unclear what the syntax is.

Checkout this link to easily use cron:

 

https://crontab.guru/

 

Edit: This is what you would want to use if you want it to run everynight at 5:45am: 45 5 * * *

Edited by zacharyd3
clarified the answer
Link to comment
7 minutes ago, fluisterben said:

I know quite wel how to write cron jobs, it's just completely unclear what to put in the textform on the User scripts page. Or what the scheduled times are as set in the dropdown.

You put your cron setup in the text box. As for the scheduled times, you can get a plugin to set the "Daily" time yourself. I'm at work at the moment so I can't remember what it's called but I'm pretty sure it's a dynamix plugin and then you get a new settings page under the scheduler to adjust it. I've got my "daily" tasks setup to run at 6:30pm everyday and it work flawlessly.

 

Edit: Yup it's dynamix that has the scheduler

 

Edited by zacharyd3
added link
  • Like 1
Link to comment
  • 2 months later...

Hi there,

 

I'm currently combining two Unraid servers into one and was planning on using the "Clear an unRAID array data drive" script for one of the drives so I have enough room to move the rest of the files over while keeping parity (I moved everything off that one already)

 

I was wondering if the script will leave the drive in a pre cleared state ready to be added to the new array or if I will need to preclear it also?

Thanks for any support :)

 

EDIT1: (Basically have another new drive needing preclearing and wondering if I install it tonight so both are done at same time or just wait if I have to do it on the "old" one anyway. I don't like opening the case every time especially since its running my xeoma cam server atm)

 

EDIT2: Um at the current speed, ~3.7MB (with recon write) its going to take 11.6 days so I'm just gonna install a new drive and which should have enough space for the rest of the files.

Edited by Helbirden
Link to comment
6 hours ago, Helbirden said:

I was wondering if the script will leave the drive in a pre cleared state ready to be added to the new array or if I will need to preclear it also?

I know you already figured out a solution, but for completion's sake, the script doesn't add the preclear signature, it only zeroes the disk. So, no, even though the disk is clear, it's not going to be accepted as such if you add it back to a parity protected array.

Link to comment
  • 3 weeks later...
On 7/24/2016 at 11:17 AM, Squid said:

Record Disk Assignments

 

Records your current disk assignments to a file on the flash drive called DISK_ASSIGNMENTS.txt (config folder).  Not necessary if you run CA's appdata backup as that's done automatically

 

 


#!/usr/bin/php
<?PHP
  $availableDisks = parse_ini_file("/var/local/emhttp/disks.ini",true);
  $txt .= "Disk Assignments as of ".date(DATE_RSS)."\r\n";
  foreach ($availableDisks as $Disk) {
    $txt .= "Disk: ".$Disk['name']."  Device: ".$Disk['id']."  Status: ".$Disk['status']."\r\n";
  }
  file_put_contents("/boot/config/DISK_ASSIGNMENTS.txt",$txt);
  echo "Disk assignments have been saved to the flashdrive (config/DISK_ASSIGNMENTS.txt)\n";
?>
 

 

record_disk_assignments.zip 891 B · 57 downloads

No longer works

Link to comment
On 7/30/2019 at 12:20 AM, Helbirden said:

Um at the current speed, ~3.7MB (with recon write) its going to take 11.6 days

Something is not right with that. Most likely you have connection issues with one or more disks. You must double-check all connections any time your are in the case.

 

Post your diagnostics.

Link to comment

Script to convert text files from DOS to Unix format.

 

dos2unix

 

#!/bin/bash

# Convert text files from DOS to Unix format.

if [ $# -eq 0 ] || [ "$1" == "--help" ]
then
	printf "Usage: dos2unix <files>...\n"
	exit 0
fi

for file in "${@}"
do
	user=$(stat -c '%U' "$file")
	group=$(stat -c '%G' "$file")
	perms=$(stat -c "%a" "$file")

	tmp="$file.$(date +%N)"
	cat "$file" | fromdos > "$tmp"
	mv "$tmp" "$file"

	chown $user:$group "$file"
	chmod $perms "$file"
done

 

Script to convert text files from Unix to DOS format.

 

 unix2dos

#!/bin/bash

# Convert text files from Unix to DOS format.

if [ $# -eq 0 ] || [ "$1" == "--help" ]
then
	printf "Usage: unix2dos <files>...\n"
	exit 0
fi

for file in "${@}"
do
	user=$(stat -c '%U' "$file")
	group=$(stat -c '%G' "$file")
	perms=$(stat -c "%a" "$file")

	tmp="$file.$(date +%N)"
	cat "$file" | todos > "$tmp"
	mv "$tmp" "$file"

	chown $user:$group "$file"
	chmod $perms "$file"
done

 

Edited by JoeUnraidUser
  • Upvote 1
Link to comment
On 8/16/2019 at 2:42 AM, jpowell8672 said:

No longer works

Script works perfectly fine.  What you were doing though is copying and pasting the script via the forum which occasionally adds some hidden characters, resulting in a broken script.

 

Changing the plugin to remove the unprintable characters when pasting into the edit box

  • Upvote 1
Link to comment
3 hours ago, Squid said:

Script works perfectly fine.  What you were doing though is copying and pasting the script via the forum which occasionally adds some hidden characters, resulting in a broken script.

 

Changing the plugin to remove the unprintable characters when pasting into the edit box

Thanks, yes I am guilty of copying & pasting. It's the easiest & quickest way to add a script. Did not know that would break it, but now I know. I would have copied to folder but my smb sharing has not been working in unraid for a while now. The only way I can transfer to unraid at this point is through usb drive through unassigned devices & krusader.

Link to comment
  • 2 months later...

Does anyone have a copy script that will work like this...

 

Existing share on an unassigned drive

Want to back this up to the array daily (so schedule a user script) 

Would like it to look at the initial backup that was made, and then just append to keep it up to date. 

 

I have all my mp3's on a SSD for fast reading from my Mac in iTunes, plus sonos around the house, but would like them on the array too incase the SSD dies. 

Link to comment
  • 1 month later...
1 hour ago, rbronco21 said:

I'm using "Clear an unRAID array data drive" to clear disks for encryption. The script stopped at 40GB on my 8TB disk and I am not sure what state I am in now. Can I try it again? Do I need to rebuild it before anything else?

That script isn't working correctly (or it's very slow) with current Unraid, you can still do it manually.

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.