1.8-execute command after automatic login

Source: Internet
Author: User

Then look at a script that executes the command and then exits after landing:


#!/usr/bin/expect

Set user "root"

Set passwd "123456"

Spawn ssh [email protected]

Expect {

"Yes/no" {send "yes\r"; Exp_continue}

"Password:" {send "$passwd \ r"}

} #以上和上一个脚本相同

Expect "]*"

Send "touch/tmp/12.txt\r"

Expect "]*"

Send "echo 1212 >/tmp/12.txt\r"

Expect "]*"

Send "exit\r"


Note: After landing the remote machine, the command behavior [[email protected] ~]# so expect "]*" means to match "]" and * (any character), because some machines are # or maybe $ or other.


1.8-execute command after automatic login

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.