Hi
I am using a Beaglebone Black with new debian
I used it with reference to the following link
https://www.digikey.com/eewiki/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-RootFileSystem
I want a program to run automatically after the Beaglebone black power is turned on
I changed the file ( /lib/systemd/system/serial-getty@.service) for auto log in as following
...
[Service]
ExecStart=-/sbin/agetty -a debian -s %I 115200
...
Automatic login works good.
but I have a shell script and a program.
modem.sh
#!/bin/bash
echo "GPIO pin setting ------------------------"
config-pin P9.24 uart
config-pin P9.26 uart
config-pin P9.11 uart
config-pin P9.13 uart
sleep 5
echo "set modem call -------------------------"
sudo echo -ne 'at$qcrmcall=1,1\r' > /dev/ttyUSB2
sleep 2
echo "set wwan setting -----------------------"
sudo dhclient -v wwan0
./LoraControl
.bashrc
...
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
sudo ./modem.sh
After the Beaglebone is automatically logged in, when the modem.sh is executed, it stops with a message asking for the superuser’s password.
I want to run the shell script (modem.sh) without message asking password
so I want to run the program ( LoraControl ) automatically without any input after the board is powerd on
Please let me know how to do it.
and one more questing
Is there another way to make modem.sh run automatically without putting it in .bashrc?
Thank you
@taek8461 couple things, first let’s solve the “sudo” issue. If you want to call something with sudo without a password prompt, you can add the specific applications in “/etc/sudoers”… Now, you need to be very careful editing this file, as you can very easily lock yourself out of the file system…
/etc/sudoers
debian ALL=NOPASSWD: /sbin/dhclient, /bin/echo
Next, i’d nuke your whole “sudo ./modem.sh”, with a systemd service file. Drew has an awesome “config-pin” example systemd service that you could use…
Plus, as it’s already run as root, you won’t need any sudo calls if you use Drew’s example. (it’ll also wait till the system can call config-pin)…
Regards,
1 Like
hi RobertCNelson
I edited the file “/etc/sudoers” as follow
but when I powered on the board, the message is displayed as follows.
it have permission denied and ask password.
I don’t know why.
I changed “sudo ./modem.sh” in .bashrc to “./modem.sh”
How can i resolve it.
thank you
@taek8461, remove “, /dev/ttyUSB2” from /etc/sudoers, that is a “device” not an “application”…
In your script, you have a race condition with /dev/ttyUSB2, it’s best to make sure that device exists before you write to it… (this is easier with a systemd service file) But to hack up your current script more, change:
echo "set modem call -------------------------"
sudo echo -ne 'at$qcrmcall=1,1\r' > /dev/ttyUSB2
sleep 2
to:
echo "set modem call -------------------------"
until [ -d /sys/class/tty/ttyUSB2/ ] ; do
sleep 1
echo "Debug: waiting for ttyUSB2"
done
echo "Debug: ttyUSB2 is active"
sudo echo -ne 'at$qcrmcall=1,1\r' > /dev/ttyUSB2
sleep 2
Also in “.bashrc”, use the actual path for “./modem.sh” your just asking for trouble… If it’s under /home/debian/ just add it… “./modem.sh” -> “/home/debian/modem.sh” or where ever you actually placed “./modem.sh”…
Edit, looking at your log, the other sudo password came during:
echo "set wwan setting -----------------------"
sudo dhclient -v wwan0
So, dhclient is using a different path… run: “sudo which dhclient” then update /etc/sudoers with where it’s located on your root file system.
voodoo@hades:~$ sudo which dhclient
/sbin/dhclient
Regards,
Hi RoberCNelson
Thank you for your response
I am getting a lot of help from you.
I tried running it according to your solution
but I still have problems.
- /dev/ttyUSB2 has been a permission denied.
- dhclient request password.
the path is /sbin/dhclient
I don’t know what’s wrong.
Below is /etc/sudoers
Below is modem.sh
Please, let me know the solution.
Thank you.
@taek8461, that’s odd, okay, let’s just change it to allowing everything:
debian ALL=NOPASSWD: ALL
Regards,
Hi
Thank you for your response
When I tried to run an app (including sudo) on prompt, it didnot ask the password.
but when powered on and run automatically, it asked the password
How can I resolve it?
Regards.
@taek8461, okay not sure what’s causing that. So enough with the random hacks, and let’s do things the right way for a systemd based system in 2020.
First what’s the actual location of “./LoraControl”, you should change that in below:
First we will create the enable-modem file: sudo nano /usr/bin/enable-modem.sh
It’s contents:
#!/bin/bash
echo "GPIO pin setting ------------------------"
config-pin P9.24 uart
config-pin P9.26 uart
config-pin P9.11 uart
config-pin P9.13 uart
sleep 5
echo "set modem call -------------------------"
until [ -d /sys/class/tty/ttyUSB2/ ] ; do
sleep 1
echo "Debug: waiting for ttyUSB2"
done
echo "Debug: ttyUSB2 is active ---------------"
echo -ne 'at$qcrmcall=1,1\r' > /dev/ttyUSB2
sleep 2
echo "set wwan setting -----------------------"
/sbin/dhclient -v wwan0
echo "Running LoraControl --------------------"
#TODO: replace "./" with actual location...
./LoraControl
Set enable-modem.sh permissions:
sudo chmod 755 /usr/bin/enable-modem.sh
Next Create the service file: sudo nano /lib/systemd/system/enable-modem.service
It’s contents:
[Unit]
Description=Enable Modem
After=multi-user.target
[Service]
Type=forking
ExecStart=/usr/bin/enable-modem.sh
[Install]
WantedBy=multi-user.target
Now reload systemd and enable the new service file:
sudo systemctl daemon-reload
sudo systemctl enable enable-modem.service
On bootup you should be able to grep it’s startup with journalctl | grep Modem
Regards,
1 Like
Hi.
I resolved it.
Thank you so much.