How to store file name in a variable?

Hi All,

Daily I am generating a file dfm_daily_file_

ex: dfm_daily_file_05072015 date will be changed daily.

Once the file is FTP it is deleted.

I have tried the below code to get the file name with any date and store it in a variable its not working.

#!/bin/ksh 
filename="dfm_daily_file_*.dat"

echo "Sending File $filename by FTP"

ftp_file "RTM_SERVER"  "$filename" 

if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
fi

rm -f $SRDS_LA/$filename

fin_normale $0

Please help me how to get the file name into a variable.

Thanks in advance.

Please use code tags as required by forum rules!

The * within the quotes will not be expanded. Is there just one file? Try filename=dfm_daily_file_*.dat , then. If there's more than one single file, use sth. like find , but you'll need to specify the target date anyhow

You could also try a for loop.

Modifications to you setup:

#!/bin/ksh 

for filename in dfm_daily_file_*.dat
do

  echo "Sending File $filename by FTP"

  ftp_file "RTM_SERVER"  "$filename" 

  if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
  fi

  rm -f "$SRDS_LA/$filename"
done
fin_normale $0

It is just a suggestion for a couple of changes relative to your code. I do not know the validity of the rest of your code...

Hi,

Just only one file.

I forgot to mention one thing this file dfm_daily_file_.dat is not in the same diectory.
This file dfm_daily_file_
.dat in this directory $SRDS_LA.

file name and Directory name I am passing to ftp_file.

As per your suggestion I modified as

filename=dfm_daily_file_*.dat

echo "Sending File $filename by FTP"

ftp_file "RTM_SERVER"  "$filename" "$SRDS_LA"

if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
fi

rm -f $SRDS_LA/$filename

fin_normale $0

After executing this script the output is showing as

ficftp="dfm_daily_file_*.dat"
Sending File dfm_daily_file_*.dat by FTP

Is it taking the file?

Please help me.

Thanks.

Doesn't look like. What is "ficftp" and what is "filename"? Try assigning like filename=$SRDS_LA/dfm_daily_file_*.dat .