KSH /tmp/sh$$.* files problem

KSH /tmp/sh$$.* files problem

am 04.11.2005 13:21:52 von amitkr.3

Hi,

I am encountring this problem from some time now...

ksh creates temp files /tmp/sh$$.* .
Sometimes if some of my shell script crashes or I kill it... these temp
files remain in the /tmp directory.

At some later time when some script gets the same PID it tries to
create files in the /tmp directory, It fails complaining that

sh$$.* : cannot create

Its a multi user unix system... so shell script may not overwrite files
created by other user.

Does any one have a solution to this problem....?

I dun want to do something like checking and deleting stray temp files
once in a while...

May be some environment variables I can set to customize the names of
these temp files...

Thanks

Re: KSH /tmp/sh$$.* files problem

am 04.11.2005 16:37:30 von Bill Marcum

On 4 Nov 2005 04:21:52 -0800, A Kumar
wrote:
> Hi,
>
> I am encountring this problem from some time now...
>
> ksh creates temp files /tmp/sh$$.* .
> Sometimes if some of my shell script crashes or I kill it... these temp
> files remain in the /tmp directory.
>
These files shouldn't remain unless you kill your script with "kill -9".
Don't do that.

> At some later time when some script gets the same PID it tries to
> create files in the /tmp directory, It fails complaining that
>
> sh$$.* : cannot create
>
> Its a multi user unix system... so shell script may not overwrite files
> created by other user.
>
You can schedule a cron job as root to delete these files.
0 0 * * * find /tmp -name 'sh$$.*' -atime +1 -exec rm {} \;

If you don't have root access, you can at least clean up your own files.

>
> May be some environment variables I can set to customize the names of
> these temp files...
>
man ksh
You can set the TMPDIR variable to store temporary files somewhere other
than /tmp.


--
"What do you give a man who has everything?" the pretty teenager
asked her mother.
"Encouragement, dear," she replied.

Re: KSH /tmp/sh$$.* files problem

am 05.11.2005 03:16:34 von Dan Mercer

"A Kumar" wrote in message news:1131106912.009493.28030@z14g2000cwz.googlegroups.com...
: Hi,
:
: I am encountring this problem from some time now...
:
: ksh creates temp files /tmp/sh$$.* .
: Sometimes if some of my shell script crashes or I kill it... these temp
: files remain in the /tmp directory.
:
: At some later time when some script gets the same PID it tries to
: create files in the /tmp directory, It fails complaining that
:
: sh$$.* : cannot create
:
: Its a multi user unix system... so shell script may not overwrite files
: created by other user.
:
: Does any one have a solution to this problem....?
:
: I dun want to do something like checking and deleting stray temp files
: once in a while...
:
: May be some environment variables I can set to customize the names of
: these temp files...
:
: Thanks
:
These files are produced by here documents. Your ksh must be very
old (pdksh perhaps?). Modern ksh's creat the files and then
unlink them, so when they close they disappear completely.
Either upgrade you ksh o get rid of the here docs.

Dan Mercer

Re: KSH /tmp/sh$$.* files problem

am 05.11.2005 03:17:48 von Dan Mercer

"Bill Marcum" wrote in message news:qqbs33-3jr.ln1@don.localnet...
: On 4 Nov 2005 04:21:52 -0800, A Kumar
: wrote:
: > Hi,
: >
: > I am encountring this problem from some time now...
: >
: > ksh creates temp files /tmp/sh$$.* .
: > Sometimes if some of my shell script crashes or I kill it... these temp
: > files remain in the /tmp directory.
: >
: These files shouldn't remain unless you kill your script with "kill -9".
: Don't do that.

They shouldn't even be visible unless the shell dies between the
creat and unlink. UPGRADE!

Dan Mercer
:
: > At some later time when some script gets the same PID it tries to
: > create files in the /tmp directory, It fails complaining that
: >
: > sh$$.* : cannot create
: >
: > Its a multi user unix system... so shell script may not overwrite files
: > created by other user.
: >
: You can schedule a cron job as root to delete these files.
: 0 0 * * * find /tmp -name 'sh$$.*' -atime +1 -exec rm {} \;
:
: If you don't have root access, you can at least clean up your own files.
:
: >
: > May be some environment variables I can set to customize the names of
: > these temp files...
: >
: man ksh
: You can set the TMPDIR variable to store temporary files somewhere other
: than /tmp.
:
:
: --
: "What do you give a man who has everything?" the pretty teenager
: asked her mother.
: "Encouragement, dear," she replied.

Re: KSH /tmp/sh$$.* files problem

am 08.11.2005 02:38:54 von brian_hiles

A Kumar wrote:
> ksh creates temp files /tmp/sh$$.*

It is not a necessary condition that only SIGKILL signals
leave temporary files. Both sh(1) and ksh(1) (and presumably
ksh93(1), although I haven't tested this) have an
undocumented bug that these files, represented here-files
within the script, will not be deleted if the controlling
process attached to the here-file is asynchronous (that is,
in the background with a "&").

The above is from memory, and may not be totally precise,
although it has been thoroughly tested and documented by
me elsewhere.

=Brian

Re: KSH /tmp/sh$$.* files problem

am 09.11.2005 19:31:27 von Sven Mascheck

bsh wrote:

> It is not a necessary condition that only SIGKILL signals
> leave temporary files. Both sh(1) and ksh(1) (and presumably
> ksh93(1), although I haven't tested this) have an
> undocumented bug that these files, represented here-files
> within the script, will not be deleted if the controlling
> process attached to the here-file is asynchronous (that is,
> in the background with a "&").

I only knew this from the traditional Bourne shells until now.
It happens if also command substitution is involved,

cat< `pwd`
EOF

or without &, and replacing the external command (cat)
with a built-in (probably rarely used),

read var< `pwd`
EOF

In both cases you get the error message "/tmp/sh12345: cannot open",
though. In both cases, the shell loses track when having to handle
several tempfiles.


BTW, a good candidate in traditional Bourne shells for
temp-files lying around on interruption is the following :)

func() {
cat< EOF
}

because a tempfile interestingly is created at the time of
definition already: "type func" results in

func(){
cat 0< }