Or parallel -k 'echo ssh "hostname ls"' :::: hosts. When you run multiple commands with conditional. Note The Progress stream does not support redirection. You can run multiple commands from a single command line or script using conditional processing symbols. PowerShell supports the following output streams. For more information, see aboutRedirection. You can write to these streams using the associated cmdlet or redirection. Also, you will need to add the -n flag to the ssh command so that it doesn't read from stdin. The streams provide channels for different types of messages. ssh sshcmd 'hostname & ls -l /path/to/folder grep sometoken' & If you remove the & from that line, the script will wait until the ssh session finishes to continue on to the next iteration of the loop. 'ĪLternative syntaxes for passing hosts.txt are parallel -k 'echo ssh "hostname ls"' < hosts.txt PowerShell provides multiple output streams. parallel -S node1,node4,node56 'hostname grep. While some SSH servers (like OpenSSH) can handle even multiple commands this way (so your batch file would work there), it's no way a standard behaviour. You can also set up GNU Parallel to be able to ssh into hosts itself, normally in order to distribute processing jobs amongst servers, then the job becomes even easier. A command specified using Plink/PuTTY -m switch is executed using 'exec' SSH channel, that's designed for a single command only. Escape inner quotes Quotes inside other quotes should be escaped, otherwise you're creating an extra end point and start point. The commands are run sequentially, waiting for each before continuing onto the next, but their success or failure has no impact on each other. In order to run SSH commands using powershell you will need to have a copy of plink.exe this can be downloaded independently as a binary here. By default, if you have 8 cores in your CPU, it will run 8 jobs in parallel, but you could set it to 64 for example with parallel -k -j 64. The semicolon is used to separate commands. Obvioulsy you need to remove the echo and add in your quoting and gripping, but the concept should be clear enough.Īnother advantage, other than it now being a one-liner, is that if you have 32,000 hosts to work on, GNU Parallel can be told, using the -j flag, how many processes to run at a time without overloading your server. So, if hosts.txt contains the following: host1 Use GNU Parallel to do them all nicely in parallel and use the -k option to keep the output in order: parallel -k -a hosts.txt 'echo ssh "hostname ls"'
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |