2017-02-20 35 views
0

Ich versuche Shell-Skript von Power Shell in Windows-Maschine ausführen. So begann das Schreiben der Shell-Skript und aufgerufen in der Linux-Box mit dem Befehl unten:Shell-Skript von Power Shell in Windows-Maschine ausführen

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" 

So wurde es kopiert. Danach, wenn ich durch die Verwendung unter Befehl bin Ausführung:

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

Es ist nicht im Sinne immer Fehlern arbeitet wie:

./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 

Sollte wertvollen Anregungen spürbar und Dank im Voraus ......

Antwort

0

zuerst das Paket installieren

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

nach, dass die unter Befehl

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

laufen danach die Erlaubnis Datei, um das Skript auszuführen assaign

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

Geben Sie den Script-Dateipfad an, dann wird Ihr Skript ausgeführt.

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

Ich habe nicht viele Windows-Text-Editoren verwendet, aber "^ M: schlechter Interpreter: Keine solche Datei oder Verzeichnis" - gibt an, dass es eine Windows-Version von Wagenrücklauf gibt. Es könnte also helfen, Ihre Skriptdatei einfach in Unix-Stil zu konvertieren.

Referenz: https://kb.iu.edu/d/acux

Verwandte Themen