Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Plugin] CA User Scripts

Featured Replies

1 hour ago, wgstarks said:

Actually I think you have to use the number instead of WED.


0 4 * * 3

 

You right you right 🙂

  • 4 weeks later...
  • Replies 2.1k
  • Views 567.1k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • I could make up something long, convoluted, and technical as a reason why it doesn't do that but it would all be bs.  The simple answer is that when I did this, I never thought of that, and why it sti

  • Hi All - We have a fix and are publishing a Connect plugin update to fix it today. Thanks for letting us know.

  • @Squid I tried many commands and by that I found out that pkill does not kill (all) child processes: root@Thoth:/tmp# pgrep -f isleep2m | xargs --no-run-if-empty ps fp PID TTY STAT T

Posted Images

Any scripts that backups selected shares (including for example nextcloud) to an SATA unassigned device with the backup being encrypted?
(want to backup to a drive 2-4 times a year and store it outside my own home)

The unassigned devices plugin has a very nice option to run a script when external drive is plugged in.

Use the default script button to start with a default script and build from there, I have something similar build but not with encryption.

Edited by soana

2 minutes ago, soana said:

The unassigned devices plugin has a very nice option to run a script when external drive is plugged in.

Use the default script button to start with a default script and build from there, I have something similar build but not with encryption.

I have tried multiple times to get the UD scripts to work but could never figure it out, it doesn't make sense. I wish it could be connected to user scripts so I can just select a user script to run.

Here is my script I did not put too much time into it since it did the job from the first time.

Line 4 and 5 define the source and the destination. The backup (rsync) and notification bits are in the ACTION block

 

#!/bin/bash
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

source="/mnt/user/Personal/"
destination="/mnt/disks/My_Book_3Tb/"

## Available variables: 
# AVAIL      : available space
# USED       : used space
# SIZE       : partition size
# SERIAL     : disk serial number
# ACTION     : if mounting, ADD; if unmounting, UNMOUNT; if unmounted, REMOVE; if error, ERROR_MOUNT, ERROR_UNMOUNT
# MOUNTPOINT : where the partition is mounted
# FSTYPE     : partition filesystem
# LABEL      : partition label
# DEVICE     : partition device, e.g /dev/sda1
# OWNER      : "udev" if executed by UDEV, otherwise "user"
# PROG_NAME  : program name of this script
# LOGFILE    : log file for this script

case $ACTION in
  'ADD' )
    # do your stuff here
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device mounted" -i "normal"
    date >/var/log/My_Book_3Tb_Backup.log
    /usr/bin/rsync -avrtH --delete $source $destination >>/var/log/My_Book_3Tb_Backup.log
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "My_Book_3Tb" -d "Backup to My_Book_3Tb finished see /var/log/My_Book_3Tb_Backup.log for details" -i "normal"

    # This will refresh the UD webpage when the script is finished.
    /usr/local/sbin/rc.unassigned refresh $DEVICE
  ;;

  'UNMOUNT' )
    # do your stuff here
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounting" -i "normal"
  ;;

  'REMOVE' )
    # do your stuff here
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Device unmounted" -i "normal"
  ;;

  'ERROR_MOUNT' )
    # do your stuff here
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Error mounting device" -i "alert"
  ;;

  'ERROR_UNMOUNT' )
    # do your stuff here
    /usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Unassigned Devices" -d "Error unmounting device" -i "alert"
  ;;
esac

 

  • 2 weeks later...
On 6/26/2016 at 1:23 AM, Squid said:

#description=this is the description of the script

#foregroundOnly=true

#backgroundOnly=true

#arrayStarted=true

#name=blah blah blah

#clearLog=true

#argumentDescription=This is the description of the argument(s)

#argumentDefault=defaultArg1 defaultArg2 etc

#noParity=true

First of, I love this plugin. Second, would it be possible to allow variables for Node scripts too, i.e. parsing `//` right after the shebang, in addition to `#`? Like:

#!/usr/bin/env node
//name=Script name

I know I can just run the JS file from the shell script but I prefer to have it self-contained.

@Squid Hi

Please add multi-language support, tnx

info 

 

Does anyone have a script that will check the docker logs for a specific error and restart a container if the error is present?

 

In my case, Plex corrupts EasyMediaEncoder every now and then which will not allow any media to play. The only way I have managed to fix it is to go in and manually delete the folder and restart the container. I did create a script that does this for me but I have to manually fire it. 

 

I am hoping there is a way that I can monitor the logs every 5 minutes or so to search for (or any portion of)

