[Plugin] CA User Scripts


Recommended Posts

Hi

none of my scripts are running, so I have tried to manually run then the same way the plugin does ie
 

echo /usr/local/emhttp/plugins/user.scripts/startBackground.php /tmp/user.scripts/tmpScripts/arrayStartup/script | at NOW -M > /dev/null 2>&1

 

and in the /var/log/syslog there is this error:

Oct  4 10:42:51 Gen8 atd[9567]: PAM unable to dlopen(/lib64/security/pam_unix.so): /lib64/libc.so.6: version `GLIBC_2.32' not found (required by /lib64/libpthread.so.0)
Oct  4 10:42:51 Gen8 atd[9567]: PAM adding faulty module: /lib64/security/pam_unix.so
Oct  4 10:42:51 Gen8 kernel: atd[9567]: segfault at 0 ip 00001516594bf886 sp 00007ffc66660bb0 error 4 in libpthread-2.33.so[1516594bf000+f000]
Oct  4 10:42:51 Gen8 kernel: Code: 00 48 c7 82 e8 02 00 00 e0 ff ff ff b8 11 01 00 00 66 48 0f 6e c7 66 0f 6c c0 0f 11 82 d8 02 00 00 0f 05 48 8b 05 3a 57 01 00 <48> 8b 00 64 48 89 04 25 98 06 00 00 0f b6 05 6f 5a 01 00 64 88 04

 

Link to comment
4 minutes ago, Isanderthul said:

Hi

none of my scripts are running, so I have tried to manually run then the same way the plugin does ie
 

echo /usr/local/emhttp/plugins/user.scripts/startBackground.php /tmp/user.scripts/tmpScripts/arrayStartup/script | at NOW -M > /dev/null 2>&1

 

and in the /var/log/syslog there is this error:

Oct  4 10:42:51 Gen8 atd[9567]: PAM unable to dlopen(/lib64/security/pam_unix.so): /lib64/libc.so.6: version `GLIBC_2.32' not found (required by /lib64/libpthread.so.0)
Oct  4 10:42:51 Gen8 atd[9567]: PAM adding faulty module: /lib64/security/pam_unix.so
Oct  4 10:42:51 Gen8 kernel: atd[9567]: segfault at 0 ip 00001516594bf886 sp 00007ffc66660bb0 error 4 in libpthread-2.33.so[1516594bf000+f000]
Oct  4 10:42:51 Gen8 kernel: Code: 00 48 c7 82 e8 02 00 00 e0 ff ff ff b8 11 01 00 00 66 48 0f 6e c7 66 0f 6c c0 0f 11 82 d8 02 00 00 0f 05 48 8b 05 3a 57 01 00 <48> 8b 00 64 48 89 04 25 98 06 00 00 0f b6 05 6f 5a 01 00 64 88 04

 

I think I might be causing this by installing aaa_glibc-solibs-2.33-x86_64-3.txz in my /boot/extras

Link to comment
20 hours ago, Isanderthul said:

I think I might be causing this by installing aaa_glibc-solibs-2.33-x86_64-3.txz in my /boot/extras

Ah now I realised I needed aaa_glibc-solibs-2.33-x86_64-3.txz for vim. But I need scripts more than I need vim... so 🤷‍♂️.

Link to comment

Hey guys,

 

I have a problem. Currently I use User Scripts for controlling my fans. For this I have two scripts. One for the night and one for the day. Always when I go to bed, I abort the day script and start the night one. After some time I noticed, my script stopped working and throws the same error again and again. The error itself has nothing to do with user script. It only made me realize
something. When I press abort, the script itself doesn't get killed. Here you can see the output of ps -ax | grep script after I aborted the script:

 

1020191156_Screenshot2021-10-10at17_23_59.thumb.png.8eff26168acc26d8dbe82e6115b19b31.png

The highlighted process is the process I aborted. It is still running which obviously is an issue. The first time I had 20 processes running without noticing. All doing the same thing which overloaded my ipmi controller. I attached the script to this comment. fan-script.sh Why does user script not kill the script. This is what I expect when I press abort. Or is it even a problem of my script?

 

Link to comment
19 hours ago, Squid said:

If the user script spawns another script / process that won't exit, then the main script stays running.

 

Stopping spawned processes automatically is a royal PITA

But it doesn't spawn any new process. The content of fan-script.sh is the content of the user script.

Link to comment

Hey all,

 

I was thinking that my UPS would run for much longer if some other dockers were not running during a power outage. I also figured user scripts would be my best bet at accomplishing this. 

 

Has anyone attempted this or found any resources for this?

Link to comment
On 2/15/2021 at 7:17 AM, Squid said:

 

You would need to do this:

 

Create the file called /usr/local/emhttp/plugins/myscript/script.page

