[Plugin] CA User Scripts


1283 posts in this topic Last Reply

Recommended Posts

  • Replies 1.3k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Just a simple little plugin to act as a front end for any little scripts that you may have that you may need to run every once in a while, and don't feel like dropping down to the command line to do i

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

@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

4 minutes ago, wgstarks said:

IIRC it will use the daily schedule set in Scheduler.

Adjustable if you have The Schedules plugin installed

Link to post

Since running mover with a docker up potentially causes everything up to hangs that force you to do a hard reset, I want to check my work before putting this in. 

So every night at 2am I shut down Unraid using a script with the powerdown command. About 15 minutes after that the zwave box its plugged into cuts power. In the morning power is restored and based on a bios setting the Unraid box comes up. This allows me to shave power usage by 25% every day since it's a 6 hour outage when we're all supposed to be sleeping. I do have a zwave button on the 2nd floor that allows me to easily turn it back on without having to traverse the basement should it be a late TV night. So far I haven't had to use it. 

Anyway, I thought the morning would be a great time to run mover. So I'm going to have Unraid come up at 7:30AM, and 5 minutes later run mover. What I'd like to do is have a docker start after mover ends. This is what I have. Please confirm. 
 

mover &&
docker start Emby-01

 

That just feels entirely too simple, so again, please confirm. 

******Update*******

Never mind. I got impatient and tested it. Works beautifully. I just wasn't sure how mover worked, and wanted to be sure the subsequent command waited until it was completely finished. 

So the server goes down at 2am, the power is cut 15 minutes later to ensure a clean shutdown. Around 7:30am the power is restored, and as per the bios setting the server turns on. 7 minutes later the mover script executes, and when that's done the dockers and VMs will start. Presto, 5.5 hours off the electric bill, no more crazy box-hanging conflicts with mover, and docker gets bounced once a day so no more if not at least less Docker hangs. No weird issues with mover and spinning up drives either since it goes off right after a startup. 

Edited by NAStyBox
Self-addressed
Link to post

I am looking for a script that does the following:

- check if cache is more than 60% ful 

- If so, then pause/stop all torrents in rtorrent and start mover

- if cache is less than 60% full do nothing

 

Anyone got a script like this?

Link to post
On 3/25/2021 at 5:33 PM, ProphetSe7en said:

I am looking for a script that does the following:

- check if cache is more than 60% ful 

- If so, then pause/stop all torrents in rtorrent and start mover

- if cache is less than 60% full do nothing

 

Anyone got a script like this?

 

Link to post
  • 2 weeks later...
11 minutes ago, ProphetSe7en said:

Thanks. That covers one part of want I want. Still need to figure out how to stop/pause all torrents and then restart them after mover is done

Without delving into whether it's possible to interact with rtorrent at that level, can't you just stop and start the docker with "docker stop <name-of-container>" and "docker start <name-of-container>" commands?

Link to post

Probably, but stopping a torrent container can cause problems if a torrent is during dl or recently finished and no session has been saved the last 20 minutes. So I prefere to sett all active torrents in a pause state, run mover then resume all torrents

Link to post
29 minutes ago, ProphetSe7en said:

Probably, but stopping a torrent container can cause problems if a torrent is during dl or recently finished and no session has been saved the last 20 minutes. So I prefere to sett all active torrents in a pause state, run mover then resume all torrents

docker pause <name-of-container> / docker unpause <name-of-container> then?

Link to post

Hmm. That might work, need to test it first :)

Do you know if it is possible to issue the pause command only if cache is >60% full? No need to pause the container if mover wont run because of cache drive is less the 60% full.

 

I know mover can be started using script, and from mover settings it wont run if cache is less than 60%. But while doing this with a script it will cause rtorrent to pause/resume each time the script runs regardless of mover will be running or not

 

Edit: So I need to add the pause & unpause command to the mover script? Clearly the "docker pause/unpause rtorrentvpn" wont work like this, but what format should it be in to work?
 

if ( $percent > $moveAt ) {
  docker pause rtorrentvpn;
  exec("/usr/local/sbin/mover");
  docker unpause rtorrentvpn;
}

 

Edited by ProphetSe7en
Link to post
1 hour ago, ProphetSe7en said:

Clearly the "docker pause/unpause rtorrentvpn" wont work like this, but what format should it be in to work?

I'm not at my machine at the moment, but somebody else would know better.  Your script would pause the docker (assuming that's the correct name), but I'm guessing it would unpause it straight away.

 

You'd need a second part to the script in an else block that checks if docker is paused and whether the mover is running.  If the mover has finished, unpause.  Something like...

 

if ( $percent > $moveAt ) {
  docker pause rtorrentvpn;
  exec("/usr/local/sbin/mover");
} else {
  if (!moverRunning && dockerIsPaused) {
    docker unpause rtorrentvpn;
  }
}

...although without researching I don't know how to check if the mover is running and a docker is paused - this is just to illustrate the concept.

Link to post
6 hours ago, Cessquill said:

I'm not at my machine at the moment, but somebody else would know better.  Your script would pause the docker (assuming that's the correct name), but I'm guessing it would unpause it straight away.

 

You'd need a second part to the script in an else block that checks if docker is paused and whether the mover is running.  If the mover has finished, unpause.  Something like...

 

Hmm. I thought if I put the command under the "if" part of that script it would only be issued if the cache disk is >xx% ful, like the mover would in the script?

 

Maybe I am mistaken, but in this script everything under "if" only runs if the disk threshold is met?

 

#!/usr/bin/php
<?PHP

$moveAt = 70;    # Adjust this value to suit.

$diskTotal = disk_total_space("/mnt/cache");
$diskFree = disk_free_space("/mnt/cache");
$percent = ($diskTotal - $diskFree) / $diskTotal * 100;

if ( $percent > $moveAt ) {
  exec("/usr/local/sbin/mover");
}
?>

 

So I need to figure out on how to combine the script above with these commands.

 

docker exec comand

mover &&

docker exec comand (when mover is finished)

 

Not very elegant, but can I replace  

exec("/usr/local/sbin/mover");

 with

exec("/mnt/user/various/unRaid/script/mover.sh);

 

Then in the mover.sh I have the 

docker exec (command to pause all torrents)
mover &&
docker exec (command to start all torrents)

 

I get it to work, but then I dont have the threshold part in place.

Link to post

Hey all,

This might be a more generic unix question but is there an easy way to enable timestamps for all logs that a "userscript" would produce?

quick googling i can do things like pipe my commands into various things to achieve this but i was wondering if there was an easy "turn on for everything in unraid" or maybe just "turn on for user scripts logs"?

Thanks in advance!

Link to post
  • 3 weeks later...

Hello,

i hava a cron job problem.

I can't create a job with letters in day. This cron syntax 

40 7 * * Tue

sends an error in log "failed parsing crontab for user root: TUE" but 

40 7 * * 2 works

Link to post

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?

Link to post

Hey all,

 

I'm migrating from and Ubuntu based server and I was trying to set back up one of my scripts.

 

It's a simple script that uses inotifywait to watch a folder and then emails (via mutt) any new pdf files to my kindle.

 

The inotify part works well enough but obviously mutt isn't part of unraid. Is there a command line alternative or even a simple docker container I could use to the same effect? (Short of running a linux vm lol)

Link to post
10 hours ago, cavinyagi said:

Hey all,

 

I'm migrating from and Ubuntu based server and I was trying to set back up one of my scripts.

 

It's a simple script that uses inotifywait to watch a folder and then emails (via mutt) any new pdf files to my kindle.

 

The inotify part works well enough but obviously mutt isn't part of unraid. Is there a command line alternative or even a simple docker container I could use to the same effect? (Short of running a linux vm lol)

If it's not already available within the NerdPack plugin, then you can ask for it to be added, or install (or build from source) a slackware package.

Link to post
4 hours ago, Squid said:

If it's not already available within the NerdPack plugin, then you can ask for it to be added, or install (or build from source) a slackware package.

Quite a newbie so didn't know about Nerdpack - although mutt (or alt) doesn't seem to be included yet. I may request as you've suggested but I'll try and install one myself first I think as why not? haha

 

Thanks for the help!

Link to post
Posted (edited)

My unraid box has a bit of a custom arrangement, where the GPU has 2x oversized fans - one blows on the GPU directly, and the other on the array drives and the GPU. The GPU controls one of the fans, and unraid controls the array fan.

 

I am trying to set up the ability to calculate and compare a required PWM value for the array drives and the GPU, and then decide which is higher and apply it to the array fan.

 

In my windows VM I use nvidia-smi with a timeout -t 5 loop running on a schedule to constantly update a txt file on the cache drive which unraid can read. This part seems to work ok, windows updates the txt file with the fan % value.

 

I have included in the array fan script (which I found on these forums) an arrangement which takes the percentage and converts it to PWM.

 

The issue is - it does not work with the file that is being dynamically updated by windows, but it does work with a static test file which was created by me in windows and is sitting in the exact same location!

 

I'm pulling my hair out on this, I can't work out why it is not working...any thoughts?

 

#!/bin/bash
# unraid_array_fan.sh v0.4
# v0.1  First try at it.
# v0.2: Made a small change so the fan speed on low doesn't fluctuate every time the script is run.
# v0.3: It will now enable fan speed change before trying to change it. I missed 
#	it at first because pwmconfig was doing it for me while I was testing the fan.
# v0.4: Corrected temp reading to "Temperature_Celsius" as my new Seagate drive
#	was returning two numbers with just "Temperature".
# A simple script to check for the highest hard disk temperatures in an array
# or backplane and then set the fan to an apropriate speed. Fan needs to be connected
# to motherboard with pwm support, not array.
# DEPENDS ON:grep,awk,smartctl,hdparm

### VARIABLES FOR USER TO SET ###
# Amount of drives in the array. Make sure it matches the amount you filled out below.
NUM_OF_DRIVES=2

# unRAID drives that are in the array/backplane of the fan we need to control
HD[1]=/dev/sdd
HD[2]=/dev/sde
#HD[3]=/dev/nvme0n1
#HD[4]=/dev/sdc
#HD[5]=/dev/sdf
#HD[6]=/dev/sdg

# Temperatures to change fan speed at
# Any temp between OFF and HIGH will cause fan to run on low speed setting 
FAN_OFF_TEMP=47		# Anything this number and below - fan is off
FAN_HIGH_TEMP=60	# Anything this number or above - fan is high speed

# Fan speed settings. Run pwmconfig (part of the lm_sensors package) to determine 
# what numbers you want to use for your fan pwm settings. Should not need to
# change the OFF variable, only the LOW and maybe also HIGH to what you desire.
# Any real number between 0 and 255.
FAN_OFF_PWM=55
FAN_LOW_PWM=55
FAN_HIGH_PWM=255

# Calculate size of increments.
FAN_TEMP_INCREMENTS=$(($FAN_HIGH_TEMP-$FAN_OFF_TEMP))
FAN_PWM_INCREMENTS=$(($(($FAN_HIGH_PWM-$FAN_LOW_PWM))/$FAN_TEMP_INCREMENTS))

# Fan device. Depends on your system. pwmconfig can help with finding this out. 
# pwm1 is usually the cpu fan. You can "cat /sys/class/hwmon/hwmon0/device/fan1_input"
# or fan2_input and so on to see the current rpm of the fan. If 0 then fan is off or 
# there is no fan connected or motherboard can't read rpm of fan.
ARRAY_FAN=/sys/devices/platform/nct6775.656/hwmon/hwmon2/pwm7

### END USER SET VARIABLES ###

#GPU1=1
#GPUFAN=1

GPU1=$(cat /mnt/cache/windows10scratch/w10system/nvidiafan/gpufan.txt)
#echo $GPU1
#if [[ "$GPU1" == "" ]]; then
#    GPU1=1
#elif [[ "$GPU1" == 0 ]]; then
#    GPU1=1
#fi

GPU1=$((GPU1 + 1))
GPUFAN=$(($((GPU1 * 255)) / 100))

echo "GPU1 is "$GPU1

echo "GPUFAN is "$GPUFAN

# Program variables - do not modify
HIGHEST_TEMP=0
CURRENT_DRIVE=1
CURRENT_TEMP=0

# while loop to get the highest temperature of active drives. 
# If all are spun down then high temp will be set to 0.
while [ "$CURRENT_DRIVE" -le "$NUM_OF_DRIVES" ]
do
 SLEEPING=`hdparm -C ${HD[$CURRENT_DRIVE]} | grep -c standby`
 if [ "$SLEEPING" == "0" ]; then
   CURRENT_TEMP=`smartctl -d ata -A ${HD[$CURRENT_DRIVE]} | grep -m 1 -i Temperature_Celsius | awk '{print $10}'`
   if [ "$HIGHEST_TEMP" -le "$CURRENT_TEMP" ]; then
     HIGHEST_TEMP=$CURRENT_TEMP
   fi
 fi
#echo $CURRENT_TEMP
 let "CURRENT_DRIVE+=1"
done
echo "Highest temp is: "$HIGHEST_TEMP



# Calculate new fan values based on highest drive temperature
  if [[ $HIGHEST_TEMP -le $FAN_OFF_TEMP ]]; then
    ADJUSTED_FAN_SPEED=$FAN_OFF_PWM
    ADJUSTED_PERCENT_SPEED=0
    ADJUSTED_OUTPUT="OFF"
  else
    if [[ $HIGHEST_TEMP -ge $FAN_HIGH_TEMP ]]; then
      ADJUSTED_FAN_SPEED=$FAN_HIGH_PWM
      ADJUSTED_PERCENT_SPEED=100
      ADJUSTED_OUTPUT="FULL"
    else
      ADJUSTED_FAN_SPEED=$(($(($(($HIGHEST_TEMP-$FAN_OFF_TEMP))*$FAN_PWM_INCREMENTS))+$FAN_LOW_PWM))
      ADJUSTED_PERCENT_SPEED=$(($(($ADJUSTED_FAN_SPEED*100))/$FAN_HIGH_PWM))
      ADJUSTED_OUTPUT=$ADJUSTED_FAN_SPEED
    fi
  fi

# Adjust fan to GPU output, if GPU is higher set GPU PWM to adjusted output
  if [[ $ADJUSTED_FAN_SPEED -le $GPUFAN ]]; then
      ADJUSTED_FAN_SPEED=$GPUFAN
      ADJUSTED_OUTPUT=$ADJUSTED_FAN_SPEED 
  fi

#echo "Adjusted output is "$ADJUSTED_FAN_SPEED
echo "Adjusted output is "$ADJUSTED_OUTPUT

# Implemenent fan speed change if neeeded
CURRENT_FAN_SPEED=`cat $ARRAY_FAN`
if [[ $CURRENT_FAN_SPEED -ne $ADJUSTED_FAN_SPEED ]]; then
  # Enable speed change on this fan if not already
  if [ "$ARRAY_FAN" != "1" ]; then
  echo 1 > "${ARRAY_FAN}_enable"
  fi
  # set fan to new value`
  echo $ADJUSTED_FAN_SPEED > $ARRAY_FAN
  echo "Setting pwm to: "$ADJUSTED_FAN_SPEED
fi

 

Output with the "test.txt" file - works as intended:

Script location: /tmp/user.scripts/tmpScripts/Case fan control/script
Note that closing this window will abort the execution of this script
GPU1 is 51
GPUFAN is 130
Highest temp is: 39
Adjusted output is 130
Setting pwm to: 130

 

Output with the dynamic "gpufan.txt" file - fails to read gpufan.txt...

Script location: /tmp/user.scripts/tmpScripts/Case fan control/script
Note that closing this window will abort the execution of this script
")
")

GPUFAN is
Highest temp is: 39
Adjusted output is OFF
Setting pwm to: 55

 

Edited by mishmash-
Link to post

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.