一般来说,我对linux并不熟悉,所以我可能不知道某些事情。因此,我尝试了大量的解决方案,但我没有成功地运行discord.js机器人。我在其他脚本中使用了rc.local,比如在启动date > <file-path>上在文件上写入日期,它工作正常,但是在启动时运行bot会失败,也不能完全读取任何错误。
rc.local文件:
#!/bin/sh -e
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/bin/sh /home/pi/superscript.sh
exit 0superscript.sh文件:
#!/bin/sh
date > /home/pi/boot.log
( cd /home/pi/Desktop/discord-bot; /usr/bin/node /home/pi/Desktop/discord-bot/index.js ) &当我手动执行node ~/Desktop/discord-bot/index.js &时,bot完全可以工作,甚至如果我手动执行superscript.sh,它也能工作,所以我无法真正找到问题所在。有谁能帮我一下吗?我真的很感激。
谢谢。
发布于 2021-04-02 06:22:49
最简单的方法是在启动时使用crontab执行命令。
# Edit cron
crontab -e
# type following to start a script-file.sh on startup
@reboot script-file.sh参考资料:https://www.simplified.guide/linux/automatically-run-program-on-startup
https://stackoverflow.com/questions/66899086
复制相似问题