Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm eriting a MacOS script that need to run under admin rights (under 'sudo'). Script needs a temp folder in order to keep some temp files. Unfortunately, there is no 'TMPDIR' under root! If i run 'env' i see TMPDIR with a nice temp path. If i run 'sudo env' i don't see TMPDIR :(. Is it any way to obtain correct "temp folder" path under root?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

If there's a $TMPDIR, use it. Otherwise use /tmp (it should exist on Mac too).

share|improve this answer
    
Using /tmp looks fine for me. Is it any official BSD documentation that instructs to use it under root account, or is it a common knowledge? –  Eye of Hell Jun 1 '09 at 14:40
    
/tmp is just the standard location for temporary files, as defined in en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard –  grawity Jun 1 '09 at 15:25
add comment

In general, you're supposed to create temp files using the library-provided functions and use the filenames and/or handles provided. On mac, the mktemp(1) command with the "-d" option should do what you want.

NAME mktemp -- make temporary filename (unique)

SYNOPSIS mktemp [-dqtu] [-p directory] [template]

DESCRIPTION The mktemp utility takes the given filename template and overwrites a portion of it to create a unique filename. The template may be any file- name with some number of `Xs' appended to it, for example /tmp/tfile.XXXXXXXXXX. If no template is specified a default of tmp.XXXXXXXXXX is used and the -t flag is implied (see below).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.