在 beaglebone black 中執行沒有 ssh 的程式碼

在 beaglebone black 中執行沒有 ssh 的程式碼

我想在通電時運行一些程式碼Beaglebone black而不做任何事情。ssh

我嘗試放置一些命令來運行~/.bashrc文件中的程式碼,但它僅在我使用ssh.我對文件嘗試過同樣的操作/etc/rc.local,但即使在 ssh 之後也不起作用。

我也嘗試過@reboot my_commandcrontab -e但它還要求我使用 ssh 登入。

有什麼建議麼?

編輯:

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

輸出crontab -e:最後幾行

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是我要運行的腳本

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

許可證和所有者main

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

答案1

crontab 就是解決方案。調用方式:

crontab -e

這將打開預設編輯器。添加:

@reboot your command

儲存並退出。如果該命令需要超級使用者密碼,您應該先sudo su -crontab -eroot 身分登入。

為了找到問題的根源(無論是 cron 還是腳本),可以創建一個更簡單的情況用於偵錯目的:

  • @reboot date >> /root/a首先,在之後添加諸如或類似的行作為 cron 作業crontab -e
  • 如果它有效(〜將日期/時間附加到檔案「/root/a」),則該行將保存到具有相同所有權和權限(-rwxr-xr-x 1 root root)的bash腳本中,例如:

    #!/usr/bin/sh
    date >> /root/a
    

相關內容