Operating System - HP-UX
1834142 Members
2246 Online
110064 Solutions
New Discussion

script to copy user files.

 
SOLVED
Go to solution
david_252
Frequent Advisor

script to copy user files.

Hi:

We have 800 users on our nclass box running 11.0 and they create core files in their home directories say /home/$USER/core. They also create a core when we kill some process with a -6 signal(orphan process) we have a requirement to rcp this core files to a remote box. How do i go about doing this each and every time as we have at least 15 core files a day. Any ideas..

Thanks
David.
10 REPLIES 10
Stefan Farrelly
Honored Contributor

Re: script to copy user files.

How about nfs mount the remote server to your local server, and in each users home dir create a symbolic link for core to point to the nfs mounted dir of the remote server - this way no need to rcp, all core files automatically created on the remote servers filesystem ?

eg. cd $HOME
ln -s /core core

or what we do is ln -s /dev/null core so no more core files!
Im from Palmerston North, New Zealand, but somehow ended up in London...
david_252
Frequent Advisor

Re: script to copy user files.

Hi Stephan:

Thanks.

Good idea but i guess we are not suppose to use NFS.

Thanks
David.
John Palmer
Honored Contributor

Re: script to copy user files.

A conventional approach would be to write a script which combines 'find' and 'rcp' to locate and copy the core files to the remote server. Then use 'cron' to run the script on a regular basis.

If you do a lot of kill -6's then you could script this also and follow the kill with an rcp of the resulting core file.

As ever in UNIX, there are many ways to skin the proverbial cat.

Regards,
John
Rodney Hills
Honored Contributor

Re: script to copy user files.

David,

If your requirement is to use "rcp", then you have the how part of your answer.

If your question is about how to schedule this task as per the statement "doing this each and every time", then you would set up a crontab entry (see man crontab) to run the task as needed. Either once at the end of the day or every 2 hours.

HTH

-- Rod Hills
There be dragons...
S.K. Chan
Honored Contributor

Re: script to copy user files.

sorry ..
# find /home -name core -exec rcp {} mars:/tmp \;
S.K. Chan
Honored Contributor

Re: script to copy user files.

Something as simple as this may work for you. Copying all found "core" files to remote server "mars" and put all of them in /tmp.
# find /home -name core -exec rcp {} /tmp \;
Let this run from cron on a daily basis. It seems odd why would you want to keep core files unless the crash is important enough for you to analyze it. Here we just blow 'em away from cron once a week.
david_252
Frequent Advisor

Re: script to copy user files.

Thanks everyone.

we may have more than 3 files for a particular user the same day. After copying the files the core files should be deleted(since we have to be ready to copy the next one) What would be a good idea to go that way. Also since we also generate some cores using kill -6 is it possible to differentiate those cores(kill -6) from the other cores. All cores however would land up in the home directory.

Thanks
David.
John Palmer
Honored Contributor

Re: script to copy user files.

As I stated earlier, you could write a script that does the following:
- works out the username
- kills the process
- waits for the core file to be written
- moves the core file to your remote server

Core files are written to the current directory of the process that produces them so if that isn't the user's home directory, finding the right one could be difficult.

Your filename on the remote server ought to have some sort of date/time extension otherwise you'll be continually overwriting the same file.

I still don't know why you want to do this though. We just trash ours.

Regards,
John
Rodney Hills
Honored Contributor

Re: script to copy user files.

David,

If this a specific application you are trying to capture the "core" files, would it be possible to wrap a shell script around the launch of the application. If so, then you could use "trap" to capture the application when it generates a core dump.

example-

#!/usr/bin/ksh
trap "rcp core otherhost:/tmp/savecore" 3
/run/your/application

This way if a core dump is created, then the rcp would be run. You may want to add additional code to make the "core" file names unique at the destination.

HTH

-- Rod Hills
There be dragons...
Steve Labar
Valued Contributor
Solution

Re: script to copy user files.

The thing to be careful of is if you continuously cp core without a renaming convention, you will always overwrite previous cores that you may have needed. You may want to try something like
find /home -name core -exec rcp {}remote:/tmp/core.`date +'%m%d%H%M'` \;

This should copy the file to the remote server with a name of core.11131345 as an example for Nov. 13 at 1:45pm. You could modify the time stamps as you like. If you ran this as a cron job every 5-10 minutes the likelihood of duplicates would probably be decreased.

Good Luck.

Steve