Olgun Kaya
Olgun Kaya

Reputation: 2589

Solaris shell scripting

I am writing a script to ftp some files using some rules. But I have problems with the scripts ftp session creation.

below is the shell script I am using right now.

#!/bin/bash
cd /var/ericsson/nin/charging/archive
date=`(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;')`
movedFile=`ls | grep $date`
HOST=xxxx
USER=xxxx
PASSWD=xxxxx
for i in $movedFile; 
do
    echo $date >> trial.txt
    echo "Uploading file $i" >> trial.txt
    ftp -n $HOST
    quote USER $USER
    quote PASS $PASSWD
    binary
    cd TEMP
    put $i
    quit
    END_SCRIPT
    echo "kk" 
done

the problem is. It is unable to trigger quote commands of ftp.

Upvotes: 1

Views: 3973

Answers (2)

Olgun Kaya
Olgun Kaya

Reputation: 2589

since it is unable to be seen in the comments. here is the correct answer worked my situation

cd xxxx 
date=(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60‌​);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;') 
movedFile=ls | grep $date 
HOST=xxxx 
USER=xxxx 
PASSWD=xxxx 
for i in $movedFile; 
do 
   echo $date >> xxxx.log 
   echo $i >> xxxx.log 
   ftp -n $HOST <<End-Of-Session user "$USER" "$PASSWD" 
   binary 
   cd TEMP 
   put $i 
   quit 
   End-Of-Session 
done

Upvotes: 0

Mat
Mat

Reputation: 206831

Check out bash Here Documents. The syntax you're looking for is:

  ftp -n $HOST <<END_SCRIPT
  quote USER $USER
  quote PASS $PASSWD
  binary
  cd TEMP
  put $i
  quit
END_SCRIPT

Upvotes: 3

Related Questions