- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Expect script beginners help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 08:42 PM
тАО08-20-2003 08:42 PM
Expect script beginners help
I am trying to write an expect script that telnets into a server captures the size of a file within the server and then doe s a number of actions based on the size of the file. How do I capture this information. I know I do the following
send -- "telnet 111.111.111.111\r"
do all of the login stuff
....
send -- "ls -l test.raw"
how do I capture the response of this, also how can I use expect to write to a file on my system.
Thanks in advance
- Tags:
- expect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 10:19 PM
тАО08-20-2003 10:19 PM
Re: Expect script beginners help
(you can use remsh, or secure ssh to login without password)
For sessions like telnet you can use utility expect to do this. Then you put your stuuf for file checking.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 10:24 PM
тАО08-20-2003 10:24 PM
Re: Expect script beginners help
I'm actually more concerned with how I can isolate the size of the file and also analyse it using an if statement.
ie if(filesize < 160) then (......)
else(
)
but I'm not sure how I can get the size out of the string ie rwx--r-- directory directory 123 Aug 19 15:13 test.raw
I hope you can help;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 10:24 PM
тАО08-20-2003 10:24 PM
Re: Expect script beginners help
I'm actually more concerned with how I can isolate the size of the file and also analyse it using an if statement.
ie if(filesize < 160) then (......)
else(
)
but I'm not sure how I can get the size out of the string ie rwx--r-- directory directory 123 Aug 19 15:13 test.raw
I hope you can help;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 10:37 PM
тАО08-20-2003 10:37 PM
Re: Expect script beginners help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 11:02 PM
тАО08-20-2003 11:02 PM
Re: Expect script beginners help
if $filesize < 160 {
do stuff
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-20-2003 11:10 PM
тАО08-20-2003 11:10 PM
Re: Expect script beginners help
set file [open /dir/file w]
puts $file "Hello World" ;# writes to /dir/file
close $file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2003 09:21 AM
тАО08-21-2003 09:21 AM
Re: Expect script beginners help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2003 03:12 PM
тАО08-21-2003 03:12 PM
Re: Expect script beginners help
send -- "telnet 111.111.111.111\r"
expect -exact "login:"
send -- "username\r"
expect -exact "Password: "
send -- "password\r"
expect -exact "\$"
send -- "cd /home/username\r"
expect -exact "\$ "
send -- "ls -l test.raw\r"
ll test.raw|awk '{print $5}'
When I run it I get the following result:
$ can't read "5": no such variable
while executing
"ll test.raw|awk '{print $5}'"
(file "./script.exp" line 35)
What have I done wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-21-2003 03:58 PM
тАО08-21-2003 03:58 PM
Re: Expect script beginners help
provided by Tcl, a language used by many other tools. Your scripts needs to use tcl's syntax.
ll test.raw|awk '{print $5}' isn't in tcl's syntax. it is a unix shell command. they are not the same.
this is probably more what your wanting to do
expect -re "^.*$"
sent "ll test.raw|awk '{print $5}'"
set size $expect_out(0,string)
puts "file size = $size"
when the matching string is finally typed
expect returns. But, before returning, expect
stores the matched characters in a variable
called expect_out(0,string)