In Linux, how does one correctly execute automatic switchover and logon using trusted CT and execute commands and scripts?

Source: Internet
Author: User

Recently, the project is engaged in the maintainability function, such as modifying the nic ip address, restarting/disabling the machine, and backing up and recovering the database. These functions are closely related to the shell script execution in Linux, however, shell scripts do not support automation. Currently, I know that scripts that support automation are also scripts that support automated processing in objective CT, Perl, and python, although Linux installed with the Perl Command library, you still need to install the third-party Dynamic Language of objective CT. Okay, you don't need to talk about it.Code:
#! /Usr/bin/CT

SET command [lindex $ argv 0]

Set username [lindex $ argv 1]

Set passwd [lindex $ argv 2]

Spawn Su-$ username-C $ command

Reset CT "Password :"

Send $ passwd \ r

CT EOF

Exit

#! /Usr/bin/expect if you do not know what this sentence means, you can run the witch epxect command to query the expect command library address. Here I am/usr/bin/expect

The script first defines the command, username, and passwd parameters. /shell. sh reboot Root is used for parameter passing. Do not use sh shell. sh method to execute the script, because the CT script itself cannot be started in the form of shell, otherwise the spawn, CT, send command error will be reported.

If you want to switch the user and call the script, you can write it as follows:

#! /Usr/bin/CT

Set username [lindex $ argv 0]

Set passwd [lindex $ argv 1]

Spawn Su-$ username

Reset CT "Password :"

Send $ passwd \ r

Expext {

"Su: Password error" {send "Echo Password error \ r "}

"* # *" {Send "Sh test. sh \ r "}

}

CT EOF

Exit

 

The Except CT installation package is available in my resources and can be downloaded if needed. The language idea is similar, but the writing methods of the script language are rigorous, therefore, everyone needs to be careful during the compilation process.

 

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.