如何制作一个循环的Bash脚本:从命令列表文件中读取一个命令,将其粘贴到终端,执行该命令,继续进行

0 人关注

给出一个Bash命令的列表,写进一个文件,每行一个。 我想做一个Bash脚本,在一个循环中做以下事情。

  • reads a command from a list-of-commands file,
  • paste it into terminal,
  • execute that command (= presses enter),
  • goes on with the next command until it reaches the end of the list
  • 有可能用bash来做吗?

    否则,我想我必须用另一种语言开发一个脚本,将命令粘贴到终端的活动位置上(或 终结者 ), presses enter.

    我怎样才能做到这一点呢?

    Note:

    写入文件的一些命令是 ssh 命令( ssh user@machine_ip logout )。
    因此,列表中的命令要在不同的机器上执行。

    所以我不能通过简单地把这些命令放在bash脚本中并运行它来达到目的,因为随着 ssh 命令的解析,脚本会登录到另一台机器上,随后的命令会被 "设置为暂停",直到用户断开与远程机器的连接。

    此外,在我的情况下,我必须通过3或4台机器的ssh隧道来登录某些机器,所以我不想使用 ssh 命令,其语法如下

    ssh -o ConnectTimeout=$ssh_timeout $user_B@$remote_machine_B_ip                         \
                  "sudo -i -u user_O ssh -o ConnectTimeout=$ssh_timeout $user_O@$remote_machine_P_ip  \
                      \"ssh -o ConnectTimeout=$ssh_timeout $user_O@$remote_machine_C_ip               \