title: Bash script upload files to another server from php returns 0 bytes file
body: <p>I have a PHP script that executes a shell script which makes a .tar.gz2 and then starts an expect script that uploads the .tar.gz2 on another server, then it starts another expect script that connect on the other server via ssh and unpack the .tar.bz2.</p>
  
  <p>My problem is when I start the script from a webbrowser via the php script I receive a 0 byte .tar.gz2. But when I start it from the command line then it works just fine.</p>
  
  <p><strong>The PHP script:</strong></p>
  
  <pre><code>$exe = "./umzug_daten.sh ".$ip." ".$ssh_user." ".$ssh_pass." ".$sftp_user." ".$sftp_pass." ".$daten_path." ".$this_path."/html";
  exec($exe);//script für den umzug ausführen
  echo($exe);
  </code></pre>
  
  <p><strong>The shell script:</strong></p>
  
  <pre><code>#!/bin/bash
  ziel_ip=$1
  ssh_user=$2
  ssh_pass=$3
  sftp_user=$4
  sftp_pass=$5
  path=$6
  this_path=$7
  my_path=`pwd`
  
  cd $this_path
  #tar cfvj $my_path/mk.tar.bz2 *
  cd $my_path
  
  echo ./sftp1.sh $ziel_ip $sftp_user $sftp_pass $path $this_path
  ./sftp1.sh $ziel_ip $sftp_user $sftp_pass $path $this_path
  
  echo "Daten entpacken"
  ./ssh1_daten.sh $ziel_ip $ssh_user $ssh_pass $path #alles entpacken
  </code></pre>
  
  <p><strong>The sftp expect script:</strong></p>
  
  <pre><code>#!/usr/bin/expect
  set sftp_ip [lindex $argv 0]
  set sftp_user [lindex $argv 1]
  set sftp_pass [lindex $argv 2]
  set sftp_path [lindex $argv 3]
  set sftp_this_path [lindex $argv 4]
  spawn /usr/bin/sftp $sftp_user\@$sftp_ip
  expect "Are you sure you want to continue connecting (yes/no)?";
  send "yes\n";
  expect "password:"
  send "$sftp_pass\n"
  expect "sftp&gt;"
  send "cd $sftp_path\n"
  expect "sftp&gt;"
  send "put mk.tar.bz2\n"
  #expect "\n"   #This was a problem
  expect "sftp&gt;" 
  send "exit\n"
  interact
  </code></pre>
  
  <p>What is the problem here, am I doing anything wrong?</p>
  
  <p><strong><h1>EDIT!</h1></strong></p>
  
  <p><strong>Ok I have found the problem in the expect script at line 16</strong></p>
  
  <p>But now I have a new problem:
  When I start the script from the web browser it uploads a part from the tar.bz2 and then just stops the upload and starts unpacking the .tar.bz2 file.</p>
  
  <p><strong>The ssh expect script:</strong></p>
  
  <pre><code>#!/usr/bin/expect
  set ssh_ip [lindex $argv 0]
  set ssh_user [lindex $argv 1]
  set ssh_pass [lindex $argv 2]
  set path [lindex $argv 3]
  spawn /usr/bin/ssh $ssh_user@$ssh_ip
  expect "Are you sure you want to continue connecting (yes/no)?";
  send "yes\n";
  expect "*password:"
  send "$ssh_pass\n"
  expect "*:*#"
  send "cd $path\n" 
  expect "*:*#"
  send "tar xfvj mk.tar.bz2\n"
  expect "*:*#"
  send "exit\n"
  interact
  </code></pre>