[SSH] : commande à distance
Résolu
Bonjour,
Je souhaite effectuer des commandes complexes à distance, et çà ne fonctionne pas:
Exemple:
ssh root@192.168.xxx.xx "ls /home"
Ca marche :
awstat
billingbzh
billing_vm
conf
crm
etc...
Par contre:
ssh root@192.168.xxx.xx "for i in `ls /home`;do ls $i;done"
La j'obtiens des erreurs :
bash: -c: line 2: syntax error near unexpected token `conf'
bash: -c: line 2: `conf'
On ne peut pas exécuter des commandes complexes, ou des shells via ssh ?
Merci ;-)
Je souhaite effectuer des commandes complexes à distance, et çà ne fonctionne pas:
Exemple:
ssh root@192.168.xxx.xx "ls /home"
Ca marche :
awstat
billingbzh
billing_vm
conf
crm
etc...
Par contre:
ssh root@192.168.xxx.xx "for i in `ls /home`;do ls $i;done"
La j'obtiens des erreurs :
bash: -c: line 2: syntax error near unexpected token `conf'
bash: -c: line 2: `conf'
On ne peut pas exécuter des commandes complexes, ou des shells via ssh ?
Merci ;-)
Configuration: Windows XP Firefox 2.0.0.4
8 réponses
-
Si je fais:
ssh root@192.168.203.33 'bash -c "for i in `ls /home`;do ls $i;done"'
bash: -c: line 2: syntax error near unexpected token `billingbzh'
bash: -c: line 2: `billingbzh'
Si je fais :
ssh root@192.168.203.33 "bash -c 'for i in `ls /home`;do ls $i;done'"
bash: -c: line 2: syntax error near unexpected token `conf'
bash: -c: line 2: `conf'
LOL :-)) -
ModérateurEssaie en lançant tes commandes avec bash -c "commande1;commande2;etc"
-
Y'a du mieux il plante plus sur "conf" :
ssh root@192.168.xxx.xx bash -c "for i in `ls /home`;do ls $i;done"
ca me donne :
i: -c: line 1: syntax error near unexpected token `newline'
i: -c: line 1: `for'
bash: line 2: conf: command not found
bash: line 3: crm: command not found
bash: line 4: custuser: command not found
bash: line 5: log: command not found
bash: line 6: lost+found: command not found
bash: line 7: nttuser: command not found
bash: line 8: nusoap: command not found
bash: line 9: website: command not found
bash: -c: line 10: syntax error near unexpected token `do'
bash: -c: line 10: `ws;do ls ;done' -
Modérateurssh root@192.168.xxx.xx 'bash -c "for i in `ls /home`;do ls $i;done"'
peut-être ?
(sinon il va probablement prendre -c et ce qui suit comme une option de ssh. -
C'est juste un problème de ls :
ls $i ne fonctionne pas car tu ne te trouves pas dans le bon répertoire.
Il faut exécuter ls /home/$i !
Donc : ssh root@192.168.xxx.xx 'bash -c "for i in `ls /home`;do ls /home/$i;done"' -
ModérateurSalut,
ssh root@192.168.203.33 'bash -c "for name in /home/*; do ls "$name"; done;"'
;-))
-
Salut,
merci çà marche !
Tu peux expliquer le mystère ?
-Est-ce que je peux exécuter un shell créé en local via ssh ?
Par exemple créer un script sur la machine A puis l'exécuter via ssh :
ssh root@B 'bash -c 'mon_script.sh' ?
Apparemment non puisque mon_script.sh se trouve sur A et va essayer de l'exécuter sur B ? -
Je fais d'abord un scp (secure copy) vers la machine et en suite je l'exécute via ssh. Cela fonctionne!
Par contre, il ne faut pas oublier être placé dans les bon répertoire où on a copié le fichier .sh