Using mkdir to create a directory where its immediate subdirectories are not exist

Hi,

In my shell script, i use mkdir to create a subdirectory but it keeps failing saying the immediate subdirectory does not exist.

I use

mkdir -p  /tmp/abc/def
I got:
mkdir: 0653-357 Cannot access directory /tmp/abc.
/tmp/abc: A parameter must be a directory

I tried -p -m 755 /tmp/abc/def
I got the same error

What did I do wrong?

Thank you
xewooxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
is /tmp protected?
does /tmp/abc exist
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Heem14Commented:
typically that means you don't have permissions. /tmp/abc does not have to exist as the -p option is set. check make sure you have permissions to write in this tree
0
Heem14Commented:
OR - if you are operating in tmp - another process is deleting your directory before you have the chance to create the subdirectory.

if possible try operating outside of /tmp

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

xewooxAuthor Commented:
No, /tmp/abc does not exist.

I run the mkdir inside /tmp

If I do

mkdir -p /tmp/abc/def
failed

mkdir abc
success

mkdir -p /tmp/abc/def
success

but I want to be able to create /tmp/abc/def without first creating the subdir abc
0
michofreihaCommented:
mkdir -p /tmp/abc/def should create abc and def directories into /tmp if both directories does not exist
0
omarfaridCommented:
If you run the same command from command line (mkdir -p /tmp/abc/def) without having /tmp/abc being created earlier, do you get the same error? did you try to do the same under a different dir other that /tmp?
0
Xyptilon2Commented:
-p is short for --parents, does the long option work?

mkdir --parents /tmp/abc/def

Is /tmp a seperate partition or mounted as read-only? perhaps a symlink?
0
woolmilkporcCommented:
Just to make the picture complete - does
mkdir /tmp/abc
work?
0
TintinCommented:
Assuming you have AIX 5.1 or higher, you should have truss.  There is something, very, very strange happening on your system.

What is the output of

truss mkdir -p /tmp/abc/def
0
SaranyakkaliCommented:
    -p              With  this  option,  mkdir  creates  dir  by
                     creating  all the non-existing parent direc-
                     tories first. The mode given to intermediate
                     directories  will  be the difference between
                     777 and the bits set in the file mode  crea-
                     tion  mask. The difference, however, must be
                     at least 300 (write and  execute  permission
                     for the user).

0
dfkeCommented:
My guess is that /tmp/abc is an existing file, therefore a directory cannot be made by mkdir -p.
0
Xyptilon2Commented:
Either that or it is a more exotic problem, such as extended ext2 file attributes that are set in a parent directory preventing access that won't be visible during a normal "ls" command, or perhaps file system corruption.

Do you have this problem also outside the /tmp folder ? does mkdir -p /home/a/b/c/d/e/f work ?

This will rule out a problem with the mkdir command itself
0
TintinCommented:
AIX does not use ext2 filesystems.
0
colinvannCommented:
Ok, lets rule out a few things...

SELinux: please run "setenforce 0"
are there any acl's on the /tmp: "getfacl /tmp"
you might want to check if the filesystem is mounted with acl support: "mount |grep acl"

please display this output here for further comment.
Colin
0
TintinCommented:
Can posters please note that this issue is on an AIX system and *NOT* a Linux system, so all the Linux suggestions are not going to be valid.
0
Xyptilon2Commented:
Well....we are all ignoring the most likely explanation

The version of "mkdir" that is being used does not support the -p parameter.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.