Use shell scripts to automatically remotely update Linux servers

Source: Internet
Author: User
This experiment is passed in the Centos/RHEL system. For other versions of linux/Unix, you only need to make appropriate modifications. This script requires that the SSH service must be enabled on the Unix-like server you manage, public and Private keys have been set for automatic login. For more information, see autologinforssh. #! /Bin/bash # byService-Labshttp: // www. service. labs.

This experiment is passed in the Centos/RHEL system. For other versions of linux/Unix, you only need to make appropriate modifications. This script requires that the SSH service must be enabled on the Unix-like server you manage, public and Private keys are set for automatic login. for more information, see auto login for ssh.
#! /Bin/bash
# By Service-Labs http://www.service.labs.com
# Using an array to store SSH commands for each server
Hosts = (
"Ssh root@www.service-labs.com yum update-y"
"Ssh root@bak.service-labs.com-p 222 yum update-y"
"Ssh mail@mail.service-labs.com-t sudo '/usr/bin/yum update-y '"
"Ssh root@192.168.33.22 yum update-y"
"Ssh root@192.168.0.25-p 5006 yum update-y"
"Ssh root@192.168.35.4-t sudo '/usr/bin/yum update-y '"
)
# Reading arrays and executing ssh commands
For sshcmd in "$ {hosts [@]}"; do $ sshcmd; done

Put the above script in cron for scheduled execution. If you manage many servers, using this shell script can save you a lot of time!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.