I am not sure what is wrong with my shell script but I am guessing that it has something to do with environment variables. My script runs gridcoinresearchd on my raspberry pi. I want it to turn off the pi lights and then turn them back on if my gridcoin balance increases. I am not sure if I am setting the variable correctly. I am not sure if the script and the shell and the parent shell are all set up to do what I am trying to do. Any help would be appreciated. Here is my script so far:
#This script turns off sleep mode, activates gridcoinresearchd and turns off the rasperry pi red and green lights. It then records the gridcoin balance and saves the balance as "PREVIOUSBALANCE". The script then checks every 15 minutes to see if the real Gridcoin balance "CURRENTBALANCE" has increased. If the balance has increased, the script turns the lights back on. This script must be run as sudo.
#Disable sleep mode
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
#Activate gridcoinresearchd
gridcoinresearchd &
sleep 360
# Disable the red and green motherboard LEDs.
sh -c 'echo 0 > /sys/class/leds/led0/brightness'
sh -c 'echo 0 > /sys/class/leds/led1/brightness'
# Get and set "PREVIOUSBALANCE"
export PREVIOUSBALANCE=`gridcoinresearchd getinfo | grep "balance" /dev/stdin | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' '`
# Get "CURRENTBALANCE"
export CURRENTBALANCE=`gridcoinresearchd getinfo | grep "balance" /dev/stdin | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' '`
# If CURRENTBALANCE is greater than PREVIOUSBALANCE then turn on the lights.
if [ "CURRENTBALANCE" > "PREVIOUSBALANCE" ]; then
sh -c 'echo 14 > /sys/class/leds/led0/brightness'
sh -c 'echo 14 > /sys/class/leds/led1/brightness'
fi