简体   繁体   中英

remote bash script execution

I am thinking about a bash script that can login to 10 servers one by one, execute some task and save the output in a common file in the source server from which I am logging into the servers. To be more clear, I am using a test server 'test'and I need to login to other servers such as server1,server2,...server10 using ssh. Once I logged in successfully, execute some command, say cat /root/serverstatus and save the output to a common file in the 'test' server in a file named serverstatus.txt. I have ssh keygen is already installed and no password is required to enter to these servers. Thanks in advance.

From test server

for i in {1..10}; do ssh server${i} cat /root/serverstatus; done > file

If your user isn't root add sudo before cat For some operation with sudo via ssh you should comment line "Defaults requiretty" in sudoers file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM