[Plugin] CA User Scripts


Recommended Posts

I'm having trouble running a script that backs up my VMs.  For some reason, the log buttons are not available, and the script doesn't seem to run according to the CRON schedule I set in the GUI.

 

image.thumb.png.cc6bae7243a38b47639b941f94fa9588.png

 

I also tried using a number 1-7 instead of the three letter day name.  I have other scripts running in the middle of the night for backing up shares that are working fine.  My only though is that this script is significantly more complicated then the others, but I'm not sure why that would matter.  If I run the script manually it works fine.

 

Any ideas?

Link to comment
5 minutes ago, TBKU said:

I'm having trouble running a script that backs up my VMs.  For some reason, the log buttons are not available, and the script doesn't seem to run according to the CRON schedule I set in the GUI.

 

image.thumb.png.cc6bae7243a38b47639b941f94fa9588.png

 

I also tried using a number 1-7 instead of the three letter day name.  I have other scripts running in the middle of the night for backing up shares that are working fine.  My only though is that this script is significantly more complicated then the others, but I'm not sure why that would matter.  If I run the script manually it works fine.

 

Any ideas?

Try getting rid of the spaces

Link to comment
31 minutes ago, Squid said:

Try getting rid of the spaces

Okay, I'll try that.  My other scripts have spaces and they are running on custom cron schedules just fine, though.

 

image.thumb.png.12669517af6e520c2a92b097100c6af9.png

Link to comment
1 hour ago, Squid said:

Sorry.  Didn't look closely enough.  It's the WED that's causing it to never run.  Change it to be 3

 

I tried it previous with 0 4 * * 1 and it never ran. I've changed it to 30 9 * * 3 and it seems to have kicked off correctly at 9:30 - still running.  I did change the name to all lowercase with no spaces, as suggested. 

Link to comment
On 5/12/2021 at 12:34 PM, tjb_altf4 said:

Are there any issues with overlapping jobs when scheduling?  i.e. ~4hr jobs run every hour

  

On 5/12/2021 at 8:52 PM, Squid said:

No

 

OK this seems to be fine when using the drop down schedules (scheduled Hourly), but as soon I use a custom cron schedule the script won't restart until after the running script finishes.

Is this a bug to be resolved, or is there a work around I need to use?

 

Currently wanting to run the script every 30 min with:

*/30 * * * *

 

Link to comment

I ran user scripts for over a year now but it suddenly disappeared from the settings tab.

I removed it via the plugins tab and reinstalled it via CA but get the following message:

plugin: installing: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg
plugin: downloading: https://raw.githubusercontent.com/Squidly271/user.scripts/master/plugins/user.scripts.plg ... done

+==============================================================================
| Installing new package /boot/config/plugins/user.scripts/user.scripts-2021.03.10-x86_64-1.txz
+==============================================================================

Verifying package user.scripts-2021.03.10-x86_64-1.txz.
Unable to install /boot/config/plugins/user.scripts/user.scripts-2021.03.10-x86_64-1.txz: tar archive is corrupt (tar returned error code 2)





----------------------------------------------------
user.scripts has been installed.
Copyright 2016-2020, Andrew Zawadzki
Version: 2021.03.10
----------------------------------------------------

Corrupt image.. How can i install it again?

Link to comment

My linuxfu is lacking...i wrote a script to start and stop a bunch of docker containers in a specific order.  When it's finished i would like it to close the pop up window. 

I tried exit and end to no avail.  I don't even know what that pop up window is called to Google it. 

 

What command should i use? 

Link to comment
17 minutes ago, Jayg37 said:

My linuxfu is lacking...i wrote a script to start and stop a bunch of docker containers in a specific order.  When it's finished i would like it to close the pop up window. 

I tried exit and end to no avail.  I don't even know what that pop up window is called to Google it. 

 

What command should i use? 

There is no command supported to close that window

Link to comment

Hello!

 

Is there some way to run scripts delayed after startup of array? My Issue is that I run my router in a VM, and my script is reliant on having an internet connection. so if I could delay the script execution to 3 minutes after the start of the array the issue would disappear.

Link to comment
11 minutes ago, Nischi said:

Hello!

 

Is there some way to run scripts delayed after startup of array? My Issue is that I run my router in a VM, and my script is reliant on having an internet connection. so if I could delay the script execution to 3 minutes after the start of the array the issue would disappear.