Jobs: Exec of /config/Library/Application Support/Plex Media Server/Codecs/EasyAudioEncoder-1452-linux-x86_64/EasyAudioEncoder/EasyAudioEncoder failed. (13)

and then fire the script to automatically delete the folder and restart Plex.

 

If anyone has a script similar to this or has any info to point me in the right direction, it would be much appreciated.

 

 

--------------------------

EDIT: Got it figured out:

if docker logs --since 1m PlexMediaServer 2>&1 | grep -i "EasyAudioEncoder failed"; then
  echo "EMC Failed"
  echo "Stopping Plex container..."
  docker stop PlexMediaServer

  echo "Deleting Codecs folder..."
  rm -r "mnt/user/docker/Plex-Media-Server/config/Library/Application Support/Plex Media Server/Codecs"

  echo "Starting Plex again..."
  docker start PlexMediaServer

  echo "Sending notification to UNRAID"
  /usr/local/emhttp/webGui/scripts/notify -e "EasyMediaEncoder failed!" -s "Plex Media Server" -d "EasyAudioEncoder failed. Check to see if it has been fixed." -i "alert"

  echo "Fixed!"
fi

It basically checks the last minute in the docker logs for plex and searches "EasyAudioEncoder failed". If it does, it stops Plex, deletes the EMC folder, and then restarts Plex. 

Edited by LTM

A small feature request: whitespace in the output of a script is currently being collapsed, causing this (the columns are supposed to be aligned):

 

screenshot-unraiden.local-2021_08.22-19_14_15.thumb.png.a2021efbe2528c571e2e44202f501166.png

 

If the output were to be wrapped in a <pre> tag, it will preserve the whitespace and show correctly, like this:

screenshot-unraiden.local-2021_08.22-19_16_01.thumb.png.260f8bdddd658bc3901eabcc390d7a92.png

 

It would also have the added benefit of adding some top margin to the output, for better separation :)

 

(the font-family of the <pre> tag might need to be set to 'bitstream' to not get overridden with 'monospace')

Hello everyone,

I have been having an issue for the past months whereby i can't edit save or delete anything, clicking the save button doesn't submit anything and when I refresh the page nothing has changed. How would I reset the app so I can start fresh? I tried uninstalling the app and reinstalling but the settings ect are still there.

  • Author

Look in /config/plugins/user.scripts/scripts on the flash drive and change the folder names to avoid special characters and see if that makes a difference

Hi there, good morning. Thanks for the awesome plugin!

I set my own script to run as a cronjob this morning but it didn't execute. I had it set to run custom and cron time 30 2 * * TUE

(2:30AM on every Tuesday). Not sure why it did not execute this morning. Was my cron format wrong? Can you please advise?

 

Thanks in advance.

On 7/2/2021 at 1:24 PM, wgstarks said:

Actually I think you have to use the number instead of WED.

0 4 * * 3

 

 

13 hours ago, lamp said:

Hi there, good morning. Thanks for the awesome plugin!

I set my own script to run as a cronjob this morning but it didn't execute. I had it set to run custom and cron time 30 2 * * TUE

(2:30AM on every Tuesday). Not sure why it did not execute this morning. Was my cron format wrong? Can you please advise?

 

Thanks in advance.

 

If I have questions about the cron schedule, I rely on this......     https://crontab.guru/

 

Truly a god send.....

 

4 hours ago, jmbailey2000 said:

 

If I have questions about the cron schedule, I rely on this......     https://crontab.guru/

 

Truly a god send.....

 

If you mouse over "What Is Cron" at the top of the User Scripts page you get a popup of what this implementation of cron accepts.

Is it possible to add an optional feature, to send the output of the script (the same as what is shown if you Run the Task in the Web UI) as a Notification using the unRAID Notification system, so we can see when scripts have run, and if any issues etc were reported? Similar to how in Cron you can set it to email you on completion (assuming you have the right stuff setup).

On 8/23/2021 at 1:53 PM, Squid said:

Look in /config/plugins/user.scripts/scripts on the flash drive and change the folder names to avoid special characters and see if that makes a difference

 Solved it, it was a script that had to be deleted that was messing with the others. Thanks!

On 8/29/2021 at 5:27 PM, timethrow said:

Is it possible to add an optional feature, to send the output of the script (the same as what is shown if you Run the Task in the Web UI) as a Notification using the unRAID Notification system, so we can see when scripts have run, and if any issues etc were reported? Similar to how in Cron you can set it to email you on completion (assuming you have the right stuff setup).

You can use '/usr/local/emhttp/webGui/scripts/notify' in your script:

notify [-e "event"] [-s "subject"] [-d "description"] [-i "normal|warning|alert"] [-m "message"] [-x] [-t] [-b] [add]
  create a notification
  use -e to specify the event
  use -s to specify a subject
  use -d to specify a short description
  use -i to specify the severity
  use -m to specify a message (long description)
  use -l to specify a link (clicking the notification will take you to that location)
  use -x to create a single notification ticket
  use -r to specify recipients and not use default
  use -t to force send email only (for testing)
  use -b to NOT send a browser notification
  all options are optional

notify init
  Initialize the notification subsystem.

notify smtp-init
  Initialize sendmail configuration (ssmtp in our case).

notify get
  Output a json-encoded list of all the unread notifications.

notify archive file
  Move file from 'unread' state to 'archive' state.

 

20 hours ago, KnifeFed said:

You can use '/usr/local/emhttp/webGui/scripts/notify' in your script:

notify [-e "event"] [-s "subject"] [-d "description"] [-i "normal|warning|alert"] [-m "message"] [-x] [-t] [-b] [add]
  create a notification
  use -e to specify the event
  use -s to specify a subject
  use -d to specify a short description
  use -i to specify the severity
  use -m to specify a message (long description)
  use -l to specify a link (clicking the notification will take you to that location)
  use -x to create a single notification ticket
  use -r to specify recipients and not use default
  use -t to force send email only (for testing)
  use -b to NOT send a browser notification
  all options are optional

notify init
  Initialize the notification subsystem.

notify smtp-init
  Initialize sendmail configuration (ssmtp in our case).

notify get
  Output a json-encoded list of all the unread notifications.

notify archive file
  Move file from 'unread' state to 'archive' state.

 

 

Thanks, but this only works if you put that in for every eventuality in your script, whereas having the plugin send it after a script has completed (whether successful or not) ensures its always sent.

 

For example, if my script encounters an error that was not captured, the notify may not be sent if included in the script manually, whereas this way, it will always be sent, so long as the underlying plugin works.

 

I do have the notify in some of my user scripts, and I also do redirect alot of my output to log files I store on the array (in case I need it) but this is more for being notified for when a script is run and the output, similar to the cron service on a vanilla Linux server. It allows you to check quickly/easily if a script ran and if it has the expected output or not.

Silly question, but I can't seem to find an answer for it:

There's the pre-set Hourly, Daily, Weekly, and Monthly schedules. But I can't seem to find when they run (ie. What time does the daily kick off, day/time for weekly, etc.). Is there any way to adjust them to be your preferred values?

  • Author

Install the dynamix schedules plugin

How can I either email the output of scripts or have my scripts send an email?

 

I have an rclone script I use that emails me a summary of my rclone sync. I can't use it in Unraid since the mail command doesn't work.

 

Also, was the clearLog option removed?

25 minutes ago, IMTheNachoMan said:

How can I either email the output of scripts or have my scripts send an email?

I have an rsync backup script that I run through User Scripts that sends an email summary of the backup process.  Here are the relevant portions of the script I use:

 

	# Set up email header
	echo To: [email protected] >> /boot/logs/cronlogs/BackupNAS_Summary.log
	echo From: [email protected] >> /boot/logs/cronlogs/BackupNAS_Summary.log
	echo Subject: MediaNAS to BackupNAS rsync summary >> /boot/logs/cronlogs/BackupNAS_Summary.log
	echo   >> /boot/logs/cronlogs/BackupNAS_Summary.log

 

# Send email of summary of results
	ssmtp [email protected] < /boot/logs/cronlogs/allshares.log
	cd /boot/logs/cronlogs  
	mv BackupNAS.zip "$(date +%Y%m%d_%H%M)_BackupNAS.zip"
	rm *.log

 

The script concatenates share backup info in allshares.log and then that is emailed to a yahoo.com address

Edited by Hoopster

9 minutes ago, Hoopster said:
ssmtp

 

Ah. So Unraid is using ssmtp. Got it. I can update my scripts. Thank you!

I guess this is simple.

But, how to:

 

  • Delete all files older then 14 days in /mnt/user/surveillance_camera/cam1 and /mnt/user/surveillance_camera/cam2 (including subfolders)
  • Then Remove all empty folders whitin the same paths.

It might be something I can find out for myself, but I don't have any unraid development environment, and I don't know if I will run delete-commands that I'm not sure about on my production server.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.