{"id":12125,"date":"2019-03-22T11:17:03","date_gmt":"2019-03-22T11:17:03","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12125"},"modified":"2019-03-22T11:17:03","modified_gmt":"2019-03-22T11:17:03","slug":"using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines\/","title":{"rendered":"Using DSH (Distributed Shell) to Run Linux Commands Across Multiple Machines"},"content":{"rendered":"<p><strong>Systems Administrators<\/strong>\u00a0know all too well the importance of being able to monitor and administer numerous machines in a short time, and preferably, with as little running around as possible. Whether it is a small cloud environment, or an enormous server cluster, the ability to centrally manage computers is essential.<\/p>\n<div id=\"attachment_4526\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/DSH.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4526\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/DSH.png\" alt=\"DSH Commands\" width=\"435\" height=\"321\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">DSH Run Commands Across Multiple Servers<\/p>\n<\/div>\n<p>To partly accomplish this, I am going to show you how to use a nifty little tool called\u00a0<strong>DSH<\/strong>\u00a0that allows a user to run commands over multiple machines.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/execute-commands-on-multiple-linux-servers-using-pssh\/\" target=\"_blank\" rel=\"noopener\">Pssh \u2013 Execute Commands on Multiple Remote Linux Servers<\/a><\/p>\n<h3>What is DSH?<\/h3>\n<p><strong>DSH<\/strong>\u00a0is short for \u201c<strong>Distributed Shell<\/strong>\u201d or \u201c<strong>Dancer\u2019s Shell<\/strong>\u201d it is freely available on most major distributions of\u00a0<strong>Linux<\/strong>, but can easily be built from source if your distribution does not offer it in its package repository. You can obtain the source at.<\/p>\n<ol>\n<li><a href=\"http:\/\/www.netfort.gr.jp\/~dancer\/software\/dsh.html.en\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/www.netfort.gr.jp\/~dancer\/software\/dsh.html.en<\/a><\/li>\n<\/ol>\n<h3>Install DSH (Distributed Shell) in Linux<\/h3>\n<p>We are going to assume a\u00a0<strong>Debian<\/strong>\u00a0\/\u00a0<strong>Ubuntu<\/strong>\u00a0environment for the scope of this tutorial. If you are using another distribution, please substitute the appropriate commands for your package manager.<\/p>\n<h5>On Debian \/ Ubuntu<\/h5>\n<p>First, let\u2019s install the package via\u00a0<strong>apt:<\/strong><\/p>\n<pre>$ sudo apt-get install dsh<\/pre>\n<h5>On RHEL \/ CentOS \/ Fedora<\/h5>\n<p>This method is for those who are not using\u00a0<strong>Debian<\/strong>, and want to compile it from source tar balls. First you need to compile \u201c<strong>libdshconfig<\/strong>\u201d and install.<\/p>\n<pre># wget http:\/\/www.netfort.gr.jp\/~dancer\/software\/downloads\/libdshconfig-0.20.10.cvs.1.tar.gz\r\n# tar xfz libdshconfig*.tar.gz \r\n# cd libdshconfig-*\r\n# .\/configure ; make\r\n# make install<\/pre>\n<p>Then compile\u00a0<strong>dsh<\/strong>\u00a0and install.<\/p>\n<pre># wget http:\/\/www.netfort.gr.jp\/~dancer\/software\/downloads\/dsh-0.22.0.tar.gz\r\n# tar xfz dsh-0.22.0.tar.gz\r\n# cd dsh-*\r\n# .\/configure ; make \r\n# make install<\/pre>\n<p>The main configuration file \u201c<strong>\/etc\/dsh\/dsh.conf\u201d<\/strong>\u00a0(For\u00a0<strong>Debian<\/strong>) and \u201c<strong>\/usr\/local\/etc\/dsh.conf<\/strong>\u201d (for\u00a0<strong>Red Hat)<\/strong>\u00a0is pretty straightforward, but since\u00a0<strong>rsh<\/strong>\u00a0is an unencrypted protocol, we are going to use\u00a0<strong>SSH<\/strong>\u00a0as the remote shell. Using the text editor of your choice, find this line:<\/p>\n<pre>remoteshell =rsh<\/pre>\n<p>And change it to:<\/p>\n<pre>remoteshell =ssh<\/pre>\n<p>There are other options you can pass in here, if you choose to do so, and there are plenty of them to find on the\u00a0<strong>dsh man page<\/strong>. For now, we are going to accept the defaults and have a look at the next file,\u00a0<strong>\/etc\/dsh\/machines.list<\/strong>\u00a0(for\u00a0<strong>Debian<\/strong>).<\/p>\n<p>For\u00a0<strong>Red Hat<\/strong>\u00a0based systems you need to create a file called \u201c<strong>machines.list<\/strong>\u201d in \u201c<strong>\/usr\/local\/etc\/<\/strong>\u201d directory.<\/p>\n<p>The syntax here is pretty easy. All one has to do is to enter in a machine\u2019s credentials (<strong>Hostname<\/strong>,\u00a0<strong>IP Address<\/strong>, or\u00a0<strong>FQDN<\/strong>) one per line.<\/p>\n<p><strong>Note<\/strong>: When accessing more than one machine simultaneously, it would behove you to set up\u00a0<a href=\"https:\/\/www.tecmint.com\/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps\/\" target=\"_blank\" rel=\"noopener\">key-based password-less SSH<\/a>\u00a0on all of your machines. Not only does this provide ease of access, but security wise, it hardens your machine as well.<\/p>\n<p>My \u201c<strong>\/etc\/dsh\/machines.list<\/strong>\u201d or \u201c<strong>\/usr\/local\/etc\/machines.list<\/strong>\u201d file says:<\/p>\n<pre>172.16.25.125\r\n172.16.25.126<\/pre>\n<p>Once you have entered in the credentials of the machines you wish to access, let\u2019s run a simple command like `<strong>uptime<\/strong>` to all of the machines.<\/p>\n<pre>$ dsh \u2013aM \u2013c uptime<\/pre>\n<h5>Sample Output<\/h5>\n<pre><strong>172.16.25.125<\/strong>: 05:11:58 up 40 days, 51 min, 0 users, load average: 0.00, 0.01, 0.05\r\n<strong>172.16.25.126<\/strong>: 05:11:47 up 13 days, 38 min, 0 users, load average: 0.00, 0.01, 0.05<\/pre>\n<h3>So what did this command do?<\/h3>\n<p>Pretty simple. First, we ran\u00a0<strong>dsh<\/strong>\u00a0and passed the \u201c<strong>\u2013a<\/strong>\u201d option to it, which says to send the \u201c<strong>uptime<\/strong>\u201d command to \u201c<strong>ALL<\/strong>\u201d of the machines listed in \u201c<strong>\/etc\/dsh\/machines.list<\/strong>\u201c.<\/p>\n<p>Next, we specified the \u201c<strong>\u2013M<\/strong>\u201d option, which says to return the \u201c<strong>machine name<\/strong>\u201d (specified in \u201c<strong>\/etc\/dsh\/machines.list<\/strong>\u201c) along with the output of the uptime command. (Very useful for sorting when running a command on a number of machines.)<\/p>\n<p>The \u201c<strong>\u2013c<\/strong>\u201d option stands for \u201c<strong>command to be executed<\/strong>\u201d in this case, \u201c<strong>uptime<\/strong>\u201c.<\/p>\n<p><strong>DSH<\/strong>\u00a0can also be configured with groups of machines in the \u201c<strong>\/etc\/dsh\/groups\/<\/strong>\u201d file, where is a file with a list of machines in the same format as the \u201c<strong>\/etc\/dsh\/machines.list<\/strong>\u201d file. When running\u00a0<strong>dsh<\/strong>\u00a0on a group, specify the\u00a0<strong>groupname<\/strong>\u00a0after the \u201c-<strong>g<\/strong>\u201d option.<\/p>\n<p>For\u00a0<strong>Red Hat<\/strong>\u00a0based systems you need to create a folder called \u201c<strong>groups<\/strong>\u201d in \u201c<strong>\/usr\/local\/etc\/<\/strong>\u201d directory. In that \u201c<strong>groups<\/strong>\u201d directory you create a file called \u201c<strong>cluster<\/strong>\u201c.<\/p>\n<p>For example, run the \u201c<strong>w<\/strong>\u201d command on all machines listed in the \u201c<strong>cluster<\/strong>\u201d group file \u201c<strong>\/etc\/dsh\/groups\/cluster<\/strong>\u201d or \u201c<strong>\/usr\/local\/etc\/groups\/cluster<\/strong>\u201c.<\/p>\n<pre>$ dsh \u2013M \u2013g cluster \u2013c w<\/pre>\n<p><strong>DSH<\/strong>\u00a0provides much more flexibility, and this tutorial only scratches the surface. Aside from executing commands,\u00a0<strong>DSH<\/strong>\u00a0can be used to transfer files, install software, add routes, and much more.<\/p>\n<p>To a\u00a0<strong>Systems Administrator<\/strong>\u00a0tasked with the responsibility of a large network, it is invaluable.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Systems Administrators\u00a0know all too well the importance of being able to monitor and administer numerous machines in a short time, and preferably, with as little running around as possible. Whether it is a small cloud environment, or an enormous server cluster, the ability to centrally manage computers is essential. DSH Run Commands Across Multiple Servers &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using DSH (Distributed Shell) to Run Linux Commands Across Multiple Machines&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12125","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12125"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12125\/revisions"}],"predecessor-version":[{"id":12126,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12125\/revisions\/12126"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}