How can I automate running commands remotely over SSH to multiple servers in parallel?

前端 未结 20 1689
温柔的废话
温柔的废话 2020-12-12 20:03

I\'ve searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as:

ssh user@host -t sudo su -         


        
20条回答
  •  抹茶落季
    2020-12-12 20:12

    Well, for step 1 and 2 isn't there a tomcat manager web interface; you could script that with curl or zsh with the libwww plug in.

    For SSH you're looking to: 1) not get prompted for a password (use keys) 2) pass the command(s) on SSH's commandline, this is similar to rsh in a trusted network.

    Other posts have shown you what to do, and I'd probably use sh too but I'd be tempted to use perl like ssh tomcatuser@server perl -e 'do-everything-on-one-line;' or you could do this:

    either scp the_package.tbz tomcatuser@server:the_place/.
    ssh tomcatuser@server /bin/sh <<\EOF
    define stuff like TOMCAT_WEBAPPS=/usr/local/share/tomcat/webapps
    tar xj the_package.tbz or rsync rsync://repository/the_package_place
    mv $TOMCAT_WEBAPPS/old_war $TOMCAT_WEBAPPS/old_war.old
    mv $THE_PLACE/new_war $TOMCAT_WEBAPPS/new_war
    touch $TOMCAT_WEBAPPS/new_war [you don't normally have to restart tomcat]
    mv $THE_PLACE/vhost_file $APACHE_VHOST_DIR/vhost_file
    $APACHECTL restart [might need to login as apache user to move that file and restart]
    EOF

提交回复
热议问题