Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 01-17-2007, 04:00 AM   #1
Registered: Dec 2005
Distribution: Ubuntu,Debian
Posts: 41

Rep: Reputation: 15
Script... variables with expect?

Need some help with a script im trying to modify, i "stole" it from ping2tariq here on the forum.
Sad to say my scripting skills arent what they should be.

This is what i want to do: log into a telnet session, run command and save output to file, name that file by todays date/time, save the file on a share.
Heres what i got so far, my problem is the naming, having trouble with the naming of the file. (running it on local machine for testing purpose)

[root@test ~]cat /tmp/test
for i in `cat /tmp/ip`
/usr/sbin/ttelnet1 $i

[root@test ~]cat /tmp/ip

#!/usr/bin/expect --
set timeout 30
set machine [lindex $argv 0]
set username user
set password p@ssw0rd
#log_user 0
spawn telnet $machine
expect "*login*:"
send "$username\n"
expect "*Password*"
send "$password\n"
send "ifconfig > /tmp/$date" <--- want to name this file by date,
#expect "ip:" where and how do i deffine
send "\n" variable?
#expect "name:"
send "$machine\n"
send "exit\n"

Alternativly instead of date i could name it my self, for example if i run ./test <filename> the file will be named <filename>.

Old 01-19-2007, 04:41 AM   #2
Senior Member
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
from man date

send "ifconfig > /tmp/`date +%D`"

The backticks allow shell expansion of the command date


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect Script coolest Programming 7 02-16-2009 03:59 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 10:44 AM
How to combine Expect and Shell script Uday123 Programming 0 12-27-2005 09:01 AM
cron job for expect script ruchitadesai Programming 9 05-27-2005 04:34 AM
BAD SU- from a cronned expect script ganninu Linux - General 1 07-18-2004 10:49 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration