LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

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

Rep: Reputation: 0
Expect script help


Hey,
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"
interact

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,
Shrikant
 
Old 07-07-2009, 12:06 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,009
Blog Entries: 5

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
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, 12:39 PM   #3
shriyer
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, 08:42 PM   #4
Niartov
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.

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


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


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

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