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

  • Author

Works for me.  Not sure.  What browser?

  • Replies 2.1k
  • Views 567k
  • 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

Well you put me already on the right path. Checking with chromium works but my "daily" browser Firefox 91.7.0esr doesn't

 

Hi @Squid

 

I just found out something weired and maybe of interest regarding the behaviour of the "User-Script" plugin.

 

If I just regularly delete a script in the GUI, the script itself is being deleted in /boot/config/plugins/user.scripts but within the schedule.json file the scripts definitions from the deleted scripts are still there.

(see picture in spoiler: the marked ones have been deleted before)

Spoiler

grafik.thumb.png.c962b09a16f72cae8e58e6203e9dd4f1.png

 

In fact, as long as the script-file itself does not exist any longer, it would not be a problem.

 

But 1.) every time this schedule.json file is loaded by the plugin, it loads old, already unnecessary stuff.

And 2.), going one step further, imagine what could happen if you create a script with the same name or the same file-name or if you create a script manually and put it into this directory with the same file name?

 

Of course, all this may be a problem just in rare circumstances but in my opinion the file and config handling of plugins in such important systems like a NAS should be as correct as possible to prevent from unintended errors as good as possible.

 

At this point, nevertheless, a *BIG* thank you for this plugin. It helps a lot!

 

Regards DaKarli. 🤗

  • Author
2 hours ago, DaKarli said:

But 1.) every time this schedule.json file is loaded by the plugin, it loads old, already unnecessary stuff.

 

Yes that's correct.  It was a design consideration to make everything a ton easier and also handle if the user manually deleted the scripts.  The script execution engine checks for the existence of the script before executing to handle this.

 

2 hours ago, DaKarli said:

And 2.), going one step further, imagine what could happen if you create a script with the same name or the same file-name or if you create a script manually and put it into this directory with the same file name?

Then it should show up on the list with the same settings as the one previously deleted.

21 hours ago, Squid said:

Yes that's correct.  It was a design consideration to make everything a ton easier and also handle if the user manually deleted the scripts.  The script execution engine checks for the existence of the script before executing to handle this.

 

Then it should show up on the list with the same settings as the one previously deleted.

 

Ok, so if the script exec engine checks this before, like I said, it may be no problem.

So it would be no problem either to manually delete old entries from the .json file if someone wants to go this extra step.

 

Regarding your 2nd point, I just want to add that the risk is somewhere else. If you add a different script but with the same name, you may not be aware that this new script will be executed by the old line in the .json file right after you saved that file.

But just as I already said, these may be rare circumstances and I just wanted point to possible risks with the handling being like it is.

Cheers ! 😉

CA Backup/Restore Appdata does not see my script at /boot/config/plugins/user.scripts/scripts/. How can I path to custom start script in this use case? Do I need to save the script somewhere else the plugin can see?

Just a thought I had for a possible visual addition to this fantastic plugin. Highlighting when hovering over a script to more easily identify which script you are on when over in the far right like in the log section for example. Kind of like is implemented in the new Dynamix File Manager plugin, or how things are highlighted in the main and shares tabs of Unraid 6.10.0-rc4.

I have seen some scripts include "echo", "logger" and behind some commands they write 2>&1 >>[some adress to a log file], and a date command, what do they do?

Any website I havent found yet that explains it? (might be searching for the wrong things)

Edited by Mihle

