2009-10-15 11 views
0

Je suis writting un script shell et je veux ces commandes à exécuter en même tempsexécuter quelques commandes simultanément

find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 1' | ./bin/foo.py -m 3 -b 1 | next_command >> log/foo_log.log 2>&1 
find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 2' | ./bin/foo.py -m 3 -b 2 | next_command >> log/foo_log.log 2>&1 
find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 0' | ./bin/foo.py -m 3 -b 3 | next_command >> log/foo_log.log 2>&1 

est-il possible d'utiliser & de laisser tous à courir en même temps? Si c'est possible, puis-je exécuter la commande suivante pour sortir le journal seulement après l'exécution des trois commandes ci-dessus?

tail log/foo_log 

Répondre

2

assez facile, vous pouvez utiliser wait pour faire une pause jusqu'à ce que tous les processus ont quitté.

wait: wait [n]
attente pour le processus spécifié et pour signaler son état de terminaison. Si N n'est pas indiqué, tous les processus enfants actuellement actifs sont attendus, et le code de retour est zéro. N peut être un ID de processus ou une spécification de travail ; Si une spécification de travail est donnée, tous les processus dans le pipeline du travail sont attendus.

Voilà!

find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 1' | ./bin/foo.py -m 3 -b 1 | next_command >> log/foo_log.log 2>&1 & 
find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 2' | ./bin/foo.py -m 3 -b 2 | next_command >> log/foo_log.log 2>&1 & 
find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 0' | ./bin/foo.py -m 3 -b 3 | next_command >> log/foo_log.log 2>&1 & 
wait 
tail log/foo_log 
0

j'ai vu this discussion lors de la recherche de solution, donc je pensais que je voudrais essayer de répondre à ma propre question XD

(find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 1' | ./bin/foo.py -m 3 -b 1 | next_command >> log/foo_log.log 2>&1) & 
(find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 2' | ./bin/foo.py -m 3 -b 2 | next_command >> log/foo_log.log 2>&1) & 
(find ./incoming/kontraktor/ -type f -name '*.html' | sort | awk 'NR % 3 == 0' | ./bin/foo.py -m 3 -b 3 | next_command >> log/foo_log.log 2>&1) & 
wait 
Questions connexes