![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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
Code:
./ssh.sh[9]: syntax error at line 11 : `<<' unmatched 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 |