admin管理员组文章数量:1277317
I am having trouble execting the below command on remote SSH. Trying to execute 3 commands on remote server and returning its output as CSV value. If the run the command on the command line it works well. But when i save it and run it as shell script, the variable values are not getting printed. However it prints the =s...
s=$(ssh -q user@host "a=$(free -g | grep Mem | awk '{print $2}' | sed 's/ //g') && b=$(lscpu | grep "^CPU(s)" | awk '{print $2}' | sed 's/ //g') && c=$(hostname) && echo ===$a===$b===$c===")
echo $s
Please do suggest if there is a better way to achieve this.
Another peculear thing I noted is in c, where i am trying to print hostname, it prints the kernel version instead of host name.
I am having trouble execting the below command on remote SSH. Trying to execute 3 commands on remote server and returning its output as CSV value. If the run the command on the command line it works well. But when i save it and run it as shell script, the variable values are not getting printed. However it prints the =s...
s=$(ssh -q user@host "a=$(free -g | grep Mem | awk '{print $2}' | sed 's/ //g') && b=$(lscpu | grep "^CPU(s)" | awk '{print $2}' | sed 's/ //g') && c=$(hostname) && echo ===$a===$b===$c===")
echo $s
Please do suggest if there is a better way to achieve this.
Another peculear thing I noted is in c, where i am trying to print hostname, it prints the kernel version instead of host name.
Share Improve this question asked Feb 25 at 12:01 Sudharsan SimhanSudharsan Simhan 271 silver badge9 bronze badges 1 |1 Answer
Reset to default 2#!/bin/bash
s=$(ssh ttdev 'a=$(free -g | grep Mem | awk "{print \$2}" | sed "s/ //g") && b=$(lscpu | grep "^CPU(s)" | awk "{print \$2}" | sed "s/ //g") && c=$(hostname) && echo ===$a===$b===$c===')
echo $s
ttdev is a name of ssh configuration to my server done under ~/.ssh/config.
The script should work with user@host as per your case as well.
本文标签: shellRemote SSHNot printing the variablesStack Overflow
版权声明:本文标题:shell - Remote SSH - Not printing the variables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741204246a2357836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
echo
in front to see how exactly the shell substituted your placeholders. Also, more generally, it helps if you reduce the scope of your problem. The above code connectsssh
,free
,grep
,awk
,sed
,lscpu
, andhostname
, which exactly produces unexpected results? – Ulrich Eckhardt Commented Feb 25 at 12:51