Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003

    Unanswered: Problem with "$$" in expect script

    Hi all,

    I have a password changing script which is writen in "expect".

    When I enter a new password which is having normal characters it is working fine.

    When I enter a new password as "test$$12" (For example) it is not setting the password to "test$$12".

    can you please let me know the way to nullify the special meaning of "$$" while passing the argument.

    Here is my program:

    #!/usr/bin/expect -f

    spawn /usr/bin/passwd

    set oldpas [lindex $argv 0]
    set newpas [lindex $argv 1]

    expect "Old password:"
    send "$oldpas\r"
    expect "New password:"
    send "$newpas\r"
    expect "new password:"
    send "$newpas\r"
    expect eof

    Best Regards

  2. #2
    Join Date
    Jun 2002
    What are 'expect' and 'send'? Are they some third party utilities? Is 'spawn' part of the same toolset? How do they work?

    You need to give us some more information. Do you know what the password is getting set to (I'd guess it will contain the PID)?

    I'd guess that when you are SENDing you new password to /usr/bin/passwd, $$ is being expanded to the PID. If this is the case, all I can think to do is to modify the password value to escape any $ so that these are not expanded.

    expect "Old password:"
    send $(echo "$oldpas\r" | sed 's/\$/\\$/g')

    It might work. Let me know - I'm curious!
    Last edited by Damian Ibbotson; 10-02-03 at 08:41.

  3. #3
    Join Date
    Aug 2003
    I think in expect that you use [ so you would have to look at the string as it's passed, something similar to

    foreach c [split $newpas ""] {
    if {[regexp "\[$\]" $c]} {
    append d $c

    well, anyhow, I'm a little rusty but it's surely close to that .....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts