The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto create local account with winbind. d_ark Linux 1 06-02-2008 07:15 AM
Local shell script need to be executed on a remote linux box rajeshomallur Linux 6 05-02-2008 01:05 PM
shell script to create dirs sjajimi Shell Programming and Scripting 2 07-24-2007 07:34 AM
create a shell script maykap100 Shell Programming and Scripting 3 08-31-2005 10:17 PM
shell script, reading and resetting local variables b888c UNIX for Dummies Questions & Answers 1 08-20-2001 04:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-18-2004
Steve Adcock Steve Adcock is offline
Registered User
  
 

Join Date: Oct 2004
Location: Australia
Posts: 8
Shell script to create local homes

Hi
I am trying to write a login script for network based clients (OSX) that looks up local accounts eg admin, root, etc and exits the script so that it doesn't apply to them. Then for everyone else I make folders eg movies, music, etc that are placed in local harddrive rather than the default place on the server harddrive.
At the moment this script creates the desired effect for the root user no matter who logs in. If I remove the first couple of lines that try to sort out the admin users it works for everyone who logs in. However I want it to work for everyone except root and local users.
ie
#!/bin/sh
#
CURRUSER=`whoami`

ADMINGROUP=`groups | grep admin`
if [ `expr "$ADMINGROUP" != ""` = 1 ]
then
exit 1
fi

mkdir -p /Users/Shared/$CURRUSER/Movies
mkdir -p /Users/Shared/$CURRUSER/Music
mkdir -p /Users/Shared/$CURRUSER/Pictures
mkdir -p /Users/Shared/$CURRUSER/Music/iTunes
mkdir -p /Users/Shared/$CURRUSER/Music/GarageBand
mkdir -p /Users/Shared/$CURRUSER/Pictures/iPhoto Library


rm -R ~/Movies
rm -R ~/Music
rm -R ~/Pictures

ln -s /Users/Shared/$CURRUSER/Movies ~/Movies
ln -s /Users/Shared/$CURRUSER/Music ~/Music
ln -s /Users/Shared/$CURRUSER/Pictures ~/Pictures


Hope someone can help.
Ta
  #2 (permalink)  
Old 10-18-2004
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
I couldn't get your if statement to work (but that could be due to the OS I'm running - can't tell since you didn't post yours).

Try this instead:

Code:
ADMINGROUP=`groups | egrep -c admin`

if [ "$ADMINGROUP" > 0 ]
   then
      exit 1
fi
  #3 (permalink)  
Old 10-18-2004
Steve Adcock Steve Adcock is offline
Registered User
  
 

Join Date: Oct 2004
Location: Australia
Posts: 8
OSX 10.3

Thanks I'll give it a try.
  #4 (permalink)  
Old 10-20-2004
Steve Adcock Steve Adcock is offline
Registered User
  
 

Join Date: Oct 2004
Location: Australia
Posts: 8
Hi I tried it and it makes sense but the script does not quite work yet , a bit of progress has been made at this link.

http://discussions.info.apple.com/we...736.689d315b/3

My script currently looks like this

#!/bin/sh
#
CURRUSER=`whoami`

ADMINGROUP=`groups | egrep -c admin`

if [ "$ADMINGROUP" > 0 ]
then
exit 1
fi

mkdir -p /Users/Shared/$CURRUSER
mkdir -p /Users/Shared/$CURRUSER/Movies
mkdir -p /Users/Shared/$CURRUSER/Music
mkdir -p /Users/Shared/$CURRUSER/Music/iTunes
mkdir -p /Users/Shared/$CURRUSER/Music/GarageBand



rm -R ~/Movies
rm -R ~/Music


ln -s /Users/Shared/$CURRUSER/Movies ~/Movies
ln -s /Users/Shared/$CURRUSER/Music ~/Music


I will add the chown part but it still needs something to create the $CURRUSER directories rather than roots . This last sentence makes sense if you read the input at the link above.

Last edited by Steve Adcock; 10-20-2004 at 04:18 AM..
  #5 (permalink)  
Old 10-20-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Add logic such as a prompt to actually set the value of CURRUSER to the ID of the person who will own the directories. Since you are running as root, then you could issue the command su $CURRUSER without the need to supply a password.
  #6 (permalink)  
Old 10-20-2004
Steve Adcock Steve Adcock is offline
Registered User
  
 

Join Date: Oct 2004
Location: Australia
Posts: 8
Would I do that just before I make the directories in the script and I am not quite sure how.
I guess I don't understand how your trying to use su.
Could you give an example in my script how you might do it.
Thanks
  #7 (permalink)  
Old 10-20-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Quote:
At the moment this script creates the desired effect for the root user no matter who logs in.
#I had thought for some reason that the script was being
#executed by root and not the everyday user

Are you saying it works for root but not others? Are you getting any permission errors, unable to create directory errors?

How are you executing the script? Does root own the script and do you have the SUID permission bit set? This would allow anyone who executes the script to run the script as if they were root (security issues with SUID's). What permissions are set for this script?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting 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




All times are GMT -4. The time now is 12:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0