Cannot get script to run-Ran fine in Noobs, not in DIetPi?

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
haaken675
Posts: 8
Joined: Thu Nov 19, 2020 9:05 pm

Cannot get script to run-Ran fine in Noobs, not in DIetPi?

Post by haaken675 »

Hey everyone, thanks a bunch for all of the help thus far. Hopefully someday I will understand these systems much better then i currently do...

I am trying to run a script to initiate the shutdown sequence when the ff switch is triggered. I had no issue getting this to work on Noobs, but will not work on DietPi. I am using a Mausberry Circuits car switch, and going through their listed method to install the script. So far, it will not run.

This is the script in the .SH file that came directly from Mausberry Circuits (https://www.mausberrycircuits.com/pages/setup):
echo '#!/bin/bash

#this is the GPIO pin connected to the lead on switch labeled OUT
GPIOpin1=23

#this is the GPIO pin connected to the lead on switch labeled IN
GPIOpin2=24

echo "$GPIOpin1" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
echo "$GPIOpin2" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction
echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
while [ 1 = 1 ]; do
power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
if [ $power = 0 ]; then
sleep 1
else
sudo poweroff
fi
done' > /etc/switch.sh
sudo chmod 777 /etc/switch.sh
sudo sed -i '$ i /etc/switch.sh &' /etc/rc.local

I have tried several methods to run the script, but I am getting a number of error such as

root@DietPi:~# sudo bash setup.sh
setup.sh: line 1: !DOCTYPE: No such file or directory
setup.sh: line 2: syntax error near unexpected token `newline'
setup.sh: line 2: ` "http://www.w3.org/TR/html4/strict.dtd">'
root@DietPi:~#


I am outclassed here. This is way beyond my knowledge to modify, change, or even understand what is wrong...Is there something so vastly different about DietPI that would make this work in Noobs but not this?
Post Reply