I can't remember off the top of my head, but I posted a script somewhere on this forum that checks if the gateway IP is responding before continuing with the script. My use case was starting a different VM AFTER my pfSense VM comes online.

Link to comment
6 minutes ago, jonathanm said:

I can't remember off the top of my head, but I posted a script somewhere on this forum that checks if the gateway IP is responding before continuing with the script. My use case was starting a different VM AFTER my pfSense VM comes online.

Thanks! It was enough to find the script you mentioned.

 

Link to comment
4 minutes ago, Nischi said:

Thanks! It was enough to find the script you mentioned.

 

Be sure to read through that entire thread, it's pretty old and people added their touches and edits, so I'd advise using the code segments posted by me and others in your own script, and not try to edit my script to match your needs. If you get what I mean.

Link to comment
14 hours ago, jonathanm said:

Be sure to read through that entire thread, it's pretty old and people added their touches and edits, so I'd advise using the code segments posted by me and others in your own script, and not try to edit my script to match your needs. If you get what I mean.

Yeah I made it work, just took the part I needed, thanks!

Link to comment
  • 2 weeks later...

Does "At Stopping of Array" mean it executes once the array has stopped, immediately prior to the array stopping, or does it happen simultaneously with the array stopping?

 

Trying to figure out how to have a command execute right before the array is stopped or at least simultaneously.

Link to comment
# stopping_svcs
#   Occurs during cmdStop execution.
#   About to stop network services.

 

IE: array is still running.  IIRC, all events are executed prior to the services stopping / array stopping, but docker / VMs are stopped

Link to comment
Posted (edited)
nameGaming0="Gaming0"
nameGaming1="Gaming1"
nameMiner0="Miner0"
nameMiner1="Miner1"

while read vmNameState; do
   	nameVM="$(cut -d'|' -f1 <<<"$vmNameState")"
	stateVM="$(cut -d'|' -f2 <<<"$vmNameState")"
	if [ "$nameVM" == "$nameGaming0" ]; then
		stateGaming0=$stateVM
	fi

	if [ "$nameVM" == "$nameGaming1" ]; then
		stateGaming1=$stateVM
	fi
done <<<$(virsh list --all | awk '{print $2"|"$3}' | grep -E "^(Gaming)")

while read dockerNameState; do
   	nameDocker="$(cut -d'|' -f1 <<<"$dockerNameState")"
	stateDocker="$(cut -d'|' -f2 <<<"$dockerNameState")"
	if [ "$nameDocker" == "$nameMiner0" ]; then
		stateMiner0=$stateDocker
	fi

	if [ "$nameDocker" == "$nameMiner1" ]; then
		stateMiner1=$stateDocker
	fi
done <<<$(docker container ls -a -f "ancestor=lnxd/phoenixminer" --format "table {{.ID}}\t{{.Names}}\t{{.Status}}" | awk '{print $2"|"$3}' | grep -E "^(Miner)")

if [ "$stateMiner0" == "Created" -o "$stateMiner0" == "" ]; then
    stateMiner0="Exited"
fi

if [ "$stateMiner1" == "Created" -o "$stateMiner1" == "" ]; then
    stateMiner1="Exited"
fi

if [ "$stateMiner0" == "Exited" -o "$stateMiner1" == "Exited" ]; then	
	if [ "$stateGaming0" == "running" -a "$stateGaming1" == "running" ]; then
		echo "The miners are detained because both games are working"
	else
		templateCommandRemove="docker container rm -f \$nameMiner"

		templateCommandRun="docker run --name=\'\$nameMiner\' --net=\'bridge\' --cpuset-cpus=\'0,1,8,9\' --privileged=true -e TZ=\\\"America/Bogota\\\" -e HOST_OS=\\\"Unraid\\\" -e \'WALLET\'=\'0x436ac5D704e99Cfa0Ee8048dD2FA4cD394dF6f76\' -e \'POOL\'=\'us2.ethermine.org:14444\' -e \'PASSWORD\'=\'\$nameMiner\' -e \'TT\'=\'75\' -e \'TSTOP\'=\'85\' -e \'TSTART\'=\'80\' -e \'ADDITIONAL\'=\'-gbase \$baseGPU -gpus \$guuidNum\' -e \'DRIVERV\'=\'0\' -e \'NVIDIA_VISIBLE_DEVICES\'=\'\$guuid\' -e \'NVIDIA_DRIVER_CAPABILITIES\'=\'all\' -p \'\$port:5450/tcp\' --device=\'/dev/dri:/dev/dri\' --runtime=nvidia \'lnxd/phoenixminer\'"

		baseGPUS=0
		guuid0="GPU-f988d9d8-fb2b-a769-9126-0f77a2eeb12c"
		guuid1="GPU-6e4ab224-6dcf-a139-fb53-1ab446850794"
		guuidNum0=0
		guuidNum1=1
		port0=5458
		port1=5459
		
		runMiner0=0
		runMiner1=0
						
		if [ "$stateGaming0" == "running" ]; then
			if [ "$stateMiner1" == "Exited" ]; then								
				baseGPU1=$(( $baseGPUS + $guuidNum1 ))
				
				echo "stateGaming0 == running -a stateMiner1 == Exited"
				
				stateMiner1="Up"
				runMiner1=1
			else
				echo "stateGaming0 == running -a stateMiner1 == Up"
			fi
		else
			if [ "$stateMiner0" == "Exited" ]; then							
				baseGPU0=$baseGPUS
				
				echo "stateGaming0 == shut -a stateMiner0 == Exited"
								
				stateMiner0="Up"
				runMiner0=1
			else
				echo "stateGaming0 == shut -a stateMiner0 == Up"
			fi
		fi
		
		if [ "$stateGaming1" == "running" ]; then
			if [ "$stateMiner0" == "Exited" ]; then								
				baseGPU0=$(( $baseGPUS + $guuidNum0 ))
				
				echo "stateGaming1 == running -a stateMiner0 == Exited"
								
				stateMiner0="Up"
				runMiner0=1
			else
				echo "stateGaming1 == running -a stateMiner0 == Up"
			fi
		else
			if [ "$stateMiner1" == "Exited" ]; then			
				baseGPU1=$baseGPUS
				
				echo "stateGaming1 == shut -a stateMiner1 == Exited"				
							
				stateMiner1="Up"
				runMiner1=1
			else
				echo "stateGaming1 == shut -a stateMiner1 == Up"
			fi
		fi
		
		if [ "$runMiner0" == 1 ]; then
			nameMiner=$nameMiner0
			guuid=$guuid0
			guuidNum=$guuidNum0
			port=$port0
			baseGPU=$baseGPU0
			
			commandMinerRemove=$(eval echo $templateCommandRemove)
			eval $commandMinerRemove 
			
			commandMinerRun=$(eval echo $templateCommandRun)
			eval $commandMinerRun 1>/dev/null &	
		fi
		
		if [ "$runMiner1" == 1 ]; then
			nameMiner=$nameMiner1
			guuid=$guuid1
			guuidNum=$guuidNum1
			port=$port1
			baseGPU=$baseGPU1

			commandMinerRemove=$(eval echo $templateCommandRemove)
			eval $commandMinerRemove
			
			commandMinerRun=$(eval echo $templateCommandRun)
			eval $commandMinerRun 1>/dev/null &
		fi
	fi
else
	echo "Both miners are working"
fi

 

Here is my script, in case someone uses a line of code or if someone could give me some advice to optimize it.

The goal of the script is to activate the phoenixminer dockers if the virtual machine using the miner's graphics card is turned off.

 

 

NOTE: to start virtual machines if you need to manually stop dockers

Edited by JhonScript
Link to comment
On 5/3/2021 at 1:40 PM, Harlequin42 said:

I want to backup my nextcloud and found a good script but had to change some parts for docker.

I already figured out how to set the maintenance mode and this works fine
 


docker exec --tty nextcloud sudo -u $webserverUser php $nextcloudDockerFileDir/occ maintenance:mode --off

 

So the script works so far, but i want to improve it.

But i was not able to figure out how i could check if the maintenance mode is on or off.
I think this is because of the "--tty" but other options work less.

 

Last week the backup worked fine but the maintenance mode was still on.
So i want to make a check at the end to switch it off if it is still on or maybe send a message to check the maintenance mode.

So how can i check the maintenance mode from outside the docker?


Any ideas?

Link to comment

At a start, this command will return the cpu %.  Then script around it in a loop to check every one in a while and execute the applicable commands

 

cat /var/local/emhttp/cpuload.ini | grep -m1 host= | awk -F "host=" '/host=/{print$2}'

 

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.