title: shell commands not working within SFTP script
body: <p>I am a novice in programming.. I have this sftp script where it sftp to the other server check some conditions &amp; then get the file.</p>
  
  <pre><code>#! /usr/bin/bash
  
  while read line
  do
  #echo $line
  if [[ $line =~ ^#  ]];
  then
  #echo $line;
  continue;
  
  else
  serverIP=`echo $line|cut -d',' -f1`
  userID=`echo $line|cut -d',' -f2`
  fi
  done &lt; sftp.conf
  
  cd /root
  
  sshpass -p red32hat sftp $userID@$serverIP &lt;&lt;EOF
  for (; ;) 
  do
  cd /root/perl
  #foreach my $file (&lt;$inputdir/*seq&gt;) {
  for $file in *seq 
  do
  abc1=`find $file -mmin +1`;
  if [[ $abc1 eq "" ]] 
  then
  echo "Skipping file as of now as file is not completed \n";
  continue;
  fi
  mget $file
  done
  sleep 30
  done
  bye
  EOF
  </code></pre>
  
  <p>but it is throwing error at every sftp step saying "invalid command".. I guess general shell commands are not working within sftp... please help...below is the error message...</p>
  
  <pre><code>eankuls@L9AHR43:~/Idea_Expan$ bash -x sftp_idea.sh
  + read line
  + [[ #bsackjsabckjdsbcds =~ ^# ]]
  + continue
  + read line
  + [[ rinacac-test,root =~ ^# ]]
  ++ echo rinacac-test,root
  ++ cut -d, -f1
  + serverIP=rinacac-test
  ++ echo rinacac-test,root
  ++ cut -d, -f2
  + userID=root
  + read line
  + [[ #geet =~ ^# ]]
  + continue
  + read line
  + sshpass -p red32hat sftp root@rinacac-test
  
      ------------------------------------------------------------------------------------
      These computer resources, specifically Internet access and E-mail, are
      provided for authorized users only. 
  
      IF YOU ARE NOT AN AUTHORIZED USER, PLEASE EXIT IMMEDIATELY.
      ------------------------------------------------------------------------------------
  Connected to rinacac-test.
  sftp&gt; for ((;;)) 
  Invalid command.
  sftp&gt; do
  Invalid command.
  sftp&gt; cd /root/perl
  sftp&gt; #foreach my $file (&lt;$inputdir/*seq&gt;) {
  sftp&gt; for file in *seq 
  Invalid command.
  sftp&gt; do
  Invalid command.
  sftp&gt; abc1=`find $file -mmin +1`;
  Invalid command.
  sftp&gt; if [[ $abc1 == "" ]]
  Invalid command.
  sftp&gt; then
  Invalid command.
  sftp&gt; echo "Skipping file as of now as file is not completed \n";
  Invalid command.
  sftp&gt; continue;
  Invalid command.
  sftp&gt; fi
  Invalid command.
  sftp&gt; mget $file
  Couldn't stat remote file: No such file or directory
  File "/root/perl/$file" not found.
  sftp&gt; done
  Invalid command.
  sftp&gt; sleep 30
  Invalid command.
  sftp&gt; done
  Invalid command.
  sftp&gt; bye
  </code></pre>