Create file in each user directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create file in each user directory
# 1  
Old 07-01-2005
Create file in each user directory

Hi, Im newbie,
I wanna to create file in each user directory, how to make that script, maybe someone can give me example, im confusing coz i have to change form one user directory to other

Thank U.
# 2  
Old 07-01-2005
i presume u want to create file in each user's home directory

for i in `awk -F":" '{print $1}' /etc/passwd`
do
cd ~$i
touch <filename>
done

plz let me know if i had misunderstood anything
# 3  
Old 07-01-2005
Code:
cut -d: -f6 /etc/passwd |
grep -v nologin |
grep /home | #site specific
while read dir; do
    cd $dir && echo touch file
done

# 4  
Old 07-01-2005
Thank U for your script.
Now i want to change owner of filename become the user's
Here is my script, but the owner of file is still a root.
1. #!/bin/sh
cut -d: -f6 /etc/passwd | grep -v nologin | grep /home |
while read dir;
do
cd $dir && echo
touch filename
export dir=$dir
cut -d: -f3 /etc/passwd | grep -v nologin | grep /home |
while read user;
do
cd $dir && echo
chown $user filename
done
done

2. How to delete files that 1 week old.

Would you give me advise, Im sorry,and Thank you.

Regards,
Cleks
# 5  
Old 07-01-2005
Quote:
Originally Posted by matrixmadhan
i presume u want to create file in each user's home directory

for i in `awk -F":" '{print $1}' /etc/passwd`
do
cd ~$i
touch <filename>
done

plz let me know if i had misunderstood anything
just add one line to matrixmadhan's script:

Code:
for i in `awk -F":" '{print $1}' /etc/passwd`
do
cd ~$i
touch <filename>
chown $i <filename>
done

# 6  
Old 07-04-2005
Thank U for the answer before, I need some help more, now im just wanna make a file in each user's directory, im confusing coz some user have a different group
ex : marketing, user, etc. maybe someone can give me advice, Thank You. Here's my script:

#!/bin/sh

for i in `awk -F":" '{print $1}' /etc/passwd |grep -v nologin |grep /home`
do
cd $i
touch filename
# for j in `awk -F":" '{print $3' /etc/passwd` # This is the idea, but it's wrong (wont' working)
# for k in `awk -F":" '{print $4' /etc/passwd`
# do
# do
# chown $j:$k /home/$i/filename
# done
# done
done
# 7  
Old 07-05-2005
Well, here goes:

Code:
while read line; do
   user=`echo $line | cut -d':' -f3`
   group=`echo $line | cut -d':' -f4`
   cd ~$user
   touch <filename>
   chown $user:$group <filename> # this will change the group ownership of the file to the user's primary group
done < /etc/passwd

Guys, if anyone can make this more efficient, please do!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

2. Shell Programming and Scripting

Create a folder under different user directory

Hello All, I have to write a shell script and use it in informatica. The script has to perform below actions: The script gets executed from edw user. Through the script, a DT folder has to be created under edw_sca user. Is this scenario possible through a SHELL script or not. ... (2 Replies)
Discussion started by: bghosh
2 Replies

3. Red Hat

Create same file name to directory name without dropping it

Hi, Under '/home' directory, there is one file called 'maddy'.Usually there used to be directories under /home directory. # ls -alrt total 132 drwx------ 2 hcladmin sys 4096 May 30 10:54 admin drwxr-xr-x 29 root root 4096 Aug 27 03:54 .. drwx------ 2 v6admin dba ... (3 Replies)
Discussion started by: Maddy123
3 Replies

4. Shell Programming and Scripting

How to create a log file that simply shows the name of a file and what directory it was moved to.

Newbie...Thank you for your help. I am creating my first script that simply generates subdirectories to organize video, music, and text files within those subdirectories from my current working directory. PROBLEM: I am trying to write a log file that contains, for each file, the original file... (0 Replies)
Discussion started by: BartleDoo
0 Replies

5. Solaris

Unable to create or delete a directory in /usr with root user

Hi All, I am trying to uninstall jdk 1.5 from my Solaris 10 64 bit but some how was not successful.so tried to delete the folder of jdk from /usr but its throughing error as: Unable to remove directory jdk: Read-only file system Even I tried to create a dir in /usr but its not allowing me... (4 Replies)
Discussion started by: Pshah
4 Replies

6. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

7. UNIX for Dummies Questions & Answers

create a file inside a directory

create a file inside a directory in one command like current directory is root i want to create a directory inside root and a file inside that directory is there any command like touch /d/d.txt d directory does not exist (1 Reply)
Discussion started by: abhisheklodha13
1 Replies

8. Solaris

create user with RWX access to a specific directory in Solaris 10

I need to create a user account for a developer that will allow him rwx access to all resources in a directory. How can I do that? Thanks (5 Replies)
Discussion started by: gsander
5 Replies

9. Shell Programming and Scripting

How to create a directory inside root as different user

Hi All, I have directory under /opt/test. The ownership of the test directory is root:root. I have login to the server as test user. I need to have some script to create a directory inside /opt/test. This script will be called as test user. When I try to execute... (4 Replies)
Discussion started by: kalpeer
4 Replies
Login or Register to Ask a Question