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??


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

root@beaglebone:~# systemctl enable cronie.service
Failed to execute operation: No such file or directory

Permission and owner of main

root@beaglebone:~/wiringBone-master/library# ll main 
-rwxr-xr-x 1 root root 66744 May 27 16:15 main

Crontab is the solution. Invoke by:

crontab -e

Which will open the default editor. Add:

@reboot your command

Save and exit. If the command requires superuser password, you should first sudo su -, and crontab -e as root.

In order to get to the very source of the problem (whether it is cron or the script), a simpler case may be created for debugging purposes:

  • First a line such as @reboot date >> /root/a or similar is added as a cron job after crontab -e
  • If it works ( ~ appends date/time to file "/root/a"), that line is saved into a bash script with the same ownership and permissions (-rwxr-xr-x 1 root root) and such as:

    date >> /root/a
| improve this answer | |
  • Will it execute my script without login into BBB ?? – Rahul Dec 16 '16 at 1:09
  • Surely. I use it to connect my Rpi to openvpn at reboot, without my login – Serhat Cevikel Dec 16 '16 at 1:23
  • I have to ssh for crontab -e to execute my script at startup. not working – Rahul Dec 16 '16 at 1:50
  • Did you crontab as a non-root user or root? If the script requires sudo privileges, it has to be crontabbed as root. And for the first time to enter the cron job, you have to ssh once. What is your exact situation? Can't you ever ssh? – Serhat Cevikel Dec 16 '16 at 8:29
  • I can ssh . I'm running Debin 7.8 in BBB and login as root when I edited crontab -e so I have all the privileges I guess. – Rahul Dec 16 '16 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.