[ssh] exécuter un script d'un server A vers un server B
Par nicolas le mardi 24 avril 2012, 18:35 - Bugs resolves - astuces - Lien permanent
Depuis Server A :
execution :cat /tmp/testssh
#!/bin/bash
echo "toto" >> /tmp/testtoto
cat /tmp/testssh |ssh linuxadmin2 "/bin/sh"
Vérification sur server B :
cat /tmp/testtoto
toto
## Recuperation des informations techniques d'un serveur ##
## depuis un serveur central : via un compte d'exploitation : user
## CPU / RAM / Disk / OS release / IP ##
LIST_CIBLE='/PATH_LIST'
USER_SSH='user'
SSH_KEY=~/.ssh/id_dsa
SSH_COMM='ssh -T -i '$SSH_KEY' -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o ChallengeResponseAuthentication=no'
LOG_OUT='./scan.log_out'
ROTATE_LOG_OUT='./scan_cmdb.log_out.old'
mv $LOG_OUT $ROTATE_LOG_OUT
echo "NAME;OS;Number_of_Logical_Processor;RAM Allocated"
for i in $LIST_CIBLE
do
$SSH_COMM $USER_SSH@$i <<'EOF'
echo "`hostname`;`head -1 /etc/redhat-release`;`grep -c ^processor /proc/cpuinfo`;`free -g | awk '/Mem/ {print \$2}'`"
EOF
done >> $LOG_OUT