2017-02-20 45 views
0

我試圖從Windows機器的電源shell執行shell腳本。因此,開始編寫shell腳本並使用以下命令調用到Linux框中:從Windows機器的電源shell執行shell腳本

PS>.\pscp.exe .\abc.sh [email protected]:/root` and gave the permissions through power shell by using below command 
PS>.\plink.exe -pw "L***e" [email protected] -P 22 "chmod +x abc.sh"` after that verified that shell script copied or not 
PS>.\plink.exe -pw "L***e" [email protected] -P 22 "ls" 

因此它被複制。在那之後,當我使用下面的命令執行:

PS>.\plink.exe -pw "L***e" [email protected] -P 22 "bash ./abc.sh"` 

這不是在這個意義上得到錯誤的工作,如:

./abc.sh: line 4: $'\r': command not found ./abc.sh: 
line 5: syntaxerror near unexpected token `$'\r'' '/abc.sh: 
line 5: `function abc() 
PS>.\plink.exe -pw "L***e" [email protected] -P 22 "./abc.sh" 
bash: ./abc.sh: /bin/bash^M: bad interpreter: No such file or directory 

如果任何有價值的建議和可觀的感謝提前......

回答

0

後運行下面的命令

PS>.\plink.exe -pw "L***e" [email protected] -P 22 "dos2unix abc.sh" 
dos2unix: converting file abc.sh to UNIX format ... 

後assaign執行權限的腳本文件

PS>.\plink.exe -pw "L***e" [email protected] -P 22 "chmod + abc.sh" 
首先安裝包

PS>.\plink.exe -pw "L***e" [email protected] -P 22 "yum install dos2unix -y" 

最後給腳本文件路徑,那麼你的腳本將被執行。

PS>.\plink.exe -pw "L***e" [email protected] -P 22 "/root/abc.sh" 
2

我沒有使用太多的Windows文本編輯器,但「^ M:糟糕的解釋器:沒有這樣的文件或目錄」 - 表示有Windows版本的回車。所以它可能只是將你的腳本文件轉換爲unix風格。

參考:https://kb.iu.edu/d/acux