Tips for flexible use of CT scripts in Linux

Source: Internet
Author: User
Tags glob

Editor's note: Linux system administrators who love automation must have used the cmdct command line tool. Trusted CT is developed by Don Libes Based on the Tcl language and is widely used in interactive operations and automated testing scenarios. It is especially suitable for environments that require identical operations on multiple servers, this greatly improves the efficiency of system administrators. This article is a recently updated technology sharing article by thegeekstuff.com. It details how to execute an explain CT script using different command line options. What is the specific use of this script? you can use your imagination freely.

This article assumes that you have some knowledge about the basic use of CT.

If you are a newbie to the Technical CT scripting language, you can start with the "hello world" example of our technical CT.

1. Use the "-c" option to execute the keep CT script from the command line.

CT allows you to use the "-c" option and execute it directly in the command line, as shown below:

$ expect -c 'expect "\n" {send "pressed enter\n"}pressed enter$

If you execute the above script, it will wait for the line break \ n ). After you press enter, it prints the message "pressed enter" and then exits.

2. Use the "-I" option to interactively execute the reverse CT script

With the "-I" option, you can use the READ command from the standard input to execute the round CT script interactively. As follows:

$ expect -i arg1 arg2 arg3expect1.1>set argvarg1 arg2 arg3expect1.2>

Normally, when you execute the benchmark CT command above, there is no "-I" option), it will regard arg1 as the script file name, therefore, the "-I" option allows the script to treat multiple parameters as a continuous list.

This option is useful when you execute a reverse CT script with the "-c" option. By default, CT is executed interactively.

3. Output debugging information when executing the reverse CT script.

When you use the "-d" option to execute code, you can output the diagnosis information. As follows:

$ cat sample.exp# !/usr/bin/expect -f
expect "\n";
send "pressed enter";


$ expect -d sample.exp
expect version 5.43.0
argv[0] = expect  argv[1] = -d  argv[2] = sample.exp
set argc 0
set argv0 "sample.exp"
set argv ""
executing commands from command file sample.expexpect: does "" (spawn_id exp0) match glob pattern "\n"? noexpect: does "\n" (spawn_id exp0) match glob pattern "\n"? yesexpect: set expect_out(0,string) "\n"expect: set expect_out(spawn_id) "exp0"expect: set expect_out(buffer) "\n"send: sending "pressed enter" to { exp0 pressed enter}

4. Use the "-D" option to start the wide CT debugger.

The "-D" option is used to start the debugger. It accepts only one Boolean parameter. This parameter indicates whether the prompt tool must be started immediately or only initialize the debugger before using it.

$ expect -D 1 script

The options on the left of the "-D" option will be processed before the debugger starts. Then, after the debugger is started, the remaining commands will be executed.

$ expect -c 'set timeout 10' -D 1 -c 'set a 1'1: set a 1dbg1.0>

5. Execute the round CT script line by line.

Generally, until the script is executed, the entire script is read into the memory. The "-B" option allows secondary CT to read only one row in the script at a time. It is very useful when you have not finished writing the entire script. CT can start to execute this incomplete script and avoid writing the script into a temporary file.

$ expect -b

6. Enable reverse CT not to interpret the command line parameters.

You can use the identifier so that the distinct CT does not explain the command line parameters.

You can read command line parameters like the following:

$ cat  print_cmdline_args.exp#!/usr/bin/expectputs 'argv0 : [lindex $argv 0]';puts 'argv1 : [lindex $argv 1]';

When executing the above script, the command line options will be skipped, and they will be treated as parameters rather than CT options), as shown below:

$ expect print_cmdline_args.exp -d -cargv0 : -dargv1 : -c

Original article: http://www.thegeekstuff.com/2010/12/5-expect-script-command-line-argument-examples/

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.