Comando SSH incorporato


15

È possibile eseguire un semplice comando SSH in linea, ad esempio:

ssh foo@bar.com { cd foo/bar && rm *.foobar }

Risposte:


27

Se si desidera eseguire cd foo/bar && rm *.foobarsul computer remoto, è sufficiente farlo

ssh foo@bar.com  'cd foo/bar && rm *.foobar'

e vedi man ssh...

ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D
[bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L   [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R
[bind_address:]port:host:hostport] [-S ctl_path] [-w tunnel:tunnel
[user@]hostname [command]

Le parti che desideri:

ssh [user@]hostname [command]

2
Vale la pena notare che è possibile reindirizzare STDIN e STDOUT anche con questo metodo: proprio l'altro giorno ho realizzato un'immagine HD di una macchina remota usando DD su ssh.
crazy2be

9

stile 1: ssh user@host 'embedded command'

style 2: ssh user@host " $(cat cmd.txt) "
cmd.txt è un file che contiene il tuo comando remoto che si trova sul tuo computer locale


7

sì :

ssh foo@bar.com 'cd foo/bar && rm *.foobar '
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.