how can I use shell variable inside ftp script as in below:-
the case as below:-
I have folder names as (Sunday,Monday...etc) and inside these folders I am trying to get files where their names are "mf_us[mv]m_ssnc[0-9]*_mo0'HOUR''MIN'[0134][05]".
where
HOUR= hour as in `date "+%H"` - 2
MIN= either 00,15,30,45
now the problem is how to get HOUR and MIN depending on the command date "+%[HM]" executed now, and then substitute MIN from the command after some calculations then put it in the code below to dynamically drag the files.
files are generated every 15 min and looked like below:
mf_us[mv]m_ssnc[0-9]*_mo01800
mf_us[mv]m_ssnc[0-9]*_mo01815
mf_us[mv]m_ssnc[0-9]*_mo01830
mf_us[mv]m_ssnc[0-9]*_mo01845
ftp -i -n <<EOF
open 192.168.xx.xxx
user user_name password
hash
prompt
bin
let "s=`date '+%H'` - 2" # doesn't work ???!!! :(:(
cd /home/dir/`date '+%A'`/Hour`date '+%H'` # working fine.:b:
lcd /home/dir/in local/
mget mf_us[mv]m_ssnc[0-9]*_mo0"$s"[0134][05] #doesn't work :(:(:(
bye
EOF
thanks in advance.
---------- Post updated at 21:07 ---------- Previous update was at 20:09 ----------
thanks guys I just figure it out.
cat ftp_run:-
if [[ `date '+%M'` -lt 15 ]]
then
sub="00"
elif [[ `date '+%M'` -ge 15 && `date '+%M'` -lt 30 ]]
then
sub="15"
elif [[ `date '+%M'` -ge 30 && `date '+%M'` -lt 45 ]]
then
sub="30"
elif [[ `date '+%M'` -ge 45 && `date '+%M'` -lt 60 ]]
then
sub="45"
else
echo "something wrong"
fi
cat << EOF
open 192.168.7.215
user user_name pass
hash
prompt
bin
cd /home/rdir/`date '+%A'`/Hour`date '+%H'`
lcd /dir
mget mf_us[mv]m_ssnc[0-9]*_mo0$(( `date '+%H'` - 2 ))$sub
bye
EOF
./ftp_run > ftp_script
then executing ftp script in cron job.