Find the answer to your Linux question:
Results 1 to 2 of 2
Help… I am having a very similar problem. I have a webpage (php) and I want to call/execute a expect script (via shell if need be). I have tried PHP-exec, ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    3

    expect script issue

    Help…
    I am having a very similar problem. I have a webpage (php) and I want to call/execute a expect script (via shell if need be). I have tried PHP-exec, passthru, shell_exec, system, escapeshell etc to no avail. (The best results are with passthru). The script is to telnet to a machine (with an argument), login, run a command and exit. When ran from a command line it runs great. I log the event to a file (in expect) and it appears that it connects to the equipment but I never get the “username” prompt to pop up. I also tried putting the expect directly in the .sh file.

    In the webpage I call the script---
    passthru(`/opt/xampp/htdocs/test/checkadd.sh $quote`);



    When ran from command line it looks like this –
    /opt/xampp/htdocs/test/checkadd.sh 72.123.36.19
    spawn telnet 66.153.111.111
    Trying 66.153. 111.111...
    Connected to 66.153.111.111.
    Escape character is '^]'.
    User Access Verification
    Username:theusername
    password:
    MachineName#1#show cable modem 72.123.36.19 verbose
    No cable modem with IP address 72.123.36.19
    MachineName#1#spawn telnet 66.153.222.222
    Trying 66.153.222.222...
    Connected to 66.153.222.222.
    Escape character is '^]'.
    User Access Verification
    Username:htcbackup
    Password:
    MachineName#1#show cable modem 72.123.36.19 verbose
    No cable modem with IP address 72.123.36.19




    Checkadd.sh
    #!/bin/sh
    cd /opt/xampp/htdocs/test
    /opt/xampp/htdocs/test/checkadd.exp $1





    Checkadd.exp
    #!/usr/local/bin/expect
    #exp_internal 1

    set modemmacadd [lindex $argv 0]

    set ipadd1 66.153.111.111
    set ipadd2 66.153.222.222

    log_file -noappend "/opt/xampp/htdocs/test/log.txt"

    #66.153.111.111 MachineName#1##############
    spawn telnet $ipadd1
    expect "Username:"
    send "theusername\r"
    expect "Password:"
    send "thepassword\r"
    expect "MachineName#1#"
    send "show cable modem $modemmacadd verbose\r"
    expect "MachineName#1#"
    send "exit\r\n"

    #66.153.222.222 MachineName#2##############
    spawn telnet $ipadd2
    expect "Username:"
    send "theusername\r"
    expect "Password:"
    send "thepassword\r
    expect "MachineName#2#"
    send "show cable modem $modemmacadd verbose\r"
    expect "MachineName#2#"
    send "exit\r\n"



    error.log
    sh: spawn: not found
    sh: Trying: not found
    sh: Connected: not found
    sh: Escape: not found
    ...



    Contents of /opt/xampp/htdocs/test/log.txt
    Trying 66.153.111.111...
    Connected to 66.153.111.111.
    Escape character is '^]'.
    theusername
    thepassword
    show cable modem 72.123.36.19 verbose
    Trying 66.153.222.222...
    Connected to 66.153.222.222.
    Escape character is '^]'.
    theusername
    thepassword
    show cable modem 72.123.36.19 verbose
    Trying 66.153.333.333...

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    You have made multiple postings with the same question, effectively. Please don't do that. I answered in your other one. Thanks.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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