[Plugin] CA User Scripts


Recommended Posts

Is it possible to make the following changes to the script?

 

1.) All scripts should be generated in /usr/local/bin/<scriptname>

2.) All logs should be stored in /var/log/scripts/<scriptname>.log

3.) A logrotate rule should get rid of huge logs

 

By that it would be possible to execute scripts on the terminal and the logs won't use so much RAM over the time.

 

root@thoth:~# ls -lahS /tmp/user.scripts/tmpScripts/*/log.txt
-rw-rw-rw- 1 root root 179M Nov  9 04:02 /tmp/user.scripts/tmpScripts/backup_appdata/log.txt
-rw-rw-rw- 1 root root 118M Nov 26 12:00 /tmp/user.scripts/tmpScripts/backup-all-computers/log.txt
-rw-rw-rw- 1 root root  65M Nov 26 03:01 /tmp/user.scripts/tmpScripts/backup-appdata/log.txt
-rw-rw-rw- 1 root root  53M Nov 26 12:12 /tmp/user.scripts/tmpScripts/minecraft-powersave/log.txt
-rw-rw-rw- 1 root root  50M Nov 26 12:12 /tmp/user.scripts/tmpScripts/shares_protect/log.txt
-rw-rw-rw- 1 root root  31M Oct 30 00:03 /tmp/user.scripts/tmpScripts/backup_marc_desktop/log.txt

 

Link to comment
On 11/21/2022 at 4:33 PM, voidpointer said:

Anyone please?

Two ideas

A) start the script every 5 minutes and check if docker is available

B) Edit /etc/rc.d/rc.docker and add your script to the line "starting $BASE ...". But this needs to be done on every server reboot.

 

I'm using a similar trick to create a RAM disk of a docker sub dir to avoid excessive writes on my NVMe:

https://forums.unraid.net/bug-reports/stable-releases/683-unnecessary-overwriting-of-json-files-in-dockerimg-every-5-seconds-r1079/?tab=comments#comment-15472

 

 

 

 

Link to comment

User scripts is awesome, thank you so much for providing this. Just a quick question which I could probably devise a test for but thought I'd ask first.

 

What happens if a script is still running from the last time when it gets to the next scheduled time? I notice while it's running the buttons to manually run it are greyed out. Does it start a new instance or does it skip until the next run?

Edited by beatles1
Link to comment

I am trying to write a script to rsync from another server. I want to schedule the script without using any argument. However I would like to have the options to add arguments when run in Foreground. The intent is that the script would rsync new files without deleting files that have been deleted on the source server, but from time to time I can run the script in foreground passing the --delete or --dry-run flag. I created that simple test script:

#!/bin/bash
#argumentDescription=Useful options: --delete --dry-run -v --stats --progress
#argumentDefault=

echo aaaa
echo arguments: $@
echo aaaa

When I run the script in foreground, the box popup with the "useful options" message and an empty arguments text box. If I enter an argument, it works as intended and echo the argument. If I leave the box empty, nothing happens. I don't get any popup page showing that the script gets executed.  It runs as expected in background.

 

I tried removing the "#argumentDefault=" line, and I get the same behavior. Ideas?

Link to comment
On 11/16/2022 at 5:03 PM, RedSpider said:

hello, user-scripts noob here. having some issues getting this to work right, i am trying to get it to run steam-lancache-prefill on a schedule, but it doesn't seem to be passing the `prefill` arg. Am i doing something wrong?

 

 

I've written up documentation to help with getting SteamPrefill setup with User Scripts.  You can find it here : https://tpill90.github.io/steam-lancache-prefill/install-guides/Unraid-Setup-Guide/

Please let me know if that works out for you, or if there is anything unclear that needs to be improved.

Link to comment

I want to turn off my server every night, but I don't get it working for some reason. The script works when I press "Run script in background" (the server shuts down):

#!/bin/bash
/sbin/poweroff

 

`/etc/cron.d/root` looks fine I guess:

 

root@Nano:~# cat /etc/cron.d/root

...

# Generated cron schedule for user.scripts
0 21 * * * /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/power_down/script > /dev/null 2>&1

 

Any ideas?

Link to comment

Hi, not sure what I'm doing but have written a simple script to run a script in a docker container:

#!/bin/bash
#backgroundOnly=true
docker exec -ti binhex-delugevpn sh "/config/tun_up.sh"

If I run the docker exec.... line in the terminal it works and returns a success message, but when I run this script it doesn't seem to work and the log shows:

the input device is not a TTY
Script Finished Dec 06, 2022 20:19.41

 

