How to pass variable to ftp script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass variable to ftp script?
# 1  
Old 02-22-2010
How to pass variable to ftp script?

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:

Code:
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



Code:
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:-

Code:
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

Code:
./ftp_run > ftp_script

then executing ftp script in cron job.


Last edited by ahmad.diab; 02-22-2010 at 02:29 PM..
# 2  
Old 02-23-2010
Please explain it better ,


If you want to pass the variable value use command line arguments ,
If you want to use the shell variables in a cron then it is not possible , since cron has no
interface and you cannot get any shell variable values inside it,
I hope that you aware of giving values inside the cron by put the values in the next line.

I guess that you have some other problems too , dont mix up ask one by one there by we can avoid confusions
# 3  
Old 02-23-2010
who said that I will sub. the variable in cronjob? you miss understood

firstly I wrote a script (run file) that will build the ftp commands.
then I put this RUN file in the cronjob to be executed.

after the RUN finish executing the ftp file is ready.
I then will made the ftp_script file executable .

At last will made a cronjob to ftp_script file to execute the ftp commands.

Finish
Job Done.

by the way it works greatly.
SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass a VARIABLE to sqlplus script

Hi Team, I am trying to run a sqlplus script against several databases via a FOR/LOOP and also passing the loop variable to a sqlplus script I am calling, as follows: #!/bin/bash export ORACLE_SID=plgc1 export ORACLE_HOME=/opt/oracle/product/11.2.0.2/db_1 export... (1 Reply)
Discussion started by: jonnyd
1 Replies

2. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

3. Shell Programming and Scripting

How to pass variable to remote script?

Hi All, I am execuring the below script and want to pass one variable also to the remote server script to perform some logic in the script. ssh username@${HostName} "/home/Temp/Test/Test.sh I want to the pass the $HostName to the Test.sh script to perfrom some logic in it. (1 Reply)
Discussion started by: sharsour
1 Replies

4. UNIX for Dummies Questions & Answers

Script to ftp in to linux then pass reply

Hello, I have an ftp loop script which I was going to use to login to various Linux systems but as It's my first connection I'm being prompted to add it to the known_hosts. Can this script be modified to reply 'yes' before passing the user/pass ? usname="someuser" pass="somepass" while read... (1 Reply)
Discussion started by: Grueben
1 Replies

5. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

6. Shell Programming and Scripting

Pass a variable to SQL script

Hi Guys, I like to pass a variable to a sql file in a unix script.. I tried a below code.. var=200903 db2 -vf test.sql 200903 test.sql is as below. select * from db2.users where quarter = $1; Please tell me where i go wrong.. Thanks in advance, Magesh (2 Replies)
Discussion started by: mac4rfree
2 Replies

7. Shell Programming and Scripting

How to pass a Awk variable to another script

Read parameter from a text file with one line which stored the date value like 20080831; below is the awk command I used gawk -F, "{getline RunDate;print $RunDate" text file When print $RunDate, it display 20080831 Would like to pass this variable to another script to use but not... (6 Replies)
Discussion started by: cbauw
6 Replies

8. Shell Programming and Scripting

pass variable from awk to shell script

Hello Experts, Actually I was searching for a solution here in this forum , but didn't get what exactly I want . Is this possible to do in awk ? I am trying to do some thing like below in ksh script . Upto my knowledge I can pass shell script to awk with "-v " option. But I... (3 Replies)
Discussion started by: user_prady
3 Replies

9. Shell Programming and Scripting

Pass script variable value to AWK

HI all, some more mistery about AWK, I hope you can help me out: 1) I have a normal ksh script and sometime I call awk command. I set some variables in the script and I would like to use them up within AWK as well. Unfortunately AWK seems to forget all the variable values outside of its own... (1 Reply)
Discussion started by: BearCheese
1 Replies

10. UNIX for Dummies Questions & Answers

How to Pass variable to shell Script

Hi , i am beginner to Unix, I have one small script which execute java programme,it has java command input output structure . Right now i have given Input output structure manually that is on same directory, now how can i pass that by commandline #!/bin/sh java Classjava input.txt... (5 Replies)
Discussion started by: sam70
5 Replies
Login or Register to Ask a Question