Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using the su command to create directories under another user 1

Status
Not open for further replies.

philipose

Programmer
Dec 24, 2003
137
US
Hi Gurus,
While running a cron job under root on AIX 5.2 (ksh), I am trying to create a directory under the ownership of another user of another group

something of this sort

/usr/bin/su - "user:group" -c "/usr/bin/mkdir -p /folder1/folder2/folder3/fol der4"

The problem is that the directories are not getting created. The issue is that the path may also have spaces in between, like fol der4.

Any suggestions to get over it ??
Thanks
philipose
 
Why don't you just create the directories as root and then chown the directories.

If you want the final directory to be two words (I wouldn't recommend it for Unix), I think you will need to put quotes around it:

mkdir -p /folder1/folder2/folder3/"fol der4"
chown -R user:group /folder1
 
Not sure why you would want a space in the directory name - unless maybe this is a share that will be access by Windows....

Your command as listed above wont work:

1.) su doesnt like the "user:group" nomenclature - it things "user:group" is the user, not the user AND the group.

2.) You have a space in your sub dir name.

to get your command to work, you would need to specify it like this:

su - someuser -c "mkdir -p /home/someuser/folder1/'fold er2'
 
sbrews,
in that case how do you specify if the group someuser belongs to is different from the person running it??

bi,
there was some issue to chown
when i issue the below command

chown "user:group" "/folder1/subfolder1"

gave a message like
chown: 3002-131 user is an unknown username.
I was not sure if that quotes had to do anything with it.

The reason why i need to cover spaces in folder names too is because some users have created directories as such, though i also dont endorse it.

Thanks for your suggestions
 
The group will default to whatever is the primary group for that user.

If you do this:

su - joe -c mkdir -p /some/location

Joe will be the owner and the group will be whatever Joe has a primary group (usually staff on AIX). If you want the group to be something else, you will need to issue the appropriate chown command.

For the error you got from this:

chown "user:group" "/folder1/subfolder1"

Try the command like this (without the quotes):

chown user:group /folder1/subfolder1

If you need/want to hit all the subdirs at once, you could do the command like this:

chown -R user:group /folder1

That will change the owner and group for folder1 and all folders under it to user:group.

scott
 
thanks sbrews for the tip. i will try it out and let you know. it will be another week before I know the result.
Thanks very much
Philipose
 
sbrews,
sorry for the late reply. you suggestions worked to create a directory using the su command.
philipose
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top