Jump to content
Squid

Additional Scripts For User.Scripts Plugin

323 posts in this topic Last Reply

Recommended Posts

Posted (edited)
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

Share this post


Link to post

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.

 

Share this post


Link to post

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

 

Share this post


Link to post
9 minutes ago, davis999 said:

"No space left on device" error

That's normal, just means dd reached the end of the device.

Share this post


Link to post

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).

Share this post


Link to post

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"

 

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post
Posted (edited)
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

Share this post


Link to post
2 minutes ago, zacharyd3 said:

Checkout this link to easily use cron:

 

https://crontab.guru/

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.

Share this post


Link to post
Posted (edited)
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

Share this post


Link to post

The dynamix schedules plugin. It’ll set a time for the preset schedules system wide.

Share this post


Link to post
Posted (edited)

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

Share this post


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

Share this post


Link to post

Hi, I am still a linux noob. Sorry if i ask a too simple question. Where is actually stored the output of the script :

Quote

viewDockerLogSize

Rgds

Share this post


Link to post
11 minutes ago, luca2 said:

viewDockerLogSize

Easier to simply get it from the docker tab, calculate container size

Share this post


Link to post
33 minutes ago, Squid said:

Easier to simply get it from the docker tab, calculate container size

OK, got it. thx!

Share this post


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

Share this post


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

Share this post


Link to post
On 8/16/2019 at 2:42 AM, jpowell8672 said:

No longer works

It works if you fix the script.  Copy/paste will not work due to incorrect line endings.  To fix the file you need to load it into an editor like notepad++,  select everything, then go to the menu and select Edit -> EOL conversion -> Unix (LF).

 

Edit:  or you can use dos2unix script to fix the file

Edited by JoeUnraidUser

Share this post


Link to post

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

Share this post


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

Share this post


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

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.