LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-20-2009, 05:19 PM   #1
vikki
Member
 
Registered: Jun 2009
Posts: 30

Rep: Reputation: 18
Shell Script for making directories from a file name


Hello guys

I have a file with usersnames in the following format
user1
user2
user3

i want to make directories of all using shell script. and then giving them required permissions. my users are on other LDAP server and i have binded ldap using pam mechanism.

please help, i am complete newbie in shell scripting.

Thanks in advance
 
Old 06-20-2009, 06:12 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,005
Blog Entries: 54

Rep: Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763
If you're new to scripting you might want some Bash scripting guides like http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html or http://www.tldp.org/LDP/Bash-Beginne...tml/index.html and later on the http://www.tldp.org/LDP/abs/html/.
 
Old 06-20-2009, 08:21 PM   #3
fritz001
Member
 
Registered: Aug 2004
Posts: 119

Rep: Reputation: 18
for beginner in `cat usernames`; do mkdir $beginner chmod 640 $beginner; done

Last edited by fritz001; 06-20-2009 at 08:22 PM.
 
Old 06-21-2009, 01:53 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by fritz001 View Post
for beginner in `cat usernames`; do mkdir $beginner chmod 640 $beginner; done
This will give spurious directories and a bunch of errors....
 
Old 06-21-2009, 09:06 AM   #5
fritz001
Member
 
Registered: Aug 2004
Posts: 119

Rep: Reputation: 18
for beginner in `cat usermanes`; do mkdir $beginner; chmod 640 $beginner; done

Now it's correct
 
Old 06-21-2009, 09:49 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,005
Blog Entries: 54

Rep: Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763
Quote:
Originally Posted by fritz001 View Post
Now it's correct
No it isn't. It may look syntactically correct but I still wouldn't ever use it like that because of 0) expanding in this "for" loop versus 'while|read' (try expanding a ludicrous amount of items), 1) lack of proper quoting (spaces), 2) duplicated commands (mkdir --mode), 3) the octal mode in the chmod command (this would render any directories created inaccessable) and 4) not rooting it in the directory the directories should be created in. Sure, that was not a requirement and most of this may seem like nitpicking but scripting often isn't only listing commands but also taking into account proper error handling...

Last edited by unSpawn; 06-21-2009 at 09:51 AM.
 
Old 06-24-2009, 06:21 AM   #7
vikki
Member
 
Registered: Jun 2009
Posts: 30

Original Poster
Rep: Reputation: 18
I got all my users of ldap from this.. to a file
#getent passwd > ldap

redirected name and gid value of users in another file with ':' as a delimeter
#gawk -F: '{ print $1,":"$4 }' ldap > arpit

now the script....
#!/bin/bash
NEW_USERS="/root/arpit"
cat ${NEW_USERS} | \
while read USER GID
do
mkdir /home/${USER}
chown ${USER}${GID} /home/${USER}
cp -f /etc/skel/.* /home/${USER}/
done


after that i tried to set user quota to my users.. but didnt worked.. can someone help me with it

after setting quota on one user i tried this.. but didnt worked
edquota -p user1 `awk -F: {print $1}' /root/arpit'

please help
 
Old 06-24-2009, 07:18 AM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by vikki View Post
edquota -p user1 `awk -F: {print $1}' /root/arpit'
This command has misplaced quotes. It should be:
Code:
edquota -p user1 `awk -F: '{print $1}'`
or using the bash notation for command substitution:
Code:
edquota -p user1 $(awk -F: '{print $1}')
 
  


Reply


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 copy one file and to multiple directories using shell script? cebuy Programming 8 03-31-2009 07:04 PM
Making a Shell Script better seefor Programming 7 03-04-2009 09:22 AM
changing directories in a shell script stocky021 Programming 9 11-04-2007 11:36 AM
Very simple shell script - move files to different directories beley Programming 7 11-02-2006 05:24 AM
Making shell script a part of linux image mayureshchitale Linux - Newbie 1 07-06-2004 01:00 AM


All times are GMT -5. The time now is 02:29 AM.

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