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: 11
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?
haaken675
Posts: 11
Joined: Thu Nov 19, 2020 9:05 pm

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

Post by haaken675 »

I thought i might revisit this one last time to see if anyone had any insight into why this script wouldn't run on dietpi, but has no issue on Rasberry Pi NOOBS, the new Raspberry Pi OS, and i would imagine several other distros.

I moved back tousing NOOBS for my dashboard simply because this script would run properly for my auto shut down switch in my car. That being said, i REALLY liked how quickly dietPi would boot...I would very much like to get this running before i put the dash back into the car this week.
User avatar
Joulinar
Posts: 3757
Joined: Sat Nov 16, 2019 12:49 am

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

Post by Joulinar »

Hi,

I don't think the install script is working on DietPi because at the end the script is expecting /etc/rc.local, which did not exist on DietPi at all
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
haaken675
Posts: 11
Joined: Thu Nov 19, 2020 9:05 pm

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

Post by haaken675 »

Ok, thats good to know. Now with that being said, i wish i knew what that did or what to replace it with. Is this something I can replace something else? If i understand correctly, rc.local is for auto starting things? Is there something else DietPi uses that i could replace that part with?
User avatar
Joulinar
Posts: 3757
Joined: Sat Nov 16, 2019 12:49 am

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

Post by Joulinar »

I'm not 100% sure but DietPi is using systemd to start services. Better to ask @MichaIng as developer :)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Parkour_Lama
Posts: 19
Joined: Sat Sep 12, 2020 2:02 pm

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

Post by Parkour_Lama »

haaken675 wrote: Mon Dec 14, 2020 3:27 am Ok, thats good to know. Now with that being said, i wish i knew what that did or what to replace it with. Is this something I can replace something else? If i understand correctly, rc.local is for auto starting things? Is there something else DietPi uses that i could replace that part with?
If you want you can just create your own /etc/rc.local file, its quite useful and it's what I did when I needed it for certain functions.

https://superuser.com/questions/1095117 ... -mint-17-3
haaken675
Posts: 11
Joined: Thu Nov 19, 2020 9:05 pm

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

Post by haaken675 »

Parkour_Lama wrote: Wed Dec 16, 2020 5:06 am
haaken675 wrote: Mon Dec 14, 2020 3:27 am Ok, thats good to know. Now with that being said, i wish i knew what that did or what to replace it with. Is this something I can replace something else? If i understand correctly, rc.local is for auto starting things? Is there something else DietPi uses that i could replace that part with?
If you want you can just create your own /etc/rc.local file, its quite useful and it's what I did when I needed it for certain functions.

https://superuser.com/questions/1095117 ... -mint-17-3
Thanks for that. I will look into it. If I can make this work, it might be worth redoing my dash for the 4th time this week. 50 second bootup to loading the tuning software dashboard on the car is a bit hard to swallow, even for a dedicated race car.
User avatar
MichaIng
Site Admin
Posts: 2621
Joined: Sat Nov 18, 2017 6:21 pm

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

Post by MichaIng »

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:~#
Aside of the rc.local topic, the syntax error looks like you tried to download the script but downloaded a raw HTML document instead. This happens regularly to me when I try to run this script via

Code: Select all

bash -c "$(curl -s https://github.com/MichaIng/DietPi/blob/master/PREP_SYSTEM_FOR_DIETPI.sh)"
accidentally instead of using the URL of the actual file content:

Code: Select all

bash -c "$(curl -s https://raw.githubusercontent.com/MichaIng/DietPi/master/PREP_SYSTEM_FOR_DIETPI.sh)"
The same would happen if the URL target does not exist, e.g. typo or removed file and the webserver returns a 404 HTML page.

From what I see, otherwise the script should work just fine after doing:

Code: Select all

echo 'exit 0' > /etc/rc.local
chmod +x /etc/rc.local
Post Reply