簡體   English   中英

遠程運行命令會返回意外的輸出

[英]Running commands remotely returns unexpected output

我想遠程殺死一個進程,並且使用ssh -i命令,如下所示:

ssh -i $app_rsa_file_path $app_server_user@$app_server_ip "ps aux | grep java | grep billing | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1"

如果我直接在服務器上運行命令,它將正常工作; 但是在遠程版本中, awk似乎沒有任何作用,該命令將傳遞ps aux | grep java | grep billing的整個輸出。 ps aux | grep java | grep billing ps aux | grep java | grep billing kill ,我得到這個:

kill: invalid option -- 'D'

Usage:
 kill [options] <pid> [...]

Options:
 <pid> [...]            send signal to every <pid> listed
 -<signal>, -s, --signal <signal>
                        specify the <signal> to be sent
 -l, --list=[<signal>]  list all signal names, or convert one to a name
 -L, --table            list all signal names in a nice table

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see kill(1).

知道原因嗎?

您使用雙引號“,因此您需要轉義$特殊字符:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM