Sort command using which directory

Hi,

One of our script is executing following "sort" command.

/bin/sort $delimiter $key $originalFile -o $newFile

and while executing this, we are getting the following error:

sort: A write error occurred while merging.

While reading about this I come to know this is because of insufficient size in TMP directory, but as I am not a unix guy, I don't know which TMP directory "sort" is using and what is the maximum size allocated to that directory. :wall:

Please help me for the same.

Thanks,
Manu

On an HP system there is big chance (99% ? ) it be /tmp...
You did not say OS version platform nor size of files you are trying to merge...

1.25 GB of file having 13,500,000 lines.
Unix version: HP-UX B.11.23

Regards,
Manu

It will be /var/tmp by default unless you have $TMPDIR set.
See man sort and the "-T" parameter regarding how to change it. You could need three times the size of the original file for work space.

Use the bdf command to find out where you have some free space.

I executed echo $TMPDIR

I didn't see any result. What it mean? that default temp directory (/var/tmp or /tmp) is being used.

Can you tell me how to set this parameter to use some other directory as temporary directory.

Thanks.

---------- Post updated at 11:53 PM ---------- Previous update was at 11:47 PM ----------

Is export TMPDIR=/tmpdump the correct way to set this environment variable?

If you see no result, that means its not set, yes.

That will work on some systems but not others. The proper way to do it, the way which works everywhere, would be:

TMPDIR=/tmpdump
export TMPDIR

Yes, if $TMPDIR is not set the "sort" command will use "/var/tmp" then "/tmp".

Will work on HP-UX in "sh" (i.e. the default for the "root" account) or "ksh".

Hi,

I am still not able to find, why sort command is failing. I have set TMPDIR to /tmpdump (as shown above) which is of 8GB and same error. While sort command was running, I have executed df -k to see if size of directory is used or not. I noticed that

/tmpdump               (/dev/vg02/lvol2       ) :  8323520 total allocated Kb
                                                   8306200 free allocated Kb
                                                     17320 used allocated Kb
                                                         0 % allocation used

and it remains the same. Please let me know how to solve this problem.

Thank you.

---------- Post updated at 01:32 PM ---------- Previous update was at 12:57 PM ----------

I saw that

TMPDIR=/tmpdump
export TMPDIR

is setting the TMPDIR to the current session only, while script is used in some other session. I want to make this change persist along all the unix sessions. How to do that?

Please help.

Thanks.

Is your filesystem set to largefiles?
What about your environment? (e.g. ulimit...)

I didn't get that.

Which commands you want me to execute?

Environment variables are not "global variables". There's no one place you can change it that will simultaneously change it for everyone.

Obvious way to do it: Run the export in the right session, not the wrong one.

More complicated way: Put it in the login scripts, perhaps /etc/profile, so the session you want will read it on login. You'll have to log out and log back in, or re-read the /etc/profile with . /etc/profile in the correct sesssion.

If your session is a cron job or something and doesn't even read those you'll have to set it manually because environment variables aren't globals and have to be read somehow.

Put this in the script containing the "sort" command.
Do not put it in /etc/profile or root's .profile because it refers to a filesystem which may not be mounted in every run state.

The "largefiles" option for fileystems is described in "man fsadm_vxfs", "man newfs_vxfs" and "man mkfs_vxfs". It allows you to create individual files larger than 2Gb. No really relevant to this thread.
Just for interest: To find out if you have any filesystems with "largefiles":

grep "largefiles" /etc/fstab | grep -v "nolargefiles"

Putting export in script solved my problem.

Many thanks to all for your valuable suggestions.