It links to a full log that doesn't work?

What have I done wrong please?

Cheers,

Tim

Link to comment
  • 2 weeks later...

Hi everyone,

 

I have two Unraid pro servers which both have a scheduled task under the "user scripts" plugin to scrub my zfs pool.  On my main server the script runs on a schedule without issue.  Recently I noticed that the second server's script has not been running on the same schedule.  I compared the setting between the two servers, and they match.  I uninstalled, rebooted, and re-installed the "users scripts" plugin, but it still appears to not run on the schedule.  Running the task manually does indeed work, it appears to simply not adhere to the schedule.

 

What am I missing here?  Feels like it must be something obvious.  Here is my diagnostics from the second server that does not run the scheduled task.

ur2-diagnostics-20221215-1546.zip

Edited by calvados
Link to comment

Is it possible to run a given user script on multiple schedules? For example, I’d want one to run at array start, and weekly at say Friday at 8pm.

 

is the only way to do this to create a second user script that either dupes the first script and set that to the second schedule, or have a second user script that just calls the script of the first?

Link to comment
5 hours ago, tmchow said:

is the only way to do this to create a second user script that either dupes the first script and set that to the second schedule, or have a second user script that just calls the script of the first?

Yes.  I have the former (a script that puts the Nvidia card into power-save mode).  It's duplicated so that it runs on array start, and then hourly.

 

(from a SpaceInvaderOne video)

Link to comment

Could I get some help please?....Hope this is the right place.

 

I would like to make two scrips

1) copy my appdata "share"

2) copy my "plugins folder"

 

I am doing the following respectively

1) "cp -r /mnt/user/appdata /mnt/user/Documents/8.Server/Unriad appdata"

2) "cp -r /usr/local/emhttp/plugins /mnt/user/Documents/8.Server/Unriad plugins"

 

In both cases the scrip says the the folder "appdata" and "plugins" does not exist

This must be a permissions issue correct?

 

I don't want to mess around with commands like chmod 777 for instance and break things

 

I know there are other methods to back up but I just feel more comfortable doing this as apposed to messing around with random applications.

 

(a bit of background, I have a script that copies my "Documents" folder to another server)

(I connected to this server (smb share) using unassigned devices, did a test and it works.....yay)

Hope that gives some insight as to what I am trying to achieve.

 

I would appreciate and ideas to get this working, thank you

Edited by BAZOOKAPANDA
Link to comment
29 minutes ago, BAZOOKAPANDA said:

1) copy my appdata "share"

There is already a plugin for that.

 

29 minutes ago, BAZOOKAPANDA said:

2) copy my "plugins folder"

Your plugins are on the flash drive and are installed from there at each boot.

 

You must always keep a current backup of flash.

Link to comment
11 minutes ago, trurl said:

There is already a plugin for that.

 

Your plugins are on the flash drive and are installed from there at each boot.

 

You must always keep a current backup of flash.

 

So I can backup my "plugins" directory by backing up my flash drive.

I think I remember seeing a guide for that, some button build into the web GUI

 

Can you elaborate on the plugin for backing up my appdata directory?

 

Thank you

Link to comment

 

I use this script daily to backup my flash drive to a zip file and it deletes the backups that are over 30 days old.

#!/bin/bash

source /root/.bash_profile

backup="/mnt/user/Backup/Flash"
mkdir -p "$backup"

date=$(date +"%Y-%m-%d-%H-%M-%S-%Z")
filename="flash.$date.zip"

echo Compressing flash backup \"$filename\"
cd /boot
zip -r "$backup/$filename" .* *

chown -R nobody:users "$backup"
chmod -R ug+rw,ug+X,o-rwx "$backup"

echo Removing backups over 30 days old
find "$backup" -mtime +30 -type f -delete -print

backupFlash.sh

 

Edit:

Added quotes around everything incase people wanted to add spaces in the backup directory name and/or the backup file name.

 

Edited by JoeUnraidUser
Link to comment

When tmux has no running sessions and I start a new tmux session on one of my bash scripts via User Scripts' GUI, tmux is started without sourcing .tmux.conf (at least based on it looking incredibly bare-bones and none of my keybinds working).

 

When I run the same script in the terminal by just running `bash <SCRIPT>`, tmux is started perfectly fine with .tmux.conf sourced. I've tried changing the script to a zsh script and a sh script, but neither has worked.

 

Curiously, when there are already other tmux sessions running, the User Scripts-created tmux session sources .tmux.conf perfectly fine.

 

Does anyone know any possible fixes to this? Thanks in advance

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.