Run Linux PTP on crontab at boot

122 Views Asked by At

I want to run 2 commands when a Beaglebone AI with Debian 10 starts up. The first one, which is a C code to initialize a Circular Microphone Board, it works (CMBini).

However, the second one it does not. It is a script it is a PTP network command (ptp4l -A -H -q -s), and I think that the problem might be that it is a command that stays running and printing results until cancelled with Ctrl+C.

So my question is how can I make this work? Is there anyway to keep that process running in the background?

My crontab file:

@reboot /home/debian/CMBini
@reboot /home/debian/startsript.sh

startscript.sh:

#! bin/bash
sleep 20
ptp4l -A -H -q -s  -i eth0
sleep 40
phc2sys -a -rr
1

There are 1 best solutions below

0
James Risner On

I tried your crontab on macOS 12.6:

@reboot /Users/risner/bin/startsript.sh

#!/bin/sh

/usr/bin/screen -d -m -S ptp -c /Users/risner/.boot-screenrc

With this in .boot-screenrc:

screen -t ptp4l 1
stuff sleep 20; ptp4l -A -H -q -s  -i eth0\015
screen -t phc2sys 2
stuff sleep 40; phc2sys -a -rr\015

The commands failed (ptp4l & phc2sys), but screen ran them. So if they commands work on your system this is a solution.

This also allows you to attach to the session via:

screen -D -R ptp

From there you can view the commands it executed.