The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Performance issue in expect library on AIX 5.3 ravindra_maddal AIX 2 05-14-2008 04:47 AM
Help with expect script somedude Shell Programming and Scripting 3 05-01-2008 11:47 AM
expect issue...help! nimrodman Shell Programming and Scripting 1 04-02-2008 07:05 AM
Need Help with EXPECT script markus2008 UNIX for Advanced & Expert Users 5 03-12-2008 04:49 PM
Expect Script HELP zuinc Shell Programming and Scripting 2 04-30-2002 06:42 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008
Registered User
 

Join Date: Feb 2008
Posts: 13
Unhappy Expect script issue

HI Al,
I have written the following expect script:
Code:
#!/bin/ksh
#!/usr/local/bin/expect--
##echo "PLease enter the server name"
##read host
echo "please enter the instance"
read instance
set ##password to be entered right before the script is run##
##/usr/local/bin/expect<<-EOF
cat serverlist.txt | while {read host};
do
/usr/local/bin/expect<<-EOF
spawn ssh -p 2222 $instance@$host
sleep 1
expect "*Password:*"
sleep 1
send "$1\r"
expect "*/export/home/a61359>#*"
send "/usr/local/bin/top -d 2 >> tempfile.txt\r"
expect "*/export/home/a61359>#*"
send "uuencode tempfile.txt tempfile.txt | mailx -s '$host' myemail@mycompany.com\r"
sleep 1
expect "*/export/home/a61359>#*"
sleep 1
send "rm tempfile.txt\r"
sleep 1
expect "*/export/home/a61359>#*"
sleep 1
send "exit\r"
expect eof
done
This script gives me the error
Code:
./ssh.sh[9]: syntax error at line 11 : `<<' unmatched
when I run it. serverlist.txt is a list of servers in teh same directory as the script
How ever when I run the script by commenting out the while loop and taking the server and the instance name from the user it works.
I have already checked the spaces around the /usr/local/bin/expect<<-EOF and the issue persists.
few noteworthy things.
I have not been able to run expect without having the "/usr/local/bin/expect<<EOF" option.
Could somebody please suggest if I am making a syntax error in the while loop or anything else...
Thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Feb 2007
Posts: 29
you can't mix both expect & ksh in same script. write two 2 scripts one reads the hostfile and sends instance,host, password to expect scripts. which does your job. here is the sample. this might not work as i did try to explain. good luck let me know how it goes.

cat yourscript.sh

#!/bin/ksh
echo "please enter the instance"
read instance
set ##password to be entered right before the script is run##
##/usr/local/bin/expect<<-EOF
cat serverlist.txt | while read host;
do
/usr/lib/some_expect.sh $instance $host $password
done

cat /usr/lib/some_expect.sh

#!/usr/local/bin/expect--
spawn ssh -p 2222 $1@$2 $3 # $1 -- Instance $2-- Host $3-- Password
sleep 1
expect "*Password:*"
sleep 1
send "$1\r"
expect "*/export/home/a61359>#*"
send "/usr/local/bin/top -d 2 >> tempfile.txt\r"
expect "*/export/home/a61359>#*"
send "uuencode tempfile.txt tempfile.txt | mailx -s '$host' myemail@mycompany.com\r"
sleep 1
expect "*/export/home/a61359>#*"
sleep 1
send "rm tempfile.txt\r"
sleep 1
expect "*/export/home/a61359>#*"
sleep 1
send "exit\r"
expect eof
Reply With Quote
  #3 (permalink)  
Old 04-25-2008
Registered User
 

Join Date: Feb 2008
Posts: 13
Thanks sooo much gopidesaboyina...
This helps a lot....
God Bless
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0