Smithis
Smithis

Reputation: 55

FTP bash script

I would like to create a script that will upload a file until the upload uperation will successfull. The script will monitoring the log file. If "not connected" to the server i want to repeat the upload operation until "connected" and "file successfully transferred" Anyone can help me to build the correct one pls. What should i write after if egrep "not...?

 LOGFILE=/home/transfer_logs/$a.log
 First=$(egrep "Connected" $LOGFILE)
 Second=$(egrep "File successfully transferred" $LOGFILE)

  ftp -p -v -i 192.163.3.3 < ../../example.script > ../../$LOGFILE 2>&1

  if
  egrep "Not connected" $LOGFILE; then

  ftp -p -v -i 192.163.3.3 < ../../example.script > ../../$LOGFILE 2>&1

  until
  [[ -n "$first" ]] && [[ -n "$second" ]]; 
  done
  fi

example contains:

  binary
  mput a.txt
  quit 

Upvotes: 0

Views: 650

Answers (1)

William Pursell
William Pursell

Reputation: 212684

while :; do
    ftp ... > $LOGFILE
    grep -qF Connected $LOGFILE && 
    grep -qF "File successfully transferred" $LOGFILE && break
done

Upvotes: 1

Related Questions