Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ssh command output to save in a text file in shell script

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 value is blank when i print.

like image 917
Mars Avatar asked Jun 26 '26 19:06

Mars


1 Answers

To save ssh's output in local file "file.log":

ssh hostname > file.log << EOF
pwd
ps -ef | grep Consumer | cut -f6 -d' '
EOF
like image 132
Cyrus Avatar answered Jun 28 '26 09:06

Cyrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!