[Plugin] CA User Scripts


Recommended Posts

5 hours ago, Squid said:

Because executing bash within a container by default means that its interactive, and the system is effectively waiting for you to enter in the commands

Try this


docker exec -t apache Step 0
docker exec -t apache Step 1
docker exec -t apache Step 2

 

 

great hint, 1 step further, thanks alot ;)

Link to comment
On 2017. 11. 18. at 2:20 PM, Squid said:

Without thinking too much:

 


#!/bin/bash
hdparm -C /dev/sdb >> /mnt/user/sharename/status.txt  #change path to suit
smartctl -a /dev/sdb | grep Temperature >> /mnt/user/sharename/status.txt
#repeat for more disks

sensors | grep Fan >> /mnt/user/sharename/status.txt

And running at whatever schedule you choose.

Thank you very much!

Link to comment
  • 2 weeks later...

hi again, may another question about exec

 

i get an cannot exec binary error when trying to copy ...

docker exec -t apache bash ./bin/cp /etc/letsencrypt/live/mydomain.de/*.pem /config/keys
./bin/cp: ./bin/cp: cannot execute binary file
 

while this command working fine

docker exec -t apache bash ./config/certbot/certbot-auto -n --config /config/certbot/cli.ini certonly

 

may an idea what this cannot access binary could mean ? inside docker it works as expected ...

for an tip, thanks ahead ;)

Link to comment
8 minutes ago, itimpi said:

The leading ‘.’ on the commands will make them relative to a home folder.   For ‘cp’ this will not work as you need an absolute path to the binary.

 

same result, also tested it without the ".", forgot to mention ;)

 

root@AlsServer:~# docker exec -t apache bash /bin/cp /etc/letsencrypt/live/mydomain.de/*.pem /config/keys
/bin/cp: /bin/cp: cannot execute binary file

Edited by alturismo
Link to comment
3 minutes ago, alturismo said:

 

same result, also tested it without the .

 

root@AlsServer:~# docker exec -t apache bash /bin/cp /etc/letsencrypt/live/mydomain.de/*.pem /config/keys
/bin/cp: /bin/cp: cannot execute binary file
 

That probably means that the ‘cp’ command is not located in /bin inside the container.     You could try omitting the /bin part to use the search path, or instead try using /user/bin in case that is where it is located.

Link to comment

hmm

 

root@AlsServer:~# docker exec -ti apache bash
root@AlsServer:/# ls
app  boot    defaults  etc   lib    media  opt   root  sbin  sys  usr  webdav
bin  config  dev       home  lib64  mnt    proc  run   srv   tmp  var
root@AlsServer:/# cd bin
root@AlsServer:/bin# ls -la
total 6532
...
-rwxr-xr-x 1 root root  130304 Mar 10  2016 cp

....

may i miss something ?

 

EDIT, its been symlinked files ... that was the reason, docker cp -L ... seems to work, thanks again

Edited by alturismo
Link to comment

Bus errors are when the system tries to execute a command on an odd memory address.  Ultimately this is a bug in PHP / Linux Kernel as its impossible for a script to do this.  You can try running a memtest to rule that out, but it happens maybe once every couple of months on my AMD system for absolutely zero reason.

 

IE: ignore it 

Link to comment
Hello,

 

I love this plugin.  I did have a question....whenver I had cron tabs running via /boot/config/plugins/dynamix/ I got an email after each cron task was completed.  When I run the same job via this GUI, I do not get an email alert with success or fail.  Any ideas?

Because this plugin doesn't directly execute any script. It calls a proxy which then executes the script. Net result is that you will never see an email from cron that the return code from your script was non zero. Any notifications you want from your script you will have to do via the notify commabd

 

And via basically adding the cron entry yourself as you were you were getting an email that your script returned a non zero return value (ie that it failed or had an error) return values of zero (success) don't send an email

Link to comment

Hi,

 

I have scripts that I want to run when I'm not home. I can track my presence using my HomeAssistant setup, however the execution of the script is what I'm stuck on. I tried HTTP POST'ing the URL, but it looks like the script execution buttons are in JS, which won't work for cURL requests.

 

My next attempt would be having a script SSH into the unRAID server and kickoff the script over SSH. Is there an easier way to do this?

Link to comment

The execution order is

 

Button (JavaScript) -> Wrapper (PHP) -> Actual Script (whatever interpreter you choose)

or via a scheduled script,

Wrapper (PHP) -> Actual Script

 

The actual scripts are scripts as in something you would run from the command line (ie: bash, PHP, python, etc)

 

Nothing is stopping you from using curl in bash or in PHP.  You could probably do it via JavaScript by installing nodejs via the NerdPack

 

This is all for background tasks.  You can however run JavaScript & any HTML via a foreground script.  See that PacMan additional script

Link to comment

Can I get some help with what should be a simple script please for someone who unlike me, knows what they are doing.

 

I run a pfSense VM which means my bootup is very slow as unRAID starts docker before VMs and each docker checks for online access before the next one starts - all in all this adds a 20--30min delay before my server boots.

 

As a temp fix, what I've started doing is disable Docker in unraid's settings before rebooting and then manually turning docker on once the pfSense VM provides connectivity.

 

What I'd like to do is add a script that runs at array start and manually starts Docker once it successfully pings 172.30.12.1 which is the address of my pfSense VM - similar to how the docker autostart manager does i.e. check if can ping 172.30.12.1, if yes, start docker, if fails after say 10 mins (customisable would be nice) then start docker anyway

 

If someone can help me with this script (I know how to start individual dockers via the command line, but not the whole docker manager).  I'll copy the script to make another one to stop docker when the array stops.

 

Thanks in advance

Link to comment

This isn't entirely what you're looking for but here's tidbits that I'm just throwing stuff out there...

 

If you can't work out the ping and network connectivity testing you could schedule a script to start docker 10 minutes after bootup.

 


echo /etc/rc.d/rc.docker start | at now + 10 min

 

To control docker from a whole you can use /etc/rc.d/rc.docker. That script has the following parameters:

  • start
  • stop
  • restart
  • status
  • Like 1
Link to comment
49 minutes ago, BRiT said:

This isn't entirely what you're looking for but here's tidbits that I'm just throwing stuff out there...

 

If you can't work out the ping and network connectivity testing you could schedule a script to start docker 10 minutes after bootup.

 

 


echo /etc/rc.d/rc.docker start | at now + 10 min

 

 

To control docker from a whole you can use /etc/rc.d/rc.docker. That script has the following parameters:

  • start
  • stop
  • restart
  • status

Thanks so far, I've got:

 

#!/bin/bash

echo /etc/rc.d/rc.docker stop
echo /etc/rc.d/rc.docker start | at now + 10 min
docker restart $(docker ps -a -q)

Line 1 is so I can leave settings\Docker 'Enable Docker' set to 'yes'.  I think I need this as otherwise I won't have the dockers tab in the GUI.  My thinking is:

 

- step 1, stop the dockers

- step 2 start  docker again in 10 mins (and re-populate the Docker tab in the GUI)

- step 3 start all containers - the command you shared didn't start the containers

 

If I can't get the ping test working I'll just go with this and if I'm at the keyboard I'll start the dockers quicker manually.

 

 

 

 

seems to stop the dockers (actually hides them from the GUI) but leaves the empty Docker tab visible

Link to comment
  • 2 weeks later...

You can do something like

/usr/local/emhttp/webGui/scripts/notify -e "rsync log" -m "$(cat /tmp/logfile.txt)" -i "warning"

This is a bash example and assumes the log file of rsync is /tmp/logfile.txt which is included using the -m option (don't forget the quotes).

Edited by bonienl
Link to comment
22 minutes ago, bonienl said:

You can do something like


/usr/local/emhttp/webGui/scripts/notify -e "rsync log" -m "$(cat /tmp/logfile.txt)" -i "warning"

This is a bash example and assumes the log file of rsync is /tmp/logfile.txt which is included using the -m option (don't forget the quotes).

It just important to note that the above assumes that the logfile doesn't contain any " characters - or that any " characters have been preprocessed with a break character like \"

 

It is extra important to realize that if someone can manipulate the logfile.txt contents, the above construct could allow a second (and most probably quite evil) command to be run directly after the notify command. What a joy it would be with a logfile.txt that contains

Bye, bye..."; rm -rf /mnt/disk*; echo " ...array data


Best would be if the notify script supported an alternative form that takes a filename instead of a direct string.

Link to comment

If the log file is not just plain text but has "special" characters then bash isn't the right language to call notify. A language like PHP allows you to escape special characters, including quotes. This has been done for the GUI to avoid the potential risk of executing commands as explained by pwm.

 

Edited by bonienl
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.