1834499 Members
2857 Online
110068 Solutions
New Discussion

Re: remote copy.

 
SOLVED
Go to solution
joe_91
Super Advisor

remote copy.

Hi Team:

This is a strange requirement and i am not sure there is a workaround? I need to copy a file from hostA to hostB on a regular basis(probably a cron job). But i should not do the following..
1. No rcp
2. No ftp as it would require a password.
3. The cron job even if run should not be run as root.

Any ideas folks, Please help me here,

Thanks & Regards
Joe.
18 REPLIES 18
Arockia Jegan
Trusted Contributor

Re: remote copy.

Here are some ways to do that,

1) using NFS and run copy(through cronjob)
as a non-root user
(2) Using CIFS/9000 and run copy(through cronjob) as a non-root user
3) using scp
joe_91
Super Advisor

Re: remote copy.

Hi:

Thanks for the quick reply, but scp would require a password is it not? The whole thing needs to be coded so that the cron would copy files as and when it finds new copy. we are running 11.0. Any ideas?

Thanks
Joe.
Mark Fenton
Esteemed Contributor

Re: remote copy.

Joe,

scp wouldn't require a password, if you use public key authentication with an unencrypted key (note -- this has potential, serious security implications if someone other than the owner of the key can read it).

Exact procedure depends on which implimentation of ssh you are using, but the command to feed cron would be the same:
scp user@hostb filename.on.hosta

hth

Mark
A. Clay Stephenson
Acclaimed Contributor

Re: remote copy.

Okay, given all of these restrictions, I would make a Perl client/server pair that would communicate over a dedicated port via sockets. The idea is that your cron job would fire off the Perl client. It would query the Perl server piece and ask "Have you got any new files for me?". If yes, then start sending otherwise exit.

This would be a fairly straightforward bit of Perl.

Plan B:

If you were to allow anonymous ftp then you can do this very easily using the Perl Net::FTP module.

Plan C: A C version of Plan A; Perl's easier and just about as fast.

The Perl options are also platform independent and could even work in a Windows/UNIX environment without changes.



Food for thought, Clay
If it ain't broke, I can fix that.
kish_1
Valued Contributor

Re: remote copy.

I am not sure rsync will do your job it is bascially used for updating files from remote server, as your issue also simillar .
think about it.
http://rsync.samba.org/README.html
share the power of the knowledge
Frank Slootweg
Honored Contributor

Re: remote copy.

If 'they' are worried about the security of the receiving side, then let the receiving side rcp the files from the source. I.e. there would be a .rhosts file on the source, but not on the target/receiving_side.

Other idea: Mail the file (if needed to a non-human 'user') and let the receiving side handle it, either (partially) 'manually', or fully automatic via .forward (and procmail if needed).
joe_91
Super Advisor

Re: remote copy.

Hi:

Thanks. I am Impressed with Clay's solution but not sure how to execute it. I have no knowledge of rsync(but is it not another "r" commands that puts off the security guys). About mailing idea, how would you set it up for a non-human user with a .forward??
You help would be appreciated.

Thanks
Joe.
Sanjay_6
Honored Contributor

Re: remote copy.

Hi Joe,

Have you checked the "rdist" command. I think it serves some purpose like that, but have not really used it myself, so i'm not sure.

Hope this helps.

Regds
joe_91
Super Advisor

Re: remote copy.

Hi Sanjay:

Thanks. So doesn't it require a password?

Joe.
Frank Slootweg
Honored Contributor

Re: remote copy.

> About mailing idea, how would you set it up for a non-human user with a .forward??

I normally use procmail in .forward, but I think you can just put this in .forward (*including* the outer quotes):

"|IFS=' '&&exec /path/to/your/script"

[The space between the single quotes is just that, a space, i.e. not a tab.]

The script can read the mail from its standard input and can do anything it likes with it.

Note: You may have to tweak the sendmail configuration to allow executables in .forward files. I will leave that part to others, because, for mail, I am a user. not an admin.]

Note 2: Instead of .forward you can set up an alias (see aliases(5M)) for the non-human user. I will leave that part also to others, for the same reason.
joe_91
Super Advisor

Re: remote copy.

Hi Frank:

Can you explain

"|IFS=' '&&exec /path/to/your/script"
and what is procmail?? is it on by default?

Thanks
Joe.
Sanjay_6
Honored Contributor

Re: remote copy.

Hi Joe,

My understanding in using rdist is that it works in the same manner as rcp, does not need a passowrd but does need a $HOME/.rhosts configured or /etc/hosts.equiv configured. Here is a link which could be of some help.

http://support2.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=500000000092407

Hope this helps.

Regds
Frank Slootweg
Honored Contributor

Re: remote copy.

Don't worry about the details of what is in the .forward file. The only important part is "/path/to/your/script", which is the path and file name of your script which handles the incoming mail.

procmail, 'process mail', is a program which can handle incoming mail. It has a commandfile, .procmailrc, which contains 'recipes' which tell procmail what to do with each type of mail, subject, address, etc., etc.. It can do quite a lot, but is probably not needed in your case. procmail is not included in HP-UX, but is freely available.

joe_91
Super Advisor

Re: remote copy.

Hi:

Well rdist.. if it has to use rhosts file then we may use rcp. Any advantages of rdist over rcp??

Thanks
Joe.
Dave La Mar
Honored Contributor

Re: remote copy.

Joe -
There are a host of good ideas in this thread.
I guess it is a matter of preference.
In our shop that seems to be ftp.
We have countless automated ftp scripts that put and get files.
No intervention, secure passwords, error checking with automated emails on failures, etc., etc.

Go for whatever your shop is comfortable with.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
joe_91
Super Advisor

Re: remote copy.

Hi Dave:

Are you using ftp with .netrc. Can you send me the procedure if possible.

Thanks
Joe.
John Dvorchak
Honored Contributor

Re: remote copy.

Have you thought about using lp to send the file? You can set up a printer on the receiving station that prints to a file. Then from the sending station lpr to the receiving station. No security involved, no user ID's or anything. Just a thought.
If it has wheels or a skirt, you can't afford it.
Dave La Mar
Honored Contributor
Solution

Re: remote copy.

Joe -
sample .netrc file to be in the root directory of the user:

# 05/25/01 dlamar Created for automated ftp
machine minga login wxyz password abcdef

*********************************
In the above wxyz is the login name on the remote machine and abcdef is the password. Make the permissions on your .netrc readable by only users/groups you desire.

Sample ftp script:

# 07/24/01 dlamar Created for unix to vse ftp
ftp -v esa2 << endl >> /home/dlamar/work/ftp.log
prompt
ascii
put /home/dlamar/work/testunix
quit
endl
tail -14 /home/dlamar/work/ftp.log | mailx -s "FTP listing results" someone@companyname.com

***************************************
In the above, following the prompt line you can insert any cd command you need.
The log file created can be scannned for errors and email sent as desired.
i.e.
grep 'Not connected' $FTP_LOG 1>/dev/null 2>/dev/null
echo $? | read RC
grep 'full' $FTP_LOG 1>/dev/null 2>/dev/null
echo $? | read RC1
grep 'fail' $FTP_LOG 1>/dev/null 2>/dev/null
echo $? | read RC2
echo "The RC value is $RC" > $SCRIPT_HOME/messages
echo "The RC1 value is $RC1" >> $SCRIPT_HOME/messages
echo "The RC2 value is $RC2" >> $SCRIPT_HOME/messages

if [ $RC -lt 1 -o $RC1 -lt 1 -o $RC2 -lt 1 ]
then
tail -5 $FTP_LOG > $SCRIPT_HOME/messages
mailx -s "FTP failed for $SCRIPT_HOME" someone@companyname.com < $FTP_LOG
exit
else

fi


Like I said, you can manipulate the script as desired and schedule in cron or call from another script, etc., etc.
Used extensively in our shop both internally and to outside sources/vendors servers.

Best of luck.

dl
"I'm not dumb. I just have a command of thoroughly useless information."