ISSUE on SFTP fucntion ,parameter passing!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ISSUE on SFTP fucntion ,parameter passing!
# 1  
Old 10-23-2009
Bug ISSUE on SFTP fucntion ,parameter passing!

Hi Everyone!!

Hey i created a SFTP function to FTP the file from unix to Linux.

I need to FTP the 48 files from unix to linux.

Code:
IP=$1
Userid=$2
Prikeypath=$3
SrcPath=$4
DstPath=$5
Files=$6
BATCHFILE=sftp.batch.$$
LOGFILE=sftp.log.$$
#Compose batch file & pass as argument to the scipt.

if [ ${SrcPath} != "D" ]
then
echo "lcd $SrcPath" >> ${BATCHFILE}
fi

if [ $DstPath != "D" ]
then
echo "cd $DstPath" >> ${BATCHFILE}
fi

NoofFiles=`echo $Files | grep -c ,`
NoofFiles=`expr ${NoofFiles} + 1`

if [ $NoofFiles -gt 0 ]
then
while [ $NoofFiles -gt 0 ]
do
File=`echo $Files | cut -d"," -f${NoofFiles}`
echo "put $File" >> ${BATCHFILE}
NoofFiles=`expr $NoofFiles - 1`
done
fi

echo "bye" >> ${BATCHFILE}

if [ $Prikeypath != "D" ]
then
sftp -oIdentityFile=${Prikeypath} -oPubkeyAuthentication=yes -oPasswordAuthentication=no -b ${BATCHFILE} ${Userid}@${IP}
 > ${LOGFILE} >> ${LOGFILE} 2>&1
else
sftp -oPubkeyAuthentication=yes -oPasswordAuthentication=no -b ${BATCHFILE} ${Userid}@${IP} > ${LOGFILE} >> ${LOGFILE} 2
>&1
fi


if [ $? -ne 0 ]
then
echo "SFTP session failed. Please refer ${LOGFILE} for further details"
else
echo "SFTP session succeeded."
#rm -f ${LOGFILE}
#rm -f ${BATCHFILE}
fi

fi
}

This is the fucntion.

The issue is
Code:
dosftp <ipadresss)  <User_Name> <Private_Keypath> <Source_Path> <Destination_Path> Abc*.txt,Bcd*.eof,xyz*.eof,crw*.txt

If i excute the fucntion like this,from the source path it's FTP ing only the first 2 files(Abc*.txt,Bcd*.eof)
but i need to ftp all the files(Abc*.txt,Bcd*.eof,xyz*.eof,crw*.txt) ,How i can modify my function to SFTP the n number of parameters in a single execution.

Please advice.

Thanks in Advance.

Last edited by zaxxon; 10-23-2009 at 08:36 AM.. Reason: code tags!
# 2  
Old 10-23-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing parameter more than 9

Hi, I've written a script where eleven parameter to be passed from command line which is inserting into an oracle table, it is working but the tenth and 11th parameter are not accepting as given it is referring to 1st parameter. HERE IS THE SCRIPT #!/bin/ksh #set -o echo $*... (4 Replies)
Discussion started by: sankar
4 Replies

2. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

3. Shell Programming and Scripting

Issue in passing a parameter value from one script to another

Hi Experts, I am passing current month & day (i.e. 'Jul 21') from script aaa.ksh to zzz.ksh. The value 'Mon DD' is being used in zzz.ksh. Problem: If I pass 'Mon DD' value manually to zzz.ksh i.e. /test/zzz.ksh 'Jul 21' it works fine. However, if I pass value from aaa.ksh, it does... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

4. Shell Programming and Scripting

Positional parameter passing

Hi All, When passing parameters to a sheel script, the parameters are referenced by their positions such as $1 for first parameter, $2 for second parameter. these positional values can only have values ranging from $0-$9 (0,1,2,3...9). I have a shell script meant to accept 20 parameters. for... (3 Replies)
Discussion started by: ogologoma
3 Replies

5. Shell Programming and Scripting

Passing parameter in quotes

Hi, PW='/as sysdba'; export PW in other module I call sqlplus ${PW} (this line I unable to change!) How I can define PW so that sqlplus calls PW in quotes i.e sqlplus '/as sysdba' I tried like this PW="'/as sysdba'"; export PW - no luck Thanks in advance (2 Replies)
Discussion started by: zam
2 Replies

6. Shell Programming and Scripting

Parameter Passing problem

Hi All, I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths. In the script i am validating the number of paramaters it received as below #-------------------------------------- # Check Command line arguments... (8 Replies)
Discussion started by: Raamc
8 Replies

7. Programming

Sleep or Dealy fucntion Issue

I am doing some programming using C on UNIX. The thing is, I have been working in both UNIX and Windows for practicing. I created a Delay fucntion over Windows using DevC++ as a compiler, when I tried over the console, it worked as I expected, I mean it was creating a delay (of one second for... (10 Replies)
Discussion started by: josejesus3340
10 Replies

8. Shell Programming and Scripting

wrong parameter passing!

Hi all I have a script which will take input as filename and passes it to a java program. It is as follows -------------------------------- FILENAME=$1 echo $FILENAME ${JAVA_HOME}/bin/java -cp DateProvider $FILENAME ------------------------------------------------- when I execute the same... (2 Replies)
Discussion started by: malle
2 Replies

9. Programming

Passing parameter to makefile?

Hi, How to pass parameter to makefile? Please let me know if any one knows and also please put an example of makefile with this feature. thanks, Manju. (3 Replies)
Discussion started by: manju_p
3 Replies

10. Shell Programming and Scripting

parameter passing

Hallo everyone, This is my problem below: /home/cerebrus/pax=>vat class2.sh ksh: vat: not found /home/cerebrus/pax=>cat class2.sh #!/bin/ksh set -x bdf|grep appsdev|awk '{ print $5 }'> class3 dd={cat class3} echo $dd /home/cerebrus/pax=> /home/cerebrus/pax=>./class2.sh + bdf +... (8 Replies)
Discussion started by: kekanap
8 Replies
Login or Register to Ask a Question