Radeji bych pouzil Ansible:
ansible webserver1, -m shell -a "uptime"
Pripadne je mozne vytvorit hosts file a mit moznost pouzivat skupiny:
cat <<END >./hosts
[webservers]
webserver1
webserver2
[mailservers]
mailserver1
mailserver2
END
A pak pustit prikaz na vsech serverech ze skupiny:
ansible webservers -i hosts -m shell -a "uptime"
Ja potrebujem robit update na X-terminaloch v ucebni, ktora nesmie mat svoje DHCP ale az DHCP Ustavu. DHCP ustavu nemam k dispozicii. A na update staci skriptik a jedine, co mi gsh da je mozno paralelizmus v ramci umyslene urobenych troch faz.
skript
#!/bin/bash
IPCKY=$(netstat -a|egrep x11|sort -u -k5|awk '{print $5}' |sed 's/:x11-2//')
PRIKAZ="yes yes |apt-get update"
for IP in $IPCKY;
do
echo "refresh repositories of:" $IP
ssh -i ./my-id_rsa root@$IP $PRIKAZ;
done
PRIKAZ="yes yes|apt-get upgrade"
for IP in $IPCKY;
do
echo "update of:" $IP
ssh -i ./my-id_rsa root@$IP $PRIKAZ;
done
PRIKAZ="reboot"
for IP in $IPCKY;
do
echo "reboot of:" $IP
ssh -i ./my-id_rsa root@$IP $PRIKAZ;
done
zeby to bolo az tak tazke si nemyslim
man 1p wiat
"
sleep 1000&
pid=$!
kill −kill $pid
wait $pid
"
#!/bin/bash
for i in `seq 0 9`; do
doCalculations $i &
done
wait
The above script will wait for all 10 spawned subprocesses, but it will always give exit status 0
wait also (optionally) takes the PID of the process to wait for, and with $! you get the PID of the last command launched in background. Modify the loop to store the PID of each spawned sub-process into an array, and then loop again waiting on each PID.
A na toto mame += v cykle
Takze ono to tak zlozite nie je. Samozrejem IPC v shellio asi nebude, neskumal som
Ja pouzivam fabric (http://www.fabfile.org/) s souborem fabfile.py udrzovanem v gitu:
# Fabric File for Servers update
# typical usage
# fab update
from fabric.api import sudo
env.hosts = ['user@example1.tld', 'user@example2.tld', 'user@1.2.3.4']
def update():
sudo("apt-get update")
sudo("apt-get upgrade")
sudo("apt-get dist-upgrade")
sudo("apt-get autoremove")
def reboot():
sudo('reboot')
Pak staci jen prikaz:
fab update
nebo kdyz chci i s restartem
fab update reboot