Expect script strange behaviour

Hi people,

I'm having some strange behaviour with an 'expect' script.

spawn csession blah
expect "Username: "
send "userblah\r"
expect "Password: "
send "passwordblah\r"
interact

When I execute the script as root it runs perfectly.

However, when executed as any other user, it appears to send the 'send' commands twice.

Well, I can only assume it is sending twice and not just sending it late as the script successfully logs in but then after approx 5-10 secs it sends 'userblah' and then 'passwordblah' to the application that it has already logged into. :confused:

Any ideas ?

Many thanks in advance for any answers.

---------- Post updated at 06:44 PM ---------- Previous update was at 05:46 PM ----------

Just added a sleep into the script after supplying the password and I can see more strange behaviour (once again not when executed as root)

Here is what happens when ran as root:

spawn csession blah

Username: userblah
Password: passwordblah

application command line:

But when ran as another user:

spawn csession blah

application command line: userblah

As you can see, the username and password does not even appear as the other user, in fact not even the prompt to put it in appears, but it must be being entered however, because you cannot get into the application without a correct username and login (I have tested this by logging into the app manually using the same commands as in the script and you MUST put then in) or you get 'Access Denied'.

This is doing my head in !:mad: