为什么 linux 远程命令或 bash 脚本没有 return 正确的输出?
why linux remote command or bash script does not return correct output?
我在执行远程命令时遇到问题。如果我通过登录到远程机器来执行命令,它就可以工作。但是,如果我从我的笔记本电脑向远程机器执行相同的命令,它 returns 不同的状态代码。
Local execution on 192.168.0.166:
root@monica-E470:~# virsh list --state-shutoff | grep Qcow2 | wc -l
1
Remote Command execution:
root@sandipd-ThinkPad-E450:~# ssh root@192.168.0.166 'virsh list --state-shutoff | grep Qcow2 | wc -l'
root@192.168.0.166's password:
0
我尝试过不同的场景,但没有成功。有人遇到同样的问题吗?
您必须添加一个伪终端才能在远程服务器中执行复杂的命令。试试这个:
ssh -t root@192.168.0.166 'virsh list --state-shutoff | grep Qcow2 | wc -l'
有关详细信息,请参阅 ssh
的 man
页。
我在执行远程命令时遇到问题。如果我通过登录到远程机器来执行命令,它就可以工作。但是,如果我从我的笔记本电脑向远程机器执行相同的命令,它 returns 不同的状态代码。
Local execution on 192.168.0.166:
root@monica-E470:~# virsh list --state-shutoff | grep Qcow2 | wc -l
1
Remote Command execution:
root@sandipd-ThinkPad-E450:~# ssh root@192.168.0.166 'virsh list --state-shutoff | grep Qcow2 | wc -l'
root@192.168.0.166's password:
0
我尝试过不同的场景,但没有成功。有人遇到同样的问题吗?
您必须添加一个伪终端才能在远程服务器中执行复杂的命令。试试这个:
ssh -t root@192.168.0.166 'virsh list --state-shutoff | grep Qcow2 | wc -l'
有关详细信息,请参阅 ssh
的 man
页。