Shell script to create local homes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to create local homes
# 8  
Old 10-20-2004
I use a login window manager from (its free)http://www.bombich.com/mactips/loginhooks.html
and this uses unix to login hook (LoginHook (POSIX path)) and it allows you to store a script on the hardrive or server and executes it at login. It runs the script with root permissions ( I assume) otherwise I don't think it would be able to create directories and sub directories. Theres good info on this page (link above) eg
Create a shell script to be run upon login. The name of the script is not important, as long as it is the same as what you will indicate in step 4. Note that the name of the user logging in is sent as an argument ($1) to this script. You can also download this basic script and copy it to /Library/Management (you may have to create this folder). Be sure to check out my Scripts Library for several other scripts that perform various tasks.

All my client machines are Mac osx 10.35 with an Admin and Root local users. Everyone else who logs in are not local users but are located on an Xserve LDAP binded database.

The reason I am trying to create certain directories locally for users as they login rather than have them on the server is because we run a wireless network that can't cope with huge movie and music files.

I hope this clears things a little.

Thanks
# 9  
Old 10-21-2004
Do you think I need to change the $CURRUSER to $1
# 10  
Old 10-21-2004
Quote:
Note that the name of the user logging in is sent as an argument ($1) to this script.
Yes, give that a try. Note that for this to work, the script will be executed as follows:

your_script_name.sh user_name

Inside of your script, change CURRUSER=`whoami` to CURRUSER=$1
# 11  
Old 10-22-2004
After changing the script so that CURRUSER=$1 the script creates the directories for all users that login.

The 2 things it still does not do is:
1. Exit the script when local admin users login.

2. Remove the network Movie and Music directories and create virtual linked directories to the ones on the local drive (users/shared/..).

It seems we are starting to get close.

Any suggestions to try next.
# 12  
Old 10-25-2004
This may be the way to go

Problems are probably due to the script running as root which means ~ still resolves to root's home.

What you should probably do is change CURRUSER $(logname) or even just $USER for that matter.

create a new shell script:

#!/bin/sh

sudo -u $1 -H <pathToOriginalScript>

exit 0


Make this one your LoginHook.

This will run your script as the user logging instead of running it as root, and set the ~ variable to the target users $HOME.

You may also want to use 'id -Gn' instead of 'groups' as 'groups' has been made obsolete by 'id'.
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