"here documents" and /tmp


 
Thread Tools Search this Thread
Operating Systems Solaris "here documents" and /tmp
# 1  
Old 02-19-2005
Question "here documents" and /tmp

Hi folks,

I am developer on solaris 8, I am using "here documents <<eof" but unfortunately I am having contention problems with /tmp directory because this facility tries to create a temporary file sh99999 on it but this filename already has been created by a different process before.

To avoid this I had thought on using $TMPDIR variable, but it seems that it only has effect with compilers.

I wonder how I can redirect /tmp directory to another directory only during the execution of my shell script in order to avoid this problem.

Thanks in advance
jterra
# 2  
Old 02-19-2005
I think that the filename is supposed to contain the pid of the shell and this should prevent name collisions. Could these be old filenames from shells that aborted? If so the fix is to address the condition(s) causing the aborts. Another though is to periodically clean out the old files. If neither is possible, crucial scripts can be written to not use here-docs.
# 3  
Old 02-19-2005
Data

Smilie Hello Perderabo,
First of all, thanks for your interest.
Yes, you are right, the filename consists of “sh” + pid, and the old filenames correspond to aborted process from operating system because they have as owner “root”. My system administrator has told me that these old files only will be removed at reboot time, but the machine only is rebooted fortnightly. And me as developer I only can try to avoid to allocate sh files on /tmp directory. I also have thought of using real files, but I have a lot of code using here-documents with variables, and before taking that way I would like to know if it were possible to redirect /tmp directory doing the same than compilers.
jterra
# 4  
Old 02-19-2005
Code:
#!/bin/ksh

............

typeset -i u="${$}"

# keep incrementing "u" till you find a non-existant tmp file
while :
do
   tmpFile="/tmp/sh${u}"
   if [ ! -f "${tmpFile}" ] ; then break; fi
   ((u = u + 1 ))
done

command <<EOF >> "${tmpFile}"
.........
.........
EOF

# 5  
Old 02-19-2005
Data

Hello vgersh99,
This is very interesting, but using here-documents I think that sh+pid file is allocated on /tmp automatically, so when system finds <<EOF the automatic allocation is done although later you redirect the output using >> "${tmpFile}". So the problem remains.
jterra
# 6  
Old 02-19-2005
Quote:
Originally Posted by jterra
Hello vgersh99,
This is very interesting, but using here-documents I think that sh+pid file is allocated on /tmp automatically, so when system finds <<EOF the automatic allocation is done although later you redirect the output using >> "${tmpFile}". So the problem remains.
jterra
I don't understand.
You have a 'here-doc' that you redirect the output to a temp file. Right?
And that temp might exist with missing 'w' permissions for you to write to. Right?

If that's the case what I'm suggesting is to find a temp file that does not exist. Take a value of '$$' - see if the tempFile exists. If it doesn't - use that file for redirection.
If it does, keep incrementing '$$' till you find the file that does not exist.

Am I missing something obvious here?
It might help if you posted relative parts of your script.
# 7  
Old 02-19-2005
vgersh99's code is not helpful. The shell itself decides on which name to use for here-docs. I suppose that you could keep forking shells until you finally get one with a pid that is not compromised with /tmp/sh* aritifacts, but that really is not a great solution. The answer to the original question is no, /tmp/sh* is hard coded. Your sysadmin's attitude is unfortunate. Had he been willing, this problem could be solved with a clever script to reap the old tmp files. This leaves the option of rewriting the scripts to avoid here-docs.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Issue with rsync: failed to set times on "/tmp/.": Not owner (1)

Hi, Here is my source host and folder details. $ hostname source-host $ id uid=600000208(src-user) gid=64688(src-user) groups=64688(src-user) $ ls -ltrd /web/Trn_File/data/ drwxrwxrwx 3 src-user src-user 4096 Feb 7 15:27 /web/Trn_File/data/ $ ls -ltrd /web/Trn_File/data/* drwxrwxrwx 8... (1 Reply)
Discussion started by: mohtashims
1 Replies

4. Solaris

Solaris 10 error "-sh: /tmp/outfile: cannot create"

Hello, Each time a user log on to host, they receive below error: -sh: /tmp/outfile: cannot create Example: $ ssh host user@host's password: Last login: Fri Dec 4 08:17:28 2015 from client.ref |-----------------------------------------------------------------| -sh:... (2 Replies)
Discussion started by: feroccimx
2 Replies

5. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

6. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question