Automatic login script using login CT

Source: Internet
Author: User

There are a lot of scripts for automatic login using CT, but there is no clear explanation. Beginners generally copy and add to favorites. However, I don't know why. This article uses a shortest example to illustrate the script principle.
The script code is as follows:
######################################## ######
#! /Usr/bin/CT
Set timeout 30
Spawn ssh-l username 192.168.1.1
Reset CT "Password :"
Send "ispass \ r"
Interact
######################################## ######
1 .[#! /Usr/bin/CT]
This line tells the code in the operating system script to use that shell for execution. The objective CT is similar to bash in Linux and CMD in windows.
Note: This line must be in the first line of the script.
2. [set timeout 30]
Basically, anyone who knows English knows that this is the time-out period. Now you only need to remember that the unit of time is second.
3. [spawn ssh-l username 192.168.1.1]
Spawn is the internal CT command that can be executed only after entering the CT environment. If the CT is not installed or the spawn command cannot be found directly in the default shell. Therefore, do not use commands such as "which spawn" to find the spawn command. For example, in windows, DIR is an internal command that comes with shell. You cannot find an executable file of dir.com or dir.exe.
Its main function is to add a shell to the SSH running process to transmit interactive commands.
4. [Keep CT "Password:"]
The secondary CT command is also an internal command of secondary CT. It is a bit dizzy. The shell command of secondary CT is the same as the internal command, but it is not a function and it is just a habit. This command is used to determine whether the output result contains a string of "Password:". If yes, return immediately; otherwise, return after a period of time, the waiting duration is the last 30 seconds.
5. [Send "ispass \ r"]
The interaction is performed here, which is equivalent to the password input.
Tip: do not add "\ r" to the end of the command string. If an exception occurs, check it.
6. [interact]
After the execution is complete, the interaction status is maintained, and the control is handed over to the console. At this time, you can perform manual operations. If this statement is not entered, the system will exit after logon, instead of staying on the remote terminal. If you only log on and run
#! /Usr/bin/expect # Pay Attention to the installation path. If you are not sure about the installation path, perform whereis expect.
# Change a login shell to bash
Set User [lindex $ argv 0]
Spawn bash $ user
CT "]:"
Send "/bin/bash"
CT EOF
Exit

Automatic login script using login CT

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.