0

I want to run some code in Beaglebone black without doing ssh when I apply power.

I have tried putting some commands to run the code in ~/.bashrc file but it only works when I login using ssh. I have tried same thing with /etc/rc.local file but didn't work even after ssh.

I have also tried @reboot my_command in crontab -e but it also requires me to login using ssh Any suggestions??

EDIT:

root@beaglebone:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.6 (jessie)
Release:    8.6
Codename:   jessie

root@beaglebone:~# ps aux | grep cron | grep -v grep
root       295  0.0  0.3   4428  1988 ?        Ss   15:03   0:00 /usr/sbin/cron -f

Output of crontab -e: last few lines

root@beaglebone:~# crontab -e
    # For more information see the manual pages of crontab(5) and cron(8)
    #
    # m h  dom mon dow   command


#@reboot /root/wiringBone-master/library/main           not working

#*/5 * * * * /root/wiringBone-master/library/main       works

main is the script I want to run

Rahul
  • 262
  • 1
  • 5
  • 22

3 Answers3

0

I don't know anything about beagle bone, but on a normal Linux system you'd likely do this with either an init script, or, more easily, in a cron script set to run at boot.

You'll have to check if you're environment would support either of those. Even if it doesn't have cron, it is probably running some sort of init (likely to be the thing starting SSH on boot, but YMMV).

halfer
  • 19,824
  • 17
  • 99
  • 186
erik258
  • 14,701
  • 2
  • 25
  • 31
  • It supports `cron` as well as `init`. Can you explain how to use them in my case. Say `execute_some` command at `some_location` at startup. – Rahul Dec 16 '16 at 00:11
  • Do you know which flavor of cron it uses? – erik258 Dec 16 '16 at 00:30
  • http://unix.stackexchange.com/questions/188042/running-a-script-during-booting-startup-init-d-vs-cron-reboot might shed some light on syntax. – erik258 Dec 16 '16 at 00:31
  • Tried `crontab -e` and `init.d` but I still need to login using ssh to execute my code at startup. – Rahul Dec 16 '16 at 02:11
  • You should update your question with the specifics of what you've tried. – erik258 Dec 16 '16 at 05:25
  • Added some extra info – Rahul Dec 16 '16 at 17:15
  • http://stackoverflow.com/questions/17375663/cron-job-to-send-ip-of-beaglebone-black-at-every-reboot-to-my-email-is-not-fir Looks like it should work? Or maybe cron version changed. Otherwise, init script like http://stackoverflow.com/questions/28854705/executing-a-script-on-statup-using-beaglebone-black might work for you, but probably more effort than cron – erik258 Dec 16 '16 at 18:36
  • Your crontab lines are *commented out*! You need to remove the `#` in front of the respective lines! – TBR Dec 18 '16 at 07:29
0

/etc/rc.local is a quick way. Make sure to launch into background and don't prevent the script from finishing.

Writing a proper systemd service file would be better though.

TBR
  • 2,790
  • 1
  • 12
  • 22
  • Added some extra info – Rahul Dec 16 '16 at 17:16
  • `Didn't work` is insufficient. You need to at least make an effort to understand *why* things don't work and post *exactly* what you did. E.g. the rc.local script contains a last line of `exit 0` by default, and you *MUST obviously* put your commands *before that*. – TBR Dec 18 '16 at 07:28
  • yes I took care of `exit 0` line. crontab method worked!!. I write an answer. – Rahul Dec 18 '16 at 13:11
0

crontab -e method worked!!. My script required two overlays to execute the code which I didn't load that's why my @reboot command didn't work. I solved my problem by adding required overlays.

@reboot config-pin overlay cape-universaln
@reboot config-pin overlay BB-ADC
@reboot /root/wiringBone-master/library/main

And now my code works on reboot.

Rahul
  • 262
  • 1
  • 5
  • 22