Shell script to create local homes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to create local homes
# 1  
Old 10-18-2004
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  
Old 10-18-2004
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  
Old 10-18-2004
OSX 10.3

Thanks I'll give it a try.
# 4  
Old 10-20-2004
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 05:18 AM..
# 5  
Old 10-20-2004
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  
Old 10-20-2004
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  
Old 10-20-2004
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to have local shell variables in a ksh script seen on remove server in SSH block?

I have googled this and found many solutions, but none of them are working for me. I am in a korn shell, most others reference bsh, maybe that is the issue? Anyway, all I am trying to do is use a variable I have declared in my main script in a remote shell I am running through ssh. So I have a... (8 Replies)
Discussion started by: DJR
8 Replies

2. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies

3. UNIX for Dummies Questions & Answers

Copy files from Linux server local windows machine using a shell script

Hello, I need to create a shell script which will copy files - which are created on particular date and starting with particular name - to local windows XP machine. Is this possible.? Currently it is being done manually using winscp (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

4. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

5. UNIX for Dummies Questions & Answers

SQL block in a Shell Script connecting to a local and remote DB

Hi All, In a Shell scriipt with a SQL block I want to issue a query against a local DB and a remote DB on a remote server. The shell script is running locally. This is how I connect to the local server. But I want the query to reference remote table in the join. Question can I specify a... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

7. Shell Programming and Scripting

Help with shell script to run the commands reading options from local file

I have to use shell script to run series of commands on another unix box by connecting through SSH and giving user credentials. For running commands on remote machine I have to use options reading from a local file. Process: Connecting to remote unix server <host1.ibm.com> through ssh Login: ... (2 Replies)
Discussion started by: itsprout
2 Replies

8. Shell Programming and Scripting

Executing shell script on local machine

Hi guys, I need to run and test some shell script. At work, i work on ksh. I don't have any such software/client installed at home and i cannot always connect to work from home. At home i have Windows Vista. Is there a free and reliable software where i can run my ksh script? Please let me... (4 Replies)
Discussion started by: jakSun8
4 Replies

9. Linux

Local shell script need to be executed on a remote linux box

I need to execute a shell script on a remote linux box. But the shell script resides on the local linux box where I am currently logged in. Is there a way to do this? I know rsh <host> <command> can execute a command on the remote host. (6 Replies)
Discussion started by: rajeshomallur
6 Replies

10. UNIX for Dummies Questions & Answers

shell script, reading and resetting local variables

Hello, I have a problem with trying to run a shell script that reads in user input, validates, and sets to a 'default' value if the input is not valid. I cannot get the portion of resetting to a default value to work. These lines are skipped, and the value of x is still whatever the user... (1 Reply)
Discussion started by: b888c
1 Replies
Login or Register to Ask a Question