How to use Expect in a Bash script

后端 未结 1 1536
感动是毒
感动是毒 2020-12-15 12:35

I am trying to write a script that pulls the latest version of my software from a Git repository and updates the configuration files. When pulling from the repository though

相关标签:
1条回答
  • 2020-12-15 12:57

    This is pretty much taken from the comments, with a few observations of my own. But nobody seems to want to provide a real answer to this, so here goes:

    Your problem is you have an Expect script and you're treating it like a Bash script. Expect doesn't know what cd, cp, and git mean. Bash does. You want a Bash script that makes a call to Expect. For example:

    #!/usr/bin/env bash
    
    password="$1"
    sourcedest="path/to/sourcedest"
    cd $sourcedest
    
    echo "Updating Source..."
    expect <<- DONE
      set timeout -1
    
      spawn git pull -f origin master
      match_max 100000
    
      # Look for password prompt
      expect "*?assword:*"
      # Send password aka $password
      send -- "$password\r"
      # Send blank line (\r) to make sure we get back to the GUI
      send -- "\r"
      expect eof
    DONE
    
    git checkout -f master
    cp Config/database.php.bak Config/database.php
    cp webroot/index.php.bak webroot/index.php
    cp webroot/js/config.js.bak webroot/js/config.js
    

    However, as larsks pointed out in the comments, you might be better off using SSH keys. Then you could get rid of the expect call altogether.

    0 讨论(0)
提交回复
热议问题