gpt4 book ai didi

Linux - 使用 SSH 的关闭脚本

转载 作者:太空宇宙 更新时间:2023-11-04 05:00:17 25 4
gpt4 key购买 nike

我想为我的树莓派制作一个关闭脚本,以通过 ssh 关闭另一个树莓派。

如果脚本本身正在运行,则该脚本可以工作,但在关闭例程时,不会执行 ssh 命令。

到目前为止我已经完成了:

  1. 在/etc/init.d 中创建脚本:
 #!/bin/sh
# the first thing is to test if the shutdown script is working
echo "bla bla bla " | sudo tee -a /test.txt
ssh pi@10.0.0.98 sudo shutdown -h now
  • 使其可执行
  • sudo chmod +x /etc/init.d/raspi.sh
  • 创建了到 rc0.d 的符号链接(symbolic link)
  • sudo ln -s /etc/init.d/raspi.sh /etc/rc0.d/S01raspi.sh

    现在我知道,到目前为止,关闭脚本通过调用自身在关闭路由之外工作,并且我创建的关闭符号链接(symbolic link)也部分工作,因为每次关闭时我都会看到 test.txt 文件中的更改。

    谁能帮我解决我的问题吗?

    最佳答案

    您尝试过使用单引号吗?Google 中的第一个链接就有它

    http://malcontentcomics.com/systemsboy/2006/07/send-remote-commands-via-ssh.html

    sudo呢,如何解决输入密码的问题?

    https://superuser.com/questions/117870/ssh-execute-sudo-command

    请检查此链接或网络上包含有用信息的其他链接。

    我本来可以在评论中发送所有这些内容,但由于声誉,我还不能发送。

    关于Linux - 使用 SSH 的关闭脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35259688/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com