Terminal User Input into a variable for a script

cabbage

Registered
I have a Xserve setup as an FTP Server only. I edited the System/Library/User Templates the way I wanted but it doesn't carry over the permissions. I want to run the below script.

I'm going to save it in /bin as myftpperm so it is in the root's path.

Let's say I have a user named apple. I want to be able to type myftpperm apple and every where it says <enterNewUserNameHere> it would replace it with apple.

How do you do that?


#!/bin/sh

cd /
createhomedir -u <enterNewUserNameHere>

cd /Volumes/FTP
chgrp -R myftpclients <enterNewUserNameHere>
chmod 550 <enterNewUserNameHere>

cd <enterNewUserNameHere>
chmod -R 770 FileDropOff
chmod -R 770 FilePickUp

exit
 
#!/bin/sh

username ="USERNAME"

cd /
createhomedir -u $username

cd /Volumes/FTP
chgrp -R myftpclients $username
chmod 550 $username

cd $username
chmod -R 770 FileDropOff
chmod -R 770 FilePickUp

exit

$username is your variable now.
Just change USERNAME to whatever you wish.
 
So when I type this at the terminal
myftpperm apple

How does it know that I want apple to equal the username? This will grab the users input?

It looks like I have to set the variable in the script before hand which is what I don't want to do.
 
There are a number of variables already set for you, all documented in your shell's manual page. The variables $0, $1, $2, etc, each refer to the respective arguments of the command which invoked the script. Keep in mind that $1 is the first argument, and $0 is the name that the script was invoked with.
 
testme was a user I created with Woorkgroup Manager

[ftpxserver:/bin] root# ftperm testme
/bin/ftperm: username: command not found
createhomedir: option requires an argument -- u
createhomedir
-h displays this help info
-a traverse search node and create local user home directories
-l traverse local node and create local user home directories
-n nodename traverse specified node and create local user home directories
-u username traverse search node and create specified local user home directory
usage: chgrp [-R [-H | -L | -P]] [-fh] group file ...
usage: chmod [-R [-H | -L | -P]] mode file ...
changed permissions on Home Folder
chmod: FileDropOff: No such file or directory
chmod: FilePickUp: No such file or directory
changed permissions on Drop Boxes

here's the script
#!/bin/sh

username = "USERNAME"

cd /
createhomedir -u $username

cd /Volumes/FTP
chgrp -R myftpgroup $username
chmod 550 $username
echo changed permissions on $username Home Folder

cd $username
chmod -R 770 FileDropOff
chmod -R 770 FilePickUp
echo changed permissions on Drop Boxes

exit
 
I got it to work! THANK YOU!


#!/bin/sh

#script to create a ftp users home folder andset permissions correctly
#2002-12-04


cd /
createhomedir -u $1
echo "..created Home Folder for $1"

cd /Volumes/FTP

#imtechftp is the group that employees use to connect to the server over AFP
#this way they have permission to edit all the clients folders and files
chgrp -R imtechftp $1

#r-xr-x---
#so the idiots don't upload any crap to the root of their home folder
#already getting calls that they don't have permission to upload
#cause their to stupid too put them in the FileDropOff folder
chmod 550 $1
echo "....changed permissions on Home Folder for $1"

cd $1
#rwxrwx---
#the client and imtechftp can do anything they want to this folder
#no one else should be able to see it
chmod -R 770 FileDropOff
chmod -R 770 FilePickUp
echo "......changed permissions on Drop Boxes for $1"

echo "$0 is done you can logout now"

exit
 
Back
Top