Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 07-07-2009, 10:48 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 17

Rep: Reputation: 0
Expect script help

I am writing an expect script to be called by a ksh script. The expect script as expect will automate ssh login, and check for /var/crash (dump) space on the server, and return a value depending on if space is
enough or not.

#!/usr/bin/expect -f
spawn ssh -o StrictHostKeyChecking=no abc@def
expect "netdump@def's password:"
sleep 1
send "abc\r"
sleep 3
expect ".com"
set result [exec df /var/crash | grep -v Filesystem | grep -v dev | tr -s " " " " | cut -d " " -f4]
puts " the value is $result"

*** The set command shud set result to value of free space on the remote server right ?? But it sets it to the value of free space on the host server. Got no idea why. ***

puts " the value is $result"
send "logout\r"

Any suggestions ?

I want the exec command to compute this on the remote server. Store the value in $result.
I 'll pass an argument to this expect script which is min free space.
I can then compare these two and return 0 if the server has enuf space and 1 if not .

Directions please,
Old 07-07-2009, 01:06 PM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,553
Blog Entries: 15

Rep: Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494Reputation: 1494
Rather than use expect why not just create an ssh trust since you want to automate the login? This way you don't have to store the password in a text file.

You can then run ssh commands and get their output more cleanly.
Old 07-07-2009, 01:39 PM   #3
LQ Newbie
Registered: Jul 2009
Posts: 17

Original Poster
Rep: Reputation: 0
true .. that is an option..
But since I'm along this path..
I dont understand why the set result [ .. ] line is executing the df command on the local host rather than remote ? The ssh session has already been spawned and authenticated by now.
Does the exec command force it to do on the local host ??
Old 07-08-2009, 09:42 PM   #4
LQ Newbie
Registered: Feb 2009
Posts: 8

Rep: Reputation: 0
It looks like you are trying to run a tcl command which I don't think will work. You still have to send the command to the remote system. I think you have to play with the escape chars but this might get you going in the right direction.

expect ".com"
send "df /var/crash | grep -v Filesystem | grep -v dev | tr -s \" \" \" \" | cut -d \" \" -f4\r"
set result $expect_out(buffer)


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: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
Expect Script coolest Programming 7 02-16-2009 04:59 PM
expect script output saltydog4791 Programming 1 05-27-2008 09:01 AM
Troubleshooting script that uses expect kaplan71 Linux - Software 4 02-29-2008 06:23 PM
Script... variables with expect? Manana Linux - Networking 1 01-19-2007 05:41 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:15 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