Menu="Tasks:80"
Name="My Script"
Type="xmenu"
Tabs="true"
Code="e942"

You can move where the tab is located by adjusting the number within "Menu" as per the tab numbering here: https://forums.unraid.net/topic/57109-plugin-custom-tab/

 

 

 

Create another file called /usr/local/emhttp/plugins/myscript/myscript.page

Menu="script"
---
<?
echo "<h1>Running script</h1><br><br>";

passthru("/bin/bash /boot/myscript.sh");
?>

Change the bash command appropriately within "passthru"

 

Note: The page will keep loading while the script executes.  If you're planning on doing something like starting a long running script (rsync?) by doing this, then the script that you call has to start another script via the "AT" command in bash.

 

The screen does not update as the script executes, but will only be updated once the script is finished.

 

If after starting the script you want the GUI to go back to where ever you were at prior to clicking the custom tab, then add to the second file

<script>history.back();</script>

 

ALL of these files need to be saved with standard linux line endings (use Notepad++)

 

Copy the files to the folder in RAM via the userscripts plugin (or go file) at first boot

 

While trying to track down a random kernel panic issue I am dealing with, I decided to upgrade to 6.10. After doing this the above script method does not seem to be working anymore?

 

The tab is still there but when I click it I just get a 404 error?

 

I checked and the files are still copied to the same location on array start and the script is unchanged from what was working yesterday?

 

Any ideas why it is not working today after the update?

 

I use this all the time, it is VERY handy. Cuts as much as 150-200w off the power draw when it is not doing anything time sensitive and I can crank it back up when I am working with it directly.

Edited by TexasUnraid
Link to comment
35 minutes ago, Squid said:

There is zero difference between 6.10 and 6.9 (or earlier versions all the way down to 6.0) with regards to this.  You'd have to post the exact .page file you're using etc

 

Ok, here is the script.page file:

 

Menu="Tasks:94"
Name="CPU Power"
Type="xmenu"
Tabs="true"
Code="e942"

 

and the cpu-power-switch.page file

 

Menu="script"
---
<?
echo "<h1>Changing CPU Governer</h1><br><br>";

passthru("/bin/bash /boot/config/plugins/user.scripts/scripts/Power\ Governer\ switcher/script");
?>

<script>history.back();</script>

 

I noticed that the 404 error just adds /script to the server address. aka, unraid.local/script

 

Just confused since this all worked yesterday.

Link to comment

A quick report of a possible bug

I am using Unraid v6.9.2 with CA Userscripts v2021.03.10 

 

when running a script that references the home directory using '~'

If I run it in foreground (ie. click the "RUN SCRIPT" button) it runs OK

but it refuses to run if I do it in the background (ie. click the "RUN IN BACKGROUND" button)

 

I investigated a little, and it seems that when running in background, the script forgot to set the proper home directory.

 

I checked it with this simple script

#!/bin/bash
set | grep HOME

 

and the result if I run it in foreground is 

HOME=/root

 

while the result if I run it in background is

HOME=/

 

For the moment, this can be easily fixed with adding this line inside the script

export HOME=/root

 

I am not sure if this is intentional or a bug, hope that helps.

Link to comment
On 10/16/2021 at 4:26 PM, Squid said:

There is zero difference between 6.10 and 6.9 (or earlier versions all the way down to 6.0) with regards to this.  You'd have to post the exact .page file you're using etc

 

Was doing some more troubleshooting but since I have no idea how or why this works I am out of my depth. I did find this error in the syslog when clicking on the cpu power button though.

 

nginx: 2021/10/22 13:11:56 [error] 15209#15209: *138612 open() "/usr/local/emhttp/script" failed (2: No such file or directory) while sending to client, client: 192.168.x.xxx, server: xxx, request: "GET /script HTTP/2.0", host: "xxxxxxx.xxxxx", referrer: "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

 

I added the XXX's, the IP's and addresses were correct though.

 

It seems to be looking for the script in "/usr/local/emhttp/script" instead of /usr/local/emhttp/plugins/myscript/script.page?

 

No idea where to go from here.

Link to comment

@Squid 

My issue still persists. Here is a test script:

61713642_Screenshot2021-10-27at16_44_25.thumb.png.4047f199b5c9e7ae2deb2263f4e98974.png

 

After aborting it, the script process is still running:

 

1366726180_Screenshot2021-10-27at16_45_20.png.5644734dc475c1f64e11ea83d4d7d675.png

 

What am I doing wrong?!

 

This is how it gets spawned if I press background process:

550709164_Screenshot2021-10-27at16_48_27.png.0be54c7f5dc6a3931b9911edca04c345.png

The process 10197 survives if I press abort.

 

Plugin is up-to-date and running on unraid 6.9.2. 

 

  • Thanks 1
Link to comment

This is probably a simple question, but after an hour of searching, I have yet to find a definitive answer.

 

I have a working script that weekly will rsync several folders from my array to an external USB drive mounted with Unassigned Devices.  I have two drives (External_USB_1 and External_USB_2) which I swap on the beginning of the month, and I keep the unconnected drive off site.  My current solution has me manually editing my script each time I swap drives, to specify the correct destination drive.  I would much rather set and forget the script, and have it check for the drive to be present before executing rsync.

 

What would be the best way to check if these drives are present and mounted? 

 

UPDATE:  I have a solution that seems to work, but if someone has a better one, I'm open to your ideas.

 

I ended up using mountpoint. 

 

#!/bin/bash
#arrayStarted=true

if mountpoint -q "/mnt/disks/External_3TB_1"
then
   rsync -avh "/mnt/disks/Samsung_USB/UNRAID_Backups" "/mnt/user/Media/Music" "/mnt/user/Photos/ORIGINALS" "/mnt/user/Backup/appdata backup" "/mnt/disks/External_3TB_1"

else
   echo "External_3TB_1 not mounted"
fi

if mountpoint -q "/mnt/disks/External_3TB_2"
then
   rsync -avh "/mnt/disks/Samsung_USB/UNRAID_Backups" "/mnt/user/Media/Music" "/mnt/user/Photos/ORIGINALS" "/mnt/user/Backup/appdata backup" "/mnt/disks/External_3TB_2"

else
   echo "External_3TB_2 not mounted"
fi

 

Edited by ConnerVT
Solution?
Link to comment

I'm trying to run a script with the following custom cron schedule:

 

50 2 * * 2 [[ $(date +%e) -le 7 ]]

 

I wanted the script to run the 1st week of every month on Tuesday at 2:50am but it didn't run this past Tuesday.  I just copied the cron schedule for my parity check and made some modifications.  Do you see anything wrong with this cron schedule?

 

Link to comment
28 minutes ago, niwmik said:

I'm trying to run a script with the following custom cron schedule:

 

50 2 * * 2 [[ $(date +%e) -le 7 ]]

 

I wanted the script to run the 1st week of every month on Tuesday at 2:50am but it didn't run this past Tuesday.  I just copied the cron schedule for my parity check and made some modifications.  Do you see anything wrong with this cron schedule?

 

I have a cron I run in Ubuntu that is for the first Saturday of every month. My syntax is:

 

0 0 * * 6 [ $(date +\%d) -le 07 ] && /script/path/follows/here.sh

Link to comment
21 hours ago, cybrnook said:

I have a cron I run in Ubuntu that is for the first Saturday of every month. My syntax is:

 

0 0 * * 6 [ $(date +\%d) -le 07 ] && /script/path/follows/here.sh

 

Thanks for the tip.  I changed the cron schedule to "50 2 * * 4 [ $(date +%d) -le 07 ]" and it appears to have run this morning based on what it is in the logs.

 

Nov  4 02:50:01 Atlas crond[2264]: exit status 2 from user root [ $(date +\%d) -le 07 ] /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/AutoBackupVM/script > /dev/null 2>&1
 

However, AutoBackupVM script doesn't appeared to have ran.  I just ran it manually to test and it ran successfully.  Is there something else I'm missing?

 

Link to comment
2 minutes ago, wgstarks said:

i'm running the clear_array_drive script. The status window shows 2.2 MB/s. At this rate it's going to take about 21 days to complete.

Will it speed up? It's a part of the shrink array process but is it really necessary?

Speed sounds about right, the script is not optimized at all.

 

You can either write all zeroes to the data drive, or rebuild parity, either way works, but rebuilding parity is much quicker.

Link to comment
4 minutes ago, JonathanM said:

Speed sounds about right, the script is not optimized at all.

 

You can either write all zeroes to the data drive, or rebuild parity, either way works, but rebuilding parity is much quicker.

That's what I thought. Drive has already been emptied, so now I can just stop the array, remove the drive, create new config and rebuild parity. Did I miss anything?  

Edited by wgstarks
typo
Link to comment
20 hours ago, cybrnook said:

What is AutoBackupVM? I use my own script to backup VM's. Seems the script is exiting with status 2, so something is not happy.

 

When you run it by hand, after it completes what does "echo $?" return

 

AutoBackupVM is a script written by an Unraid user that I use to backup my Windows 10 VM.  I've never had an issue with it before.

 

I clicked "RUN SCRIPT" in User Scripts to manually run the script so I didn't have access to a terminal screen.

 

As a test, I changed the cron schedule from "Custom" to "Scheduled Monthly" and changed Monthly schedule in Scheduler to run on the 5th.

 

I didn't see anything in the logs this morning but AutoBackupVM did run successfully.  As far as I can tell, the script only fails when I set it to a custom cron schedule.

 

 

 

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.