|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I would like to send a bunch of files to a different machine on a regular basis. I need some help in creating the file. I have created 2 files main.ksh and ftp.par (All names are dummy names for understanding purposes)
contents of main.ksh -------- ftp -nv < ftp.par > ftp.log contents of ftp.par ------- open destination.server.com quote user destuserID quote pass destpasswd mput /local/directory/file1 /dest/directory/file1 This is working. How ever here are the enhancements I need to do. 1. I want to move a bunch of files not just a single file. All of them start with xyz And then any other characters and followed by CURRENTDATE (varies every day) in the format YYYYMMDD. Examples xyzAAA.20040928 xyzBBB.20040928 xyzCCC.20040928 xyzDDDDDD.20040928 and on.. 2. Also, I do not want to specify the destination directory. It should go to the target users home directory. Any help is highly appreciated. -viswa (viswapsp@hotmail.com) |
|
#2
|
|||
|
|||
|
Hi viswapsp,
I think if you change directory to your local directory and then just do "put filename" it will be dropped into the home directory of the user on the remote node. I'd probably have a function in the script to create the ftp.par file each time: Code:
mk_ftp_script()
{
echo open destination.server.com
echo quote user destuserID
echo quote pass destpasswd
echo hash
}
and use it thus: Code:
mk_ftp_script > /var/tmp/ftp.par You can then append commands to end of this par file. e.g. Code:
CURRDATE=`date +%Y%m%d`
for FILE in `ls xyz*.${CURRDATE}`
do
echo put ${FILE} >> ftp.par
echo dir ${FILE} >> ftp.par
done
One of my scripts and logfiles attached for your information. Hope this helps. Andy Code:
#!/usr/bin/ksh
#----------------------------------------------------------------------------------------------
usage()
#----------------------------------------------------------------------------------------------
{
cat <<END
Filename : ftp_to_sun.ksh
Version : 1.0
Summary : FTP Sun Explorer output to Sun
Parameters : Mandatory
: none
: Optional:
: log=<yes|no> (defaults to yes)
: run=<yes|no> (defaults to yes)
Calls : No other scripts
Date Author Version
29-Jun-04 ASBlack 1.0 Initial version
END
}
#------------------------------------------------------------------------------------
datemsg()
#------------------------------------------------------------------------------------
{
MSG=${@:-""}
echo
date +"%Y/%m/%d %H:%M:%S ${MSG}"
}
#------------------------------------------------------------------------------------
put_file()
#------------------------------------------------------------------------------------
{
#-- Note that YOUREMAIL is your work email address
ftp -n sunsolve.sun.co.uk <<END_OF_FTP
user anonymous ${YOUREMAIL}
binary
hash
prompt
cd bin
cd cores
cd uk
cd incoming
put ${FILE}
dir ${FILE}
bye
END_OF_FTP
}
#------------------------------------------------------------------------------------
# MAIN PROGRAM STARTS HERE
#------------------------------------------------------------------------------------
#-- Display usage if requested
if [[ ${1} = "help" ]]; then usage; exit 0; fi
#-- Set variables
PRG=`basename $0`
PARAMETERS=$@
DATETIME=`date +"%Y%m%d.%H%M%S"`
TMP=/var/tmp/${PRG}.$$
YOUREMAIL=someone@somecompany.com
#-- Read command line parameters
eval $@
log=${log:-yes}
#-- Set LOGFILE variable
LOGFILE=/app/explorer/${PRG}.log
#-- Send output to logfile if log=yes
if [[ "${log}" = "yes" ]]; then
echo "Sending output to logfile ${LOGFILE}"
exec 1>${LOGFILE} 2>&1
fi
#-- Echo start time
datemsg "Started ${PRG} ${PARAMETERS}"
#-- Saving the current directory so that we can move back to it later
DIR=`pwd`
#-- Change to the /app/explorer directory
datemsg Change to /app/explorer
cd /app/explorer
#-- List files to be ftp'd
datemsg "Files to be ftp'd are:"
ls -lrt explorer*gz |tee ${TMP}.files
#-- Put files
for FILE in `awk '{print $9}' ${TMP}.files`
do
datemsg Putting file ${FILE}
ls -l ${FILE}
put_file
done
#-- Change back to the previous directory
cd ${DIR}
#-- Echo finish time
datemsg "Finished ${PRG} ${PARAMETERS}"
##-- Send email
#mailx -s "${PRG} ${PARAMETERS}" root <<+++END+++
#`cat ${LOGFILE}`
#+++END+++
#-- Tidy up
rm ${TMP}.*
#------------------------------------------------------------------------------------
Output: Quote:
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > ftp in ksh program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|