[英]Getting different behavior when running bash script using SSH connection and startup-script
I am trying to run a script which is running on GCP startup-script, my startup script looks like below:我正在尝试运行在 GCP 启动脚本上运行的脚本,我的启动脚本如下所示:
#!/bin/bash
ulimit -n 100000
source ~/miniconda3/etc/profile.d/conda.sh
conda activate base
set -e
/root/miniconda3/bin/python3.8 /root/spider/src/rotate_ip.py & /root/miniconda3/bin/python3.8 /root/spider/src/main.py
gcloud compute instances stop scheduled-spider --zone asia-northeast1-b
This script behavior is not same as when I run the program connecting with SSH. It also doesn't show any log error.此脚本行为与我运行与 SSH 连接的程序时的行为不同。它也没有显示任何日志错误。 But when I run the program connecting SSH, it works perfectly.
但是当我运行连接 SSH 的程序时,它运行得很好。 The way I run the program in SSH connection:
我在SSH连接运行程序的方式:
/root/miniconda3/bin/python3.8 /root/spider/src/rotate_ip.py & /root/miniconda3/bin/python3.8 /root/spider/src/main.py
My assumption is when I run the program from startup script, it's probably not getting the same environment as in SSH connection.我的假设是当我从启动脚本运行程序时,它可能不会获得与 SSH 连接相同的环境。 Though I am using the following commands in the startup script to get the same environment but it's not working the same way.
虽然我在启动脚本中使用以下命令来获得相同的环境,但它的工作方式不同。
source ~/miniconda3/etc/profile.d/conda.sh
conda activate base
In ssh connection: which bash
command gives me /usr/bin/bash
.在 ssh 连接中:
which bash
命令给我/usr/bin/bash
。 I have also tried this shebang, but no result.我也尝试过这个 shebang,但没有结果。 Does anyone have any clue what else to try?
有谁知道还有什么可以尝试的吗?
I have also tried something like below:我也尝试过类似下面的东西:
source ~/miniconda3/etc/profile.d/conda.sh
conda activate base
set -e
conda activate base && /root/miniconda3/bin/python3.8 /root/spider/src/rotate_ip.py & /root/miniconda3/bin/python3.8 /root/spider/src/main.py
But no output difference.但没有 output 的区别。
Were I doing this, I would use conda run
and not muck around with manual activation.如果我这样做,我会使用
conda run
而不是手动激活。
#!/bin/bash
ulimit -n 100000
set -e
conda run -n base python /root/spider/src/rotate_ip.py &
conda run -n base python /root/spider/src/main.py
gcloud compute instances stop scheduled-spider --zone asia-northeast1-b
If it needs interaction, then you may need additional flags (see conda run --help
).如果它需要交互,那么您可能需要额外的标志(请参阅
conda run --help
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.