Attempting to run a command at boot / before user login not working

poindexter

New Member
Joined
Sep 18, 2023
Messages
2
Reaction score
0
Credits
29
Hey Forum, I have a Debian build here and I am trying to get a 4g modem to work on it. I have managed to get it working but I cannot get the configuration to persist after a reboot.

There is one simple AT command that I need to send to the modem to make it connect. When I run it manually it works but I need to connect to this device remotely and without the ability to login locally to run the command.

The command that needs to execute is below. I put this into a .sh file and made it executable.

echo -e "AT#ECM=1,0\r" | sudo minicom -D /dev/ttyUSB2 -b 115200
date=$(date)
echo $date >> /home/username/modemlog.txt


I tried running it from a cronjob both on a 2 minute schedule and also @reboot but neither worked. I know it ran the script because I saw the date log in modemlog.txt. It just didn't initialise the modem.

So my next attempt was to run it as an init script in /etc/init.d followed by update-rc.d. Of course I made the script executable. The script ran but again, it didn't do the business with the modem. When checking the service status it didn't look like it was running the full command. All I could see was sudo minicom -D /dev/ttyUSB2 -b 115200 which doesn't do the job.

There is something fundamental that I am missing here. I have tried using the full path to the minicom command and the full path to the ping command but this still didn't work.

Any suggestions on how I can get this command to execute at bootup and before user login would be greatly appreciated!!

Many thanks
 


how I can get this command to execute at bootup and before user login
Since your script needs sudo, I might have suggested making a new cron job as root, not as a regular user. This may (or may not) have worked. But "before user login" is a different challenge and not something I'm really familiar with. This article is 5 years old, but it may help to get you started. You may need to install different display managers in your Debian to see if any of these solutions can help you. And as the article cautions, be careful... you could pretty easily make your system unbootable. Good luck!
 
Thanks for providing this detail. I am not expecting to use any display manager at all. I need to keep this device CLI only so it is lightweight. Really need to exercise this command without the use of any display manager at all.
 
I would put it in a systemd service file and run it that way.
 


Top