Operating System - HP-UX
1827741 Members
3091 Online
109969 Solutions
New Discussion

Re: Compress a file before ftp

 
MacMcDonald
Advisor

Compress a file before ftp

Hi,

I have a script that ftp's to over 100 deifferent servers in turn, gets a specific file, renames it and drops it onto a local backup server. The files vary in size from 4mb to 150mb. I am within a secure intranet to security with ftp is not an issue. I want to auto compress the file before I ftp it over the network, either as a seperate script or as a command contained within my original.

Can anyone help?

the current script is as follows:


hostFile=/data01/global_backup/scripts/GLOBAL_hostFile.txt
while read ip sd
do
echo "connecting to $sd on $ip"
ftp -dv $ip <get /global/prd/cycle/export/full_export.dmp /data01/global_backup/files/monday/$sd.full_export.dmp
bye
EOF
if [ $? -ne 0 ]; then
echo "Had a problem connecting to $sd on $ip"
else
echo "Connected to $sd on $ip"
fi
done < ${hostFile}
16 REPLIES 16
Coolmar
Esteemed Contributor

Re: Compress a file before ftp

MacMcDonald
Advisor

Re: Compress a file before ftp

thanks for the reply, my problem is that I have more than 80 servers to connect to in turn. I have edited the .netrc file to contain the user password details to enable autologin. This only seems to work with ftp, is there anyway I can include a telnet session in the script to compress the file in the same script prior to the ftp transfer?
Christian Tremblay
Trusted Contributor

Re: Compress a file before ftp

echo "connecting to $sd on $ip"
remsh gzip

add .gz extension to your ftp get in your script
MacMcDonald
Advisor

Re: Compress a file before ftp

for some reason when I add the line:

remsh gzip {filename}

it does not connect using that command, it seems to pass it by and run the get command direct, falling over because the .gz file is not there yet.
OldSchool
Honored Contributor

Re: Compress a file before ftp

appears to be a small typo in Christian's reply. try:

remsh $sd gzip

needs to know server to run command on
OldSchool
Honored Contributor

Re: Compress a file before ftp

or it might be $ip (if $sd isn't the dns name)
Christian Tremblay
Trusted Contributor

Re: Compress a file before ftp

not a typo, i avoid putting actual working commands because a lot of people rely on this forum to do their job for them.

I put just enough for a knowledgable user to figure it out.
MacMcDonald
Advisor

Re: Compress a file before ftp

again thanks for the reply guys - i already tried both the $sd and $ip before asking, it seems that the redhat box I am running the script from doesn't understand the remsh command.....
Christian Tremblay
Trusted Contributor

Re: Compress a file before ftp

You can substitute ssh to remsh ( which is a lot better and secure ) but you would have to deploy you ssh keys to all your servers to enable passwordless remote execution.
Which is a good thing to do if you have not already done so.

man ssh

Chris
Christian Tremblay
Trusted Contributor

Re: Compress a file before ftp

PS: I'm not sure, but I think in redhat remsh is called rsh

You may try that....
MacMcDonald
Advisor

Re: Compress a file before ftp

got the rsh part - but for some reason it falls over on the login, doesnt want to use the details included in the .netrc.
Christian Tremblay
Trusted Contributor

Re: Compress a file before ftp

I don't have access to a Redhat box to check the rsh use of .netrc, try man rsh on your Redhat box for more info.

You really should try to implement ssh in your environment. .netrc files are considered a security risk and will not survive a SOX audit. In fact their use is prohibited at most security conscious sites.
Peter Nikitka
Honored Contributor

Re: Compress a file before ftp

Hi,

.netrc is used for ftp only - rsh uses a .rhosts or /etc/hosts.equiv file on the remote host to check for logins without the need of an interactive login.

Even for ssh connections (which I recommend) you will have to add data to all involved clients you want to connect to.
If you setup sftp, you could reuse your script(s) nearly unchanged.

mfG Peter

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
MacMcDonald
Advisor

Re: Compress a file before ftp

it seems that rexec uses the .netrc file as well, could i use that to initiate the gzip command?
Volker Borowski
Honored Contributor

Re: Compress a file before ftp

Hi,

you could set up your ftp server to allow the execution of some commands, i.E. compression via script or likewise.

Get manpage of ftp and dig into the
"site exec"
section

i.E. here: http://docs.hp.com/en/B2355-60105/ftpd.1M.html

Watch it, there are scurity issues with this setup !

Volker
Arturo Galbiati
Esteemed Contributor

Re: Compress a file before ftp

Hi Mac,
you can use the rexec command:
rexec host [-l username] [-n] command

HTH,
Art