LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 01-17-2007, 04:00 AM   #1
Manana
Member
 
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
#!/bin/bash
for i in `cat /tmp/ip`
do
/usr/sbin/ttelnet1 $i
done

[root@test ~]cat /tmp/ip
127.0.0.1
76.5.250.41
76.5.250.42
76.5.250.43
76.5.250.44
76.5.250.45


#!/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 "127.0.0.1\n" variable?
#expect "name:"
send "$machine\n"
send "exit\n"
interact

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

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

Rep: Reputation: 47
from man date

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

The backticks allow shell expansion of the command date
 
  


Reply


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


All times are GMT -5. The time now is 01:32 PM.

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