You are not logged in.
[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
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
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
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
Try a debug command at the top of the script (after the #! line)
exp_internal 1
The terminal output may tell you something
....
.........
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
Glad you got it working 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
Glad you got it working
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
Will do. Is exp_internal exclusively for TCL?
I've only been reading the manpage. You will have to do your own investigating...
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
@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
@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
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