Header Ads

Breaking News

How to use expect: 2-Minute Linux Tips

Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at expect. It’s a tool that allows you to automate interactions with other scripts so that you can run them with a set of predefined answers. For a super simple example, say you have a script called ask00 that looks like this:
Now you want another script to run it for you and tell it you’re OK, so you prepare a script that looks like this one:
We can see that this script is run by expect. It spawns the ask00 script and anticipates the question that it will ask. It then provides the answer you set up ahead of time.
When you run the expect script, you’ll see something like this:
All you had to do was type “exp00”.
Of course, in the real world, rather than in the confines of a 2-minute video, the script you’re running will likely ask a lot more questions and do some real work. You can provide as many expect and send lines in your script as are needed to get the job done.
That’s your Linux tip for expect.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.

Source Link

No comments