dsrbb20862 2015-02-13 20:06
浏览 62

Webserver触发ssh shell脚本

I have googled this a lot but none of the results I have found worked for me. So far, I have only tried to do this with php, but cgi, javascript or whatever works is fine with me, as long as it gets the job done.

I would like to access a certain URL on my debian webserver. Once opened in the browser, this file shall execute the following shell commands. No buttons or links. If possible, I'd like to just open the URL, then have the script being started.

    ssh user@192.168.189.12 <<'ENDSSH'
    osascript ~/Desktop/Scripts/script.scpt

When running this as a regular .sh file it works fine. I have created lockkeys so that no password is prompted when connecting from A to B. What can I do to trigger this from, for example, the browser on my smartphone?

I am not trying to connect directly from any device to the Mac containing script.scpt. It is essential that the debian server triggers it and that it is executed by the webserver.

I just started learning about terminal comments, scripts and so on, so I have very basic knowledge of the subject. Please be patient with me.

Thanks in advance for your help :)

  • 写回答

1条回答 默认 最新

  • douteng5673 2015-02-13 20:17
    关注

    for simplicity I prefer to create a bash script. Let's call it

    /var/NONwebroot/sshcoolstuff.sh

    #!/bin/bash
      ssh user@192.168.189.12 <<'ENDSSH'
      osascript ~/Desktop/Scripts/script.scpt
    

    make sure it is executable

    <?php
    
    exec('/var/NONWwebroot/sshcoolstuff.sh');
    
    ?>
    

    Now I'd recommend putting some protection on that PHP script. Either limit who has access to it by IP address, or a password, or both.

    here is a test bash script for you

    #!/bin/sh
    cat > test << EOF
    Hello World!
    This is my test text file.
    
    You
    can also
    have
    a whole lot
    more text and
    lines
    EOF
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