I have a cron job setup that searches for 'core dump' files in a fixed set of directories and moves the core files to a separate file system.
I am able to add date and time info to the file name.
How can I add the source directory path to the file name?
In case anyone is wondering why I need to know this, it's because the support personnel demand to know the location where the core was collected from.
Here's the command in my cron job:
find /var/mqsi/ -name core -type f -exec mv '{}' /corefile/core_$(date +%Y%m%d-%H%M%S) \;
You'll need to incorporate a processing block.
For example (untested):
find /var/mqsi/ -type f -name core -print | while read filename
do
# Converted solidus in filename to underscore
location=`echo "${filename}"|sed -e "sX/X_Xg"`
mv "${filename}" "/corefile/core_$(date +%Y%m%d-%H%M%S)_${location}"
done
Before removing a file called "core" it is important to know whether it contains a core dump. Use the unix "file" command to determine the file type. When you type "man core" just imagine whether there are any vulnerable files. Some unix systems have a critical package called "core" - be careful.
To be more specific we would need to know precisely what Operating System and Shell you have. The output from "file core" on a typical core file is very helpful.