- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Pass variable to the ftp script
Operating System - HP-UX
1823985
Members
4099
Online
109667
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2002 09:31 AM
тАО11-12-2002 09:31 AM
Pass variable to the ftp script
I have the following ftp script and I want the mget or get to copy a different no. of files each time.
#vi ftpscript
#/!bin/ksh
ftp $remote_sys <
#vi ftpscript
#/!bin/ksh
ftp $remote_sys <
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2002 09:48 AM
тАО11-12-2002 09:48 AM
Re: Pass variable to the ftp script
I modified your script to look like this (example) :-
#!/bin/ksh
{ echo user skchan mypassword; echo mget $1; echo quit ; } |ftp -i -n $2
You would then run it like so ..
# for file in $(cat d)
> do
> ./ftpscript $file
> done
The $1 takes in the filename one at a time from the for loop and $2 is the system hostname that you're ftping to. The downside is of course you got to run ftp each time you want to retrieve a file which I suppose is what you wanted because you don't want to use pattern matching to retrieve multiple files in a single session.
#!/bin/ksh
{ echo user skchan mypassword; echo mget $1; echo quit ; } |ftp -i -n $2
You would then run it like so ..
# for file in $(cat d)
> do
> ./ftpscript $file
> done
The $1 takes in the filename one at a time from the for loop and $2 is the system hostname that you're ftping to. The downside is of course you got to run ftp each time you want to retrieve a file which I suppose is what you wanted because you don't want to use pattern matching to retrieve multiple files in a single session.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2002 09:53 AM
тАО11-12-2002 09:53 AM
Re: Pass variable to the ftp script
why not generate a script on the fly :
#!/bin/sh
echo 'ftp $remote_sys<> newscript
echo 'user $remote_user $remote_pass' >>newscript
cat listfile | while read filename
do
echo "get $filename" >>newscript
done
echo "bye" >>newscript
echo "EOP" >>newscript
=================================
newscript is the script to be executed and listfile is the file with the list of file to be trasnferred. This file is dynamic.
don't forget "chmod +x newscript"
Jean-Luc
PS : mind the single and double quote
#!/bin/sh
echo 'ftp $remote_sys<
echo 'user $remote_user $remote_pass' >>newscript
cat listfile | while read filename
do
echo "get $filename" >>newscript
done
echo "bye" >>newscript
echo "EOP" >>newscript
=================================
newscript is the script to be executed and listfile is the file with the list of file to be trasnferred. This file is dynamic.
don't forget "chmod +x newscript"
Jean-Luc
PS : mind the single and double quote
fiat lux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2002 08:49 AM
тАО11-13-2002 08:49 AM
Re: Pass variable to the ftp script
Below is script I use to get data. Using MGET can some time get to much stuff Trick I use, Is I first get a list of files on the system. parse the list and then get the "stuff" I need. Just a different way to look at the problem.
#!/bin/sh
#
# ftpget.sh
# Purpose: Retrieves files from a remote location
# VIA FTP. This file is usually called from
# a crontab entry.
#
# Written by: Rory Hammond
#
# I modifed this script by shortening it so that I can share the
# concepts The original had a little more error checking and then
# uploaded data into a database
#
# variables need to work
PATH=$PATH:/usr/bin
umask 0
GATEWAYPW="user proxyid proxpasswd"
REMOTEUPW="user userid passwd"
REMOTELOC="ftp.location.coml" #can also be IP Address
PUTDIR="/usr/spool/receive"
#
# Getlist lists ftp into site and list files available
# At this site I was only looking for TXT files hence the grep.
#
getlist()
{
( echo ${GATEWAYPW}
echo ${REMOTEUPW}
echo "ascii"
echo "nlist"
echo "quit"
) | ftp -n ${REMOTELOC} |grep TXT
}
#
# This gets the files gotten from the getlist.
#
getfile()
{
sleep 5
( echo ${GATEWAYPW} # do not need the first two lines if you don't have a
sleep 5 # a gateway user ID and password to get out
echo ${REMOTEUPW}
sleep 5
echo "binary"
echo "get $1 $1"
sleep 5
echo "quit"
) | ftp -n ${REMOTELOC}
}
#
# grep txt will get all file names ending with txt
# it would be faster to put this loop in the getfile
# script macro but I chose not to. After words
# you check the the line count of getlist and compare it
# with the number of files you did receive.
# As a variation you can change the script put files
# and use the getlist to enuser the the ftp worked.
#
for arg in `getlist`
do
cd ${PUTDIR}
getfile ${arg}
echo "`date` $0: --- getfile ---"
echo "$0:Getting ${arg} and putting it at" ${PUTDIR}/${arg}
echo "`date` $0: -----getfile----- transferring ${arg} copy to Mercator"
tranfile ${arg}
done
exit
#!/bin/sh
#
# ftpget.sh
# Purpose: Retrieves files from a remote location
# VIA FTP. This file is usually called from
# a crontab entry.
#
# Written by: Rory Hammond
#
# I modifed this script by shortening it so that I can share the
# concepts The original had a little more error checking and then
# uploaded data into a database
#
# variables need to work
PATH=$PATH:/usr/bin
umask 0
GATEWAYPW="user proxyid proxpasswd"
REMOTEUPW="user userid passwd"
REMOTELOC="ftp.location.coml" #can also be IP Address
PUTDIR="/usr/spool/receive"
#
# Getlist lists ftp into site and list files available
# At this site I was only looking for TXT files hence the grep.
#
getlist()
{
( echo ${GATEWAYPW}
echo ${REMOTEUPW}
echo "ascii"
echo "nlist"
echo "quit"
) | ftp -n ${REMOTELOC} |grep TXT
}
#
# This gets the files gotten from the getlist.
#
getfile()
{
sleep 5
( echo ${GATEWAYPW} # do not need the first two lines if you don't have a
sleep 5 # a gateway user ID and password to get out
echo ${REMOTEUPW}
sleep 5
echo "binary"
echo "get $1 $1"
sleep 5
echo "quit"
) | ftp -n ${REMOTELOC}
}
#
# grep txt will get all file names ending with txt
# it would be faster to put this loop in the getfile
# script macro but I chose not to. After words
# you check the the line count of getlist and compare it
# with the number of files you did receive.
# As a variation you can change the script put files
# and use the getlist to enuser the the ftp worked.
#
for arg in `getlist`
do
cd ${PUTDIR}
getfile ${arg}
echo "`date` $0: --- getfile ---"
echo "$0:Getting ${arg} and putting it at" ${PUTDIR}/${arg}
echo "`date` $0: -----getfile----- transferring ${arg} copy to Mercator"
tranfile ${arg}
done
exit
There are a 100 ways to do things and 97 of them are right
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP