0
我幾乎不知道shell腳本或終端命令的任何內容。如何通過shell腳本連接並運行遠程服務器上的shell腳本
想要實現:
做一個shell腳本,連接到遠程服務器,並連接到該服務器後,該服務器上運行某些命令。
可能嗎?
我試過Google搜索,但沒有找到東西,我期待。
我幾乎不知道shell腳本或終端命令的任何內容。如何通過shell腳本連接並運行遠程服務器上的shell腳本
想要實現:
做一個shell腳本,連接到遠程服務器,並連接到該服務器後,該服務器上運行某些命令。
可能嗎?
我試過Google搜索,但沒有找到東西,我期待。
爲此,您可以使用SSH(安全殼),你可以參考答案How to use SSH to run a shell script on a remote machine?
/tmp/sh.sh is shell script on remote server.
#!/bin/bash
ssh "[email protected]" 'sh -c "((nohup /tmp/sh.sh))"'
#use following for suppressing the output from remote server script.
ssh "[email protected]" 'sh -c "((nohup /tmp/sh.sh &>/dev/null) &)"'
我有一個疑問這個問題,難道我們不需要任何密碼的,因爲我連接到其他服務器。在你的代碼中表示沒有提及密碼? – sandeepKumar
@sandeepKumar用私鑰設置ssh。 – Barmar