Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Semi-simple shell script using chown

Semi-simple shell script using chown
Thread Tools
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jun 11, 2004, 01:24 PM
 
I have a bunch of user home folders that I want to change owner/group to their owners and groups. I thought it would be as simple as making a simple script that took two command line arguments (user and group) and then ran chown and chmod using those variables ($1 and $2). Here's where I started:
Code:
chown -R $1:$2 /Homes/$1 chmod -R 755 /Homes/$1
Here I would run the script specifying the user and group (whose home folder has the same name as his shortname) such as this:
Code:
[aorth@csucub1: ~/testing]$ sudo ./fix_permissions someone somegroup chown: somegroup: Invalid argument
When I check out the someone directory, the permissions on that are 755 just like I told chmod to do in the script but chown keps erroring out. What gets me is, why doesn't chown behave like chmod with these stupid variables?

Now I've been attempting to fix this stupid script for an hour now and I probably could have done all 260 users by hand in this amount of time. It just pisses me off that the computer could have done in in three seconds. Do I have to put something in brackets? Squigly brackets? Escape something? The shell has always been weird for me to program in.
(Last edited by [APi]TheMan; Jun 11, 2004 at 01:30 PM. )
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 11, 2004, 02:24 PM
 
Huh, something similar works fine for me
Code:
#!/bin/sh chown -R $1:$2 /Users/Shared chmod -R 755 /Users/Shared
You sure the group names that you're entering work fine? Have you tried entering the command by hand to confirm it works as expected on the command line?

e.g.
[user@host ~/testing] new_u = someuser
[user@host ~/testing] new_g = somegroup
[user@host ~/testing] chown -R $new_u:$new_g /Homes/$new_u

?
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Jun 11, 2004, 11:23 PM
 
Originally posted by Mithras:
Huh, something similar works fine for me
Code:
#!/bin/sh chown -R $1:$2 /Users/Shared chmod -R 755 /Users/Shared
You sure the group names that you're entering work fine? Have you tried entering the command by hand to confirm it works as expected on the command line?

e.g.
[user@host ~/testing] new_u = someuser
[user@host ~/testing] new_g = somegroup
[user@host ~/testing] chown -R $new_u:$new_g /Homes/$new_u

?
Were you using legit users and groups? I just figured it out I think. I was testing it with a fake user, for who I made a folder in /Homes/, but he did not have an account on the system.

Before I decided to write the script I tested on a legit user (with a legit group) by just issuing the chown and chmod commands manually. Then I wrote that script thinking that it should work fine. From your suggestion I tried the command by just using chown someuser:somegroup, and of course it failed. Then I tried for a legit user and group and it worked. Here's what happened...

The users for whose home folders I was trying to manipulate do not have local accounts, they are in a Mac OS X server directory. While I was playing with permissions in the Get Info window none of the pulldown menus listed any of these users or groups. This made sense to me as they are no local accounts so they should not be showing up. I thought Mac OS X Server was behaving as it should but I guess I was wrong, the OS knows about those users in the LDAP database too. So I assume that once I give it a try again everything will be ok.

Thanks for pointing me in the right direction
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 04:37 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2