You are not logged in.

#1 2015-11-18 00:05:30

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

[SOLVED] Expect Scripts...

[MOD EDIT - Topic moved from Scripts...]

Greetings folks. I'm finally at my wits end! So I come to you fine folks for much needed tutelage. I'm trying to use the scripting tool 'expect'. What I'm about to describe is the very general layout of what i'm trying to do...:

#!/usr/bin/expect -f

spawn sudo tcpdump -i eth0

expect {
"\[sudo\] password for kingghidorah:"
send "myPassword\r"
}

That's it, this should be a very very easy, simple script to run, but it's not working, I've gone through multiple versions replacing quotes and options but I can not get this this to actually run the tcpdump command or input the password...

One of the latest errors is that when I run it, the spawn command just displays "sudo tcpdump -i eth0"

Is there something I"m missing here? Any tips would be great, I'd like to start using expect more often but I can't even get this simple script to run!

Last edited by Horizon_Brave (2015-11-18 17:28:48)


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#2 2015-11-18 00:20:17

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Expect Scripts...

I've never used expect, but a couple of things spring to mind:
1) The -f switch is to call a command file. Is that so in your case?
2) Should there be a closing "}" in your code snippet?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2015-11-18 00:36:40

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Expect Scripts...

Whoops, there is a closing '}' in my script, I just left it out here...Re-added it now... And I've tried it with the -f and without...still nothing. There's also certain times when I've changed things around a hair, and when I run it, the output hangs for like 5 seconds...then releases the terminal back to me, with absolutely zero output


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#4 2015-11-18 01:14:51

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Expect Scripts...

Try a debug command at the top of the script (after the #! line)

exp_internal 1

The terminal output may tell you something


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#5 2015-11-18 01:39:25

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Expect Scripts...

damo wrote:

Try a debug command at the top of the script (after the #! line)

exp_internal 1

The terminal output may tell you something


yikes ....


yikes .........


I literally spent 3 hours with expect man pages...crappy videos and online how to's... I did not see anything about this debug command.....
As you can see I'm new the TCL/TK language...but THANK YOU! I figured it out... and here's the syntax..:

#!/usr/bin/expect

#exp_internal 1

spawn sudo tcpdump -i eth0
send "myPASS\r"
expect "\[sudo\] password for kingghidorah: "

This works! But I don't get it... Why do I send the password BEFORE I tell it what to actually expect? I assume these are run in sequential order... It's like saying "Here accept this password, before you know what I"m about to ask for"

Anyway, thanks a lot damo


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#6 2015-11-18 14:26:05

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Expect Scripts...

Glad you got it working smile If you could edit the title of your first post and add [SOLVED]...

PS The Expect manpages have quite a lot about debugging, including

exp_internal[-f file] value 

There is also a TCL degugger command.


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#7 2015-11-18 17:04:59

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Expect Scripts...

damo wrote:

Glad you got it working smile If you could edit the title of your first post and add [SOLVED]...

PS The Expect manpages have quite a lot about debugging, including

exp_internal[-f file] value 

There is also a TCL degugger command.

Will do. Is exp_internal exclusively for TCL?


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#8 2015-11-18 17:38:51

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: [SOLVED] Expect Scripts...

Horizon_Brave wrote:

Will do. Is exp_internal exclusively for TCL?

I've only been reading the manpage. You will have to do your own investigating...

Expect manpage wrote:

exp_internal[-f file] value
    causes further commands to send diagnostic information internal to Expect to stderr if value is non-zero


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#9 2015-11-18 17:53:57

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Expect Scripts...

@Horizon_Brave:
Including your password in a script file is a security risk.
You can reduce the risk slightly by making the script file not world-readable.

Offline

#10 2015-11-18 18:06:17

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: [SOLVED] Expect Scripts...

xaos52 wrote:

@Horizon_Brave:
Including your password in a script file is a security risk.
You can reduce the risk slightly by making the script file not world-readable.

Hi Xaos, yep, trust me I know this, but this is very non-production, non essential, test scenario I'm doing. I'd never ever do this for like SSH or anything internet facing. I'm pretty much just using this just to learn and practice.


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#11 2015-11-19 10:10:15

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] Expect Scripts...

Want examples?
Download the source package:

apt-get source expect

See directories 'example' and 'tests'

Last edited by xaos52 (2015-11-19 10:11:26)

Offline

Board footer

Powered by FluxBB