UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 28th, 2004, 06:04 PM
viswapsp viswapsp is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 viswapsp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question ftp in ksh program

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)

Reply With Quote
  #2  
Old September 29th, 2004, 04:02 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
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:
2004/09/27 06:00:00 Started ftp_to_sun.ksh log=no

2004/09/27 06:00:00 Change to /app/explorer

2004/09/27 06:00:00 Files to be ftp'd are:
-rw-r--r-- 1 nobody other 1407926 Sep 26 01:07 explorer.830ae7f1.dssdbdoc01-2004.09.26.00.00.tar.gz
-rw-r--r-- 1 nobody other 1279920 Sep 26 01:13 explorer.83107f21.dssremus2-2004.09.26.00.10.tar.gz

2004/09/27 06:00:00 Putting file explorer.830ae7f1.dssdbdoc01-2004.09.26.00.00.tar.gz
-rw-r--r-- 1 nobody other 1407926 Sep 26 01:07 explorer.830ae7f1.dssdbdoc01-2004.09.26.00.00.tar.gz
Hash mark printing on (8192 bytes/hash mark).
Interactive mode off.
######################################################################################
-rw------- 1 other 1407926 Sep 27 04:47 explorer.830ae7f1.dssdbdoc01-2004.09.26.00.00.tar.gz
#

2004/09/27 06:00:25 Putting file explorer.83107f21.dssremus2-2004.09.26.00.10.tar.gz
-rw-r--r-- 1 nobody other 1279920 Sep 26 01:13 explorer.83107f21.dssremus2-2004.09.26.00.10.tar.gz
Hash mark printing on (8192 bytes/hash mark).
Interactive mode off.
###############################################################################
-rw------- 1 other 1279920 Sep 27 04:48 explorer.83107f21.dssremus2-2004.09.26.00.10.tar.gz
#

2004/09/27 06:05:12 Finished ftp_to_sun.ksh log=no

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > ftp in ksh program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway