ssh命令输出以保存在shell脚本中的文本文件中 [英] ssh command output to save in a text file in shell script
本文介绍了ssh命令输出以保存在shell脚本中的文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写shell脚本,在其中使用ssh命令. 无论我通过ssh命令获得什么输出,我都希望将其保存在文本文件或varibale中,因此我可以在我的shell脚本中使用它. 目前,我将输出保存在变量中,但是当我在ssh命令之外使用该变量时,值显示为空白. 代码是
I want to write shell script, in which i am using ssh command. Whatever output i will get through ssh command i want save this in text file or varibale, so i can use this in my shell script. Currently i am saving output in a variable , but when i used that variable outside ssh command , value is showing blank. Code is
ssh hostname -c "'
`pwd`;
var=$(ps -ef | grep Consumer | cut -f6 -d' ')
'";
echo $?;
echo "vbar $var";
我打印时var值是空白的.
var value is blank when i print.
推荐答案
要将ssh的输出保存在本地文件"file.log"中:
To save ssh's output in local file "file.log":
ssh hostname > file.log << EOF
pwd
ps -ef | grep Consumer | cut -f6 -d' '
EOF
这篇关于ssh命令输出以保存在shell脚本中的文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文