Click to See Complete Forum and Search --> : telnet script
tecknophreak
06-10-2003, 12:04 PM
I'm curious if anyone's written a script which can telnet into a machine, say run a program, and get the output.
Say something like:
telnet xxx.xxx.xxx.xxx
username
userpassword
ls -l
And have the script output the results.
P.S. Don't be too harsh, I'm not a script-kiddie. My domain is in C/C++. However, I guess I should start learning more about it since I work 99% with Linux.
hlrguy
06-10-2003, 12:24 PM
autoexpect: autoexpect watches you interacting with another program and creates an Expect script that reproduces your interactions...and if you are a beginner, you may be able to get away with learning nothing more about Expect than how to call autoexpect.
autoexpect -f <scriptname>
telnet <IP Address>
.......
exit
NOTE: The exit is to exit autoexpect. you will see a message like 'autoexpect done, file is <filename> once you exit the autoexpect.
Once your spawned program is running, interact normally. When you have exited the shell (or program that you specified), autoexpect will create a new script for you.
The above is snipped from the man page. Incredible tool. Once created, you simply run the script it created. You can either watch it go accross the screen or
<scriptname> > logfileofscript
which will pipe the outout to a file called logfilescript
Change permission to 600 or 700 because any entered passwords are in plain text inside the script.
hlrguy
ph34r
06-10-2003, 12:54 PM
If you have promptless logins setup with SSH, you could do
export FOO=`ssh -X user@host ls -l`
tecknophreak
06-10-2003, 01:22 PM
That autoexpect is pretty sweet. Just a tweek here and there and the script it output is great. It's not exactly what I need, but it's putting me in the right direction. :D
Thanks!!
hlrguy
06-10-2003, 02:06 PM
You can use autoexpect to create a parser script that just grepped what you wanted, then
autoexpect <scriptname> | autoexpect <parsername>
For example, if you did an ls -l <dirname> and were looking for files owned by user 'Cow'
you could
grep Cow > cowfilelist
Anyway, glad to have helped.
hlrguy