EXPECT in Bash Scripting

“EXPECT” in Bash

“EXPECT” in Bash

Expect scripting language is utilized to nourish input consequently to an intuitive program. It is very easy to learn contrasted with other…

“EXPECT” in Bash

Expect scripting language is utilized to nourish input consequently to an intuitive program. It is very easy to learn contrasted with other scripting languages. 
Utilizing expect allows sysadmins and developers can to automate repetitive and bulky tasks effortlessly. It works by expecting particular strings, and sending or reacting to strings appropriately.

automation using expect

Following three expect commands are used in automation of any interactive processes with certain commands.

  • send — to send the strings to the process
  • expect — wait for the specific string from the process
  • spawn — to start the command

Generally, expect script files has .exp as extensions.

Installing Expect

apt-get install expect

Expect Examples

Expect “Hello World” Example. The following expect script is expecting the specific string “hello”. When it finds it (after user enters it), “world” string will be send as response.

#!/usr/bin/expect
expect "hello"
send "world"

SSH example using expect

#!/usr/bin/expect
set timeout 60
spawn ssh user_name@ip_address
expect “pass”
send “password\r”
interact

These little scripting techniques helps you automating your daily life hectic and lengthy tasks, use expect and save your time.

0 comments:

Post a Comment