Operating System - HP-UX
1834462 Members
2974 Online
110067 Solutions
New Discussion

Re: Script to automate ftp of log file

 
Amit Dixit_2
Regular Advisor

Script to automate ftp of log file

HI,
Want to write a script so that it will
automatically FTP my server logs to my
workstation.

File name convention of my log files are
server20041220
i.e. serveryymmdd

Thanks,
Amit.
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: Script to automate ftp of log file

ftp -nv ${WORKSTATION} << FTPEOF > /tmp/temp_log.$$
user ${USERNAME} ${PASSWORD}
#Get file
get $1
quit
FTPEOF

change /tmp/temp_log.$$ to whatever logs you actually want transferred to your workstation.

Make the permission on this script very restrictive, because you are hard coding your workstation password in an unencrypted script, further you are transmitting your password in clear text across your network.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Masatake Hanayama
Trusted Contributor

Re: Script to automate ftp of log file

Amit,

Although I may not understand correctly what you want to do, this is an example.

#!/bin/sh
ftp -nv workstation << EOF
user uuu ppp
put server`date +%Y%m%d`
quit
EOF

Regards,
Nguyen Anh Tien
Honored Contributor

Re: Script to automate ftp of log file

#/!/sbin/sh
#change these parameter for your environment
host_ip=10.0.0.99
user_name=sysopr1
pass_word=dp8910
file_name="vg01"
dir=/tmp
GetDate=`date +"%Y%m%d"`
LOG_NM=/tmp/server$GetDate


# ftp gets file
ftp -nv $host_ip << EOF > $LOG_NM
user $user_name $pass_word
cd $dir
get $file_name
quit
EOF
HP is simple
Steven E. Protter
Exalted Contributor

Re: Script to automate ftp of log file

My answer requires a re-work

ftp -nv ${WORKSTATION} << FTPEOF > /tmp/temp_log.$$
user ${USERNAME} ${PASSWORD}
#put file
put $1
cd /var/logs
put server20041220
quit
FTPEOF

/tmp/temp_log.$$ logs the ftp transfer to a local disk on the source server. Thats a nice feature. Too bad I wasn't careful to get the guts of the script right the first time.

Everything I said about the authentication should be looked at with care.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com