Find the answer to your Linux question:
Results 1 to 2 of 2
hi, i wrote an expect script that get commands from args, and executes these commands as root, i needed this script to execute commands that have space between them (i.e ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    10

    expect script , command not found


    hi,
    i wrote an expect script that get commands from args, and executes these commands as root, i needed this script to execute commands that have space between them (i.e apt-get install git), when i give these commands that have space, the script will have my command in separated args( thats because it splits my entries by space and gives the results to each of the args), so i decided to replace all of spaces in my command with "_" and send it to my script,and then in my script replace all of "_" with " ",then try to execute it, but when i do it i get "command not found",
    but when i alter my script so that it executes "apt-get install git" without getting it from args, it will execute my command correctly,what should i do?
    here is my script:

    #!/usr/bin/expect
    set pass [lindex $argv 0]
    set c [lindex $argv 1]
    set command [string map {_ { }} $c]
    spawn sudo $command
    expect "assword"
    send "$pass\r"
    expect eof

  2. #2
    Just Joined!
    Join Date
    Dec 2010
    Posts
    10
    heyy!!any body there?!!!
    my problem is that when i execute MyScript with the command : ./MyScript mypassword apt-get_install_git
    i get this error:
    "spawn sudo apt-get install git
    [sudo] password for gongotar:
    sudo: apt-get install git: command not found"

    and here is MyScript:

    #!/usr/bin/expect
    set pass [lindex $argv 0]
    set c [lindex $argv 1]
    set command [string map {_ { }} $c]
    spawn sudo $command
    expect "assword"
    send "$pass\r"
    expect eof

    but when i execute MySecondScript with the command : ./MySecondScript mypassword
    it will execute correctly with no errors,
    and here is MySecondScript:

    #!/usr/bin/expect
    set pass [lindex $argv 0]
    spawn sudo apt-get install git
    expect "assword"
    send "$pass\r"
    expect eof

    can anybody help me?!
    Last edited by gongotar; 09-18-2011 at 10:10 AM.

Posting Permissions

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