scp script with MD5

I have more than one file in my directory & I want to SCP them all with MD5 verification of local & remote file, Problem is that the script gets stop after scp one file. Below is the code.

#!/usr/bin/bash
cd /application/datafolder/my/
ls > my_file_list.txt
while read fname
do
   VAR_LOCALMD5=`csum -h MD5 /application/datafolder/my/${fname}|awk '{print $1}'`
    scp ${fname} 10.xxx.xxx.xxx:/application/datafolder/my/
    VAR_REMOTEMD5=`ssh 10.xxx.xxx.xxx csum -h MD5 /application/datafolder/my/${fname}|awk '{print $1}'`
     if [[ $VAR_LOCALMD5 == $VAR_REMOTEMD5 ]]
    then
    rm /application/datafolder/my/$fname
    echo "LOCAL MD5:  $VAR_LOCALMD5"
    echo "REMOTE MD5:  $VAR_REMOTEMD5"
    else
    echo "Error Occured in SCP files"
    echo
    echo "LOCAL MD5:  $VAR_LOCALMD5"
    echo "REMOTE MD5:  $VAR_REMOTEMD5"
    fi
    ssh 10.xxx.xxx.xxx rm /application/datafolder/my/my_file_list.txt
done < my_file_list.txt

Any help would be highly appreciated.

Start by using ls -1 > my_file_list.txt ...

its not working...please suggest

ls -ltr | awk '{ print $9}' >> filelist

@ m_raheelahmed which OS uname -a

@zozoo >> appends standard output to file and just ls -1 is enough

1 Like

AIX 6.1

post this

which ls and echo $PATH I suspect path must be broken

here it is ls & $PATH

/usr/bin/ls

/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/ahd11542/bin:/usr/bin/X11:/sbin:.