Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-26-2005, 08:30 AM   #1
Registered: Jun 2005
Location: Wycombe, England
Distribution: Mepis 3.4.3 , Ubuntu & Damm Small Linux
Posts: 119

Rep: Reputation: 15
Linux Script which uses user defined variables

I know how to do this as an MSDOS batch file, but i have ZERO experience with linux scripts, i think i need to use BASH but i have a specific immediate requirement, basically i'm being VERY lazy, and hoping someone can point me in the right direction

I need a script which performs the following, lets call the script setup

so if i type in setup username groupname

the following would happen:

1) In the users home directory a folder called home would be created
2) the newly created folder home would be assigned chown username:groupname
3) the folder would then be assigned chmod 775

So for example i have a user called joey who's primary group in year9 i currently type in the following:

cd /home/joey
mkdir home
chown joey:year9 home
chmod 775 home
cd /

What type of script would be the best to achive this?
Where can i look for idiot level instructions on this type of script?

I need a script as i have 250 users to do this for
Old 09-26-2005, 10:48 AM   #2
Registered: Dec 2004
Distribution: gentoo
Posts: 190

Rep: Reputation: 30

mkdir /home/$1/home
chown $1 /home/$1/home
chgrp $2 /home/$1/home
chmod 755 /home/$1/home
UT's CS300 class has a nice lecture on this:
Old 09-26-2005, 11:12 AM   #3
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 24, 25, RHL 5.2
Posts: 560

Rep: Reputation: 56
If this directory is something that is required everytime a new user is added you should take a look at the /etc/skel directory. It is described briefly on the useradd man page. Basically anything in /etc/skel is copied to the new users /home/username directory and given default permissions and ownership.

This of course won't help with accounts that are already set up. You can use visaris' script for those accounts. Since you are new to bash, the $1 and $2 variables relate to parameters on your command line. To execute the script you would type username group where you substitute username and group of the account where you want to add the home directory.

Old 09-26-2005, 07:29 PM   #4
Registered: Jun 2005
Location: Wycombe, England
Distribution: Mepis 3.4.3 , Ubuntu & Damm Small Linux
Posts: 119

Original Poster
Rep: Reputation: 15
Many thanks people, and i will be true to my word, and make aevey effort to learn scripting skills in linux..


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send user defined signal in linux feetyouwell Linux - Software 6 12-26-2007 05:40 AM
how to define user-defined commands in linux mannoulla Linux - General 1 04-05-2005 10:01 PM
How to run user defined services and exe files on linux. Prabhat Sharda Linux - Software 6 01-05-2005 04:54 AM
On boot the routing configuration is defined, where is the script that does that? brynjarh Linux - Networking 1 11-06-2004 12:01 PM
user defined variables linuxdev Linux - Newbie 4 02-09-2004 01:43 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration