简体   繁体   English

Bash 打开 Shell 的脚本,运行 Shell 中的命令,并保持 Shell 运行

[英]Bash Script to Open a Shell, Run a Command in the Shell, & Keep Shell Running

I'm trying to automate these steps using a bash script我正在尝试使用 bash 脚本自动执行这些步骤

  1. Run a command to access the shell of a program (bash shell of a Kube.netes pod)运行命令访问程序的shell(Kube.netes pod的bash shell)

     kubectl exec --stdin --tty hello-node-7567d9fdc9-zvz55 -- bash
  2. In this shell, run a second command (eg. python )在这个 shell 中,运行第二个命令(例如python

     root@hello-node-7567d9fdc9-zvz55:/# python Python 3.7.4 (default, Aug 13 2019, 15:17:50) [Clang 4.0.1 (tags/RELEASE_401/final)]:: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>>
  3. Keep the shell open/running in the foreground (so more commands can immediately be entered by a user into the python shell started in step 2)保持 shell在前台打开/运行(以便用户可以立即将更多命令输入 python shell 在步骤 2 中启动)

I'm able to do the first step described above using the script below.我可以使用下面的脚本执行上述第一步。 How do we do the second and third step?我们如何进行第二步和第三步?

#! /bin/bash
bash -c 'kubectl exec --stdin --tty hello-node-7567d9fdc9-zvz55 -- bash'

For step 2 you can use the nohup command to run a process and even if the user logs off the process does not get killed.对于第 2 步,您可以使用nohup命令运行一个进程,即使用户注销该进程也不会被终止。 Afterwards the shell is kept running for you to perform step 3之后 shell 继续运行,供您执行步骤 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM