LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-30-2006, 04:16 AM   #1
shawnbishop
Member
 
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249

Rep: Reputation: 30
Script to create multiple directories under users homes


Good Day

I am having a bit of a problem with a script ( in other words,all attempts have failed :-) )

I am looking to create 3 new directories under everybodies home directory like this.

/home/user - tmp
- docs
- pdf

/home/user2 - tmp
- docs
- pdf

I have about a thousand users to do this to,and I dont want to manually add all these directories.Can somebody tell me how I could do this via a script

Cheers

Shawn
 
Old 03-30-2006, 05:10 AM   #2
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
WARNING: I did this on cygwin so it might need a little tweeking.
Code:
#!/bin/bash
cd /home
for i in *;do
USER=`grep $i /etc/passwd|cut -d: -f3,4`
cd $i
mkdir tmp doc pdf
chown $USER tmp doc pdf
cd ../
done
 
Old 03-30-2006, 05:22 AM   #3
shawnbishop
Member
 
Registered: Dec 2005
Location: South Africa
Distribution: CentOS,Ubuntu,Fedora
Posts: 249

Original Poster
Rep: Reputation: 30
hi /bin/bash

Great thank you that work fantastically...

Cheers
 
Old 03-30-2006, 05:47 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
This also seems to work on my FC5 box.
Code:
#!/bin/bash
for i in $(cat /etc/passwd | grep /home |cut -d: -f6); do
mkdir $i/{tmp,doc,pdf}
done
 
Old 03-30-2006, 08:11 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
You're welcome, HTH.
 
  


Reply



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
Script to run script in multiple directories... seabass55 Linux - General 5 07-06-2004 12:44 AM
Migrating users and homes to new server anthonykirk Linux - Hardware 3 06-11-2004 03:18 PM
create users using script polis Linux - General 1 05-18-2004 08:19 AM
problem with homes & w2k users lgomez Linux - Networking 1 04-08-2003 07:09 PM
script for creating multiple users d3funct Programming 1 08-21-2001 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration