linux - 在 ssh 进入 DC 的时钟服务器后,如何在我的脚本中触发脚本?

标签 linux bash shell server scripting

所以,我有一个脚本,它的预期目的是:

  1. 询问DC号码和时钟号码

  2. 登录上述DC的时钟服务器

  3. 登录后,我打算在我的脚本中运行一个单独的脚本来更新上面提到的时钟编号。

我的问题是,一旦我触发脚本,它就会按预期登录服务器,提示我输入用户 ID,然后当“xterm”出现时我必须按“enter”。在此之后,更新脚本应该运行,但是它没有运行,而是位于命令行。

在我退出服务器后,THEN 它运行更新脚本,但失败了,因为跳转框中不存在更新脚本。

我的问题是,在脚本登录到服务器后,我怎样才能让它触发时钟服务器内的脚本,正如我所希望的那样?谢谢。

脚本如下:

#!/bin/bash -x
export LANG="C"

####
####
## This script is intended to speed up the process to setup timeclocks from DC tickets
## Created by Blake Smreker | b0s00dg | bsmreker@walmart.com
####
####

#Asks for DC number

echo "What is the four digit DC number?"

read DC         #User input

#Asks for Timeclock number

echo "What is the two digit Timeclock number?"

read TMC        #User input

#Defines naming convention of tna server

tnaserver="cs-tna.s0${DC}.us.wal-mart.com"

#creating variable to define the update script

tcupd="/u/applic/tna/shell/tc_software_update.sh tmc${TMC}.s0${DC}.us REFURBISHED"

#Logging in to the cs-tna package at the specified DC

/usr/bin/dzdo -u osedc /bin/ssh -qo PreferredAuthentications=publickey root@$tnaserver

echo "Preforming Timeclock update on Timeclock=$TMC, at DC=${DC}"

echo ""

echo "-----------------------------------------------------------------------------------------------------------------------------------------"

$tcupd #Runs update script

echo "-----------------------------------------------------------------------------------------------------------------------------------------"

echo ""

sleep 2

echo "If prompted to engage NOC due to Timeclock not being on the network, send the ticket to DC Networking"

echo ""

echo "OR"

echo ""

echo "If the script completed successfully, and the Timeclock was updated, you can now resolve the ticket"

最佳答案

您必须在 ssh session 中运行命令,而不是在它之后:

echo "Preforming Timeclock update on Timeclock=$TMC, at DC=${DC}"

echo ""

echo "-----------------------------------------------------------------------------------------------------------------------------------------"

###### $tcupd #Runs update script
/usr/bin/dzdo -u osedc /bin/ssh -qo PreferredAuthentications=publickey root@$tnaserver /bin/bash -c /u/applic/tna/shell/tc_software_update.sh tmc${TMC}.s0${DC}.us REFURBISHED

echo "-----------------------------------------------------------------------------------------------------------------------------------------"

echo ""

sleep 2

echo "If prompted to engage NOC due to Timeclock not being on the network, send the ticket to DC Networking"

echo ""

echo "OR"

echo ""

echo "If the script completed successfully, and the Timeclock was updated, you can now resolve the ticket"

man ssh 中,您会看到 ssh [-46AaCfGgKkMNnqsTtVvXxYy] ...... destination [command]。如果未指定 [command],ssh 将运行远程登录命令脚本,例如 xterm。您阅读更多 herehere 或只是浏览 google。
您需要考虑要如何以及将哪个环境变量传递给远程计算机,并记住正确封装变量,以便它们在您或远程计算机上得到扩展。

关于linux - 在 ssh 进入 DC 的时钟服务器后,如何在我的脚本中触发脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51121476/

相关文章:

android - 如何为 Android 操作系统移植一些 linux 命令?

linux - 使用 printf 创建标题

sql - 如何在 bash 中将二进制数据插入到 sqlite3 数据库中?

linux - 腻子 : Execute a shell script onto the host machine

linux - 安装 DBD::Oracle 时出错

c++ - LD_LIBRARY_PATH 不包含导出路径

linux - bashdb启动错误: bashdb/lib/setshow. sh:第91行:/dev/pts/2:权限被拒绝

linux - 检查程序是否正在特定节点上运行

linux - 系统启动时如何导出变量

linux - 差不多了!如何向 bash 提示符添加另一种 git status 颜色?