30 minutes ago, Mihle said:

 2>&1 >>[

is so both standard output and standard errors are appended to the log file.

 

 

Edited by SimonF

Trying to make a script I can run that backs stuff up to an unassigned devices HDD.

 

#!/bin/bash

#Destination of the backup:
destination="/mnt/disks/OfflineBackup"
#Name of Backup disk
drive=dev1

########################################################################
#Backup with docker containers stopped:

#Stop Docker Containers
echo 'Stopping Docker Containers'
docker stop $(docker ps -a -q)


#Backup Docker Appdata via rsync
echo 'Making Backup of Appdata'
rsync -avr --delete "/mnt/user/appdata" $destination

#Backup Flash drive backup share via rsync
echo 'Making Backup of Flash drive'
rsync -avr --delete "/mnt/user/NAS Flash drive backup" $destination

#Backup Nextcloud share via rsync
echo 'Making Backup of Nextcloud'
rsync -avr --delete "/mnt/user/NCloud" $destination


#Start Docker Containers
echo 'Starting up Docker Containers'
/etc/rc.d/rc.docker start

########################################################################
#Backup of the other stuff:

#Backup Game Backup share via rsync
echo 'Making Backup Game Backup share'
rsync -avr --delete "/mnt/user/Game Backups" $destination

#Backup Photos and Videos share via rsync
echo 'Making Backup of Photos and Videos share'
rsync -avr --delete "/mnt/user/Photos and Videos" $destination

########################################################################

#Umount destination
echo 'Unmounting and spinning down Disk....'
/usr/local/sbin/rc.unassigned umount $drive
/usr/local/sbin/rc.unassigned spindown $drive

#Notify about backup complete
/usr/local/emhttp/webGui/scripts/notify -e "Unraid Server Notice" -s "Backup to Unassigned Disk" -d "A copy of important data has been backed up" -i "normal"
echo 'Backup Complete'

 

I am not sure if I should use echo or logger?

Also, in a test script, I didnt manage to get the

2>&1 >> $LOGFILE

that I see some use at the end of rsync commands to do anything, what does it do and should I try to get it to work? Some do

>> var/log/[something].log

(together with some date command)
What do they do?

 

For reference, I set the drive to automount, then I want to manually have to start the script, but when its done running I want to be ready to just unplug without having to press anything more. (and then take to another location until its time to update it) (offline backup)

Hi,

 

I am trying to get custom schedule to work. I have a script to reindex a folder every 15 minutes every day from 6AM to 11PM. I put 0,15,30,45 6-23 * * * in the custom cron field but it never runs. Is this format supported by the plugin?

13 minutes ago, aarontry said:

Hi,

 

I am trying to get custom schedule to work. I have a script to reindex a folder every 15 minutes every day from 6AM to 11PM. I put 0,15,30,45 6-23 * * * in the custom cron field but it never runs. Is this format supported by the plugin?

Try */15 6-23 * * *

 

I had a similar expression that would run a drive spin up every evening

20 hours ago, Cessquill said:

Try */15 6-23 * * *

 

I had a similar expression that would run a drive spin up every evening

Thanks! It works.

I have been searching the web about custom time schedules and cannot find exactly what I am looking for.  If anyone can help me here that would be much appreciated.  I need my script to run every 5 minutes every Sunday from 7:30a til 12 noon.  Is this possible?

16 minutes ago, arkestler said:

I have been searching the web about custom time schedules and cannot find exactly what I am looking for.  If anyone can help me here that would be much appreciated.  I need my script to run every 5 minutes every Sunday from 7:30a til 12 noon.  Is this possible?

Just by tweaking the post above yours, this will get close: */5 7-12 * * 7

 

It should run every 5 minutes on a Sunday from 7-12, not 7.30.  I'm not personally aware of any way to put fractions in to hour ranges (somebody else might know), but if it has to be from 7.30 onwards then you could tweak your script by putting a quick bit of logic at the start.  Something like

 

startTime="07:30"
begin=$(date --date=$startTime +%s)
now=$(date +%s)

if [ "$now" -le "$begin" ]; then
	exit 1
fi

 

...would exit the script straight away for all times between 7 and 7.30.  Haven't tested it though - just patched it from a script that I used to run before I realised custom schedules were a thing.

2 hours ago, Cessquill said:

Just by tweaking the post above yours, this will get close: */5 7-12 * * 7

 

It should run every 5 minutes on a Sunday from 7-12, not 7.30.  I'm not personally aware of any way to put fractions in to hour ranges (somebody else might know), but if it has to be from 7.30 onwards then you could tweak your script by putting a quick bit of logic at the start.  Something like

 

startTime="07:30"
begin=$(date --date=$startTime +%s)
now=$(date +%s)

if [ "$now" -le "$begin" ]; then
	exit 1
fi

 

...would exit the script straight away for all times between 7 and 7.30.  Haven't tested it though - just patched it from a script that I used to run before I realised custom schedules were a thing.

This is very helpful, thank you!

I have been looking for a document for an example on how to do this.

I would like to set up a custom schedule within User Scripts to run every 2 days @ midnight.  

 

can someone please point me to the documentation, so that I can set this up please

24 minutes ago, chris_netsmart said:

can someone please point me to the documentation, so that I can set this up please

 

image.png.fbde274991deea6303553371b64f1caf.png

 

so something like

 

0 0 */2 * *

 

will run every 2nd day at midnight ...

 

google will give you around 1 mio results in no time ;) how to define cron timings, just try it and you will see it ;)

There's a typo  on the link to "What is Cron" on the /Settings/Userscripts page.
 

It goes to corntab.com instead of crontab.com

12 minutes ago, Teknishun said:

There's a typo  on the link to "What is Cron" on the /Settings/Userscripts page.
 

It goes to corntab.com instead of crontab.com

Did you try the link?

 

corntab.com is the place I always go.

crontab.com domain is for sale.

4 minutes ago, trurl said:

Did you try the link?

Doesn't seem to be working for me at the moment though.

I'm still new to using the User Scripts plugin and still trying my best to learn a few tricks.  

 

I'm trying to move files (a folder with 1 file) from one location to another.

 

For example:

 

mv -f /mnt/user/Downloads/Completed/1.MOVIES/ /mnt/user/Media/Movies/Movies-6/

 

The above of course, moves the entire 1.MOVIES folder to the location Movies-6

 

I need it to move only whatever folder and file that appear in that folder - how do I do that?

 

Thanks for any/all help!

  

9 hours ago, trurl said:

Did you try the link?

 

corntab.com is the place I always go.

crontab.com domain is for sale.

 

Huh, I'm sure I tried it last night but it was pretty late! My bad🤦

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.