Skip to main content

Tip. Automate Text Input in Commands

Jose CerrejonLess than 1 minuteAppleLinuxRaspberry PIAppleLinuxRaspberry PI

Tip: Automate Text Input in Commands

cmd
cmd

Sometimes it can be tedious to enter certain data in the command line, especially if you have to repeat it several times.

Imagine ftp command line authentication. We can make use of the expect command...


Those of us who use *Axway Appcelerator titanium_ sometimes have to logout/login every time we change from one computer to another and validate the license again. Now anymore!. It will be easier if you modify and execute the following script according to your needs:

#!/usr/bin/expect
spawn appc logout
expect eof
spawn appc login
    set timeout 2
    expect "? Appcelerator ID:"
    send "your@mail.com\r"
    expect "? Password:"
    send "your_password\r"
expect eof

You have to change your@mail.com and your_password.

You can use with other commands: ftp, ssh, etc...

Link: expect (man)open in new window

Link: thegeekstuff.com > 6 Expect Script Examples to Expect the Unexpected (With Hello World)open in new window