Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. If you want to execute a command on a set of nodes, you can install and use something dsh or parallel-ssh on your ubuntu.
  2. Or you can use the following few lines of code.
  3. This will come in handy when you don't have sudo access to install one of the above mentioned tools.
  4.  
  5. Save the following lines of code and name the file parallel.sh (you can improvise - add it to path, etc)
  6.  
  7. #!/bin/bash
  8.  
  9. P1=""
  10. for i in `cat $1`
  11. do
  12. ssh $i "$2" | sed "s/^/$i: /" &
  13. P1=$P1" "$!
  14. done
  15. wait $P1
  16.  
  17.  
  18. Create a host files with each line in the following format and save the file
  19. <username>@<ip-address>
  20.  
  21. eg:
  22. user1@10.1.1.1
  23. user1@10.1.1.2
  24. user1@10.1.1.3
  25. user2@10.1.1.4
  26.  
  27. Execute a command on all the nodes using parallel.sh as follows
  28.  
  29. ./parallel.sh <host-file-name> "<command>"
  30.  
  31. eg:
  32.  
  33. ./parallel.sh host-file "pwd"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement