This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Please put formatted code inside [code] and [/code] tags so it can be easily read and analyzed. I spent more time trying to work out whether your braces were correct and then reformatting your post than I should have, resulting in having less time to actually look at your problem.
A couple of quick thoughts -
You are expecting "aassword" - is this correct? The word Password normally only has a single "a", so I would not have expected your script to ever work.
I think that the problem is likely to be with the fact that you have nothing after the sending of the password - you just allow the expect command to return. So sometimes the timing will be right and you will have an instantaneous login on the remote box that will be immediately dropped, and sometimes expect will complete before you see the output.
So 2 possibilities:
Try putting an "interact" as the line after the "send password\r" - that will allow you to see what happens next, and allow you to use the connection you just made.
Try putting 'expect "Last login"' (or whatever text your login should provide) following the send so you can confirm that you are getting it.
One more comment, while I am thinking about this: if the expect scriptlet is the only work being performed in your overall script, you might want to consider pulling it out into an expect script of its own. This will help you in debugging, and (if you have a decent editor) you should get proper color coding.
That is, if I put your script above into a bash script, everything between the single quotes appears as a single color. Whereas if I put it in a file named rama.exp then vim is intelligent enough to work out that this is an expect script and deals with it accordingly. So the script now becomes:
The output is correct.But my requirement is how to get the output without the line "spwan ssh email@example.com ls" in the output.that is how to display only