[SSH] : commande à distance

Résolu
tlep Messages postés 596 Date d'inscription   Statut Membre Dernière intervention   -  
zipe31 Messages postés 36402 Date d'inscription   Statut Contributeur Dernière intervention   -
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 ;-)
A voir également:

8 réponses

tlep Messages postés 596 Date d'inscription   Statut Membre Dernière intervention   118
 
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 :-))
6
Chacual Messages postés 230 Date d'inscription   Statut Membre Dernière intervention   150
 
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"'
4
jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 896
 
Salut,
ssh root@192.168.203.33 'bash -c "for name in /home/*; do ls "$name"; done;"'
;-))
4
tlep Messages postés 596 Date d'inscription   Statut Membre Dernière intervention   118
 
Comment on peut intégrer un find avec ta méthode ?

for Filename in `find ...`;do echo $Filename;done

?
0
jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 896
 
Re-
ssh root@192.168.203.33 'bash -c "find /rep -name "fichier" -exec ls -l {} \;"'
;-))
0
sebsauvage Messages postés 32893 Date d'inscription   Statut Modérateur Dernière intervention   15 662
 
Essaie en lançant tes commandes avec bash -c "commande1;commande2;etc"
2

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
tlep Messages postés 596 Date d'inscription   Statut Membre Dernière intervention   118
 
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'
2
sebsauvage Messages postés 32893 Date d'inscription   Statut Modérateur Dernière intervention   15 662
 
ssh 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.
2
tlep Messages postés 596 Date d'inscription   Statut Membre Dernière intervention   118
 
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 ?
2
zipe31 Messages postés 36402 Date d'inscription   Statut Contributeur Dernière intervention   6 430
 
Si c'est possible :

ssh root@serveurB 'bash -s' ton_script.sh
0
daniel
 
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
1