【问题标题】:Get django source code directory path running on a VM using scripts使用脚本获取在VM上运行的django源代码目录路径
【发布时间】:2023-04-08 14:57:01
【问题描述】:

我需要获取在 VM 上运行的 Django 应用的源代码目录

我只有虚拟机的详细信息,而且我知道有一个 Django 应用程序正在运行。

我可以通过使用 SSH 运行以下命令来获取端口

sudo netstat -plant | grep "LISTEN.*python3" | awk '{print $4}' | cut -d ":" -f2

之后,我需要知道源代码的目录

【问题讨论】:

    标签: django python-3.x


    【解决方案1】:

    无法通过“netstat”或“ps”命令获取 Django 应用程序的路径,您会发现路径是通过手动查找。 开始查看“/var/www/ 文件夹”。
    如果你想知道不用太多搜索,检查服务器配置,查看'/etc/nginx/sites-available'文件夹中的Nginx或apache2文件你会在那里找到路径。

    【讨论】:

    • 我不需要从代码中得到这个。我已经更新了问题。
    • 解决了吗?如果是这样,请将其标记为答案。 @Ashwani
    【解决方案2】:

    如果你的虚拟机上只运行一个 Django 应用程序,我有一个解决方案:

    #We can also use ps command to get PID, I am using this to get PID and Port
    PROCESS_ID=`sudo netstat -plant | grep "LISTEN.*python3" | awk '{print $7}' | cut -d "/" -f1`
    
    APP_DIR=`sudo lsof | grep python3.*${PROCESS_ID}.*DIR | awk 'NR==1{print $9}'
    
    PORT=`sudo netstat -plant | grep "LISTEN.*python3" | awk '{print $4}' | cut -d ":" -f2`
    

    APP_DIR 将拥有 Django 应用运行的绝对路径。

    【讨论】:

      猜你喜欢
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      相关资源
      最近更新 更多