I have a bash script and tried very hard but i couldn't solve it please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I have a bash script and tried very hard but i couldn't solve it please help
# 1  
Old 10-19-2010
I have a bash script and tried very hard but i couldn't solve it please help

please can you help me with this script ( very very important )

what I'm trying is to write program that accepts list of user as its argument
1- If a user or more are given as arguments, the script should reset files permissions as follows:
a. Directory ~/share to 750 (if it exists).
b. All regular files inside ~/share to 744.
c. All directories inside ~/share to 750.
d. All other regular files in ~ to 600 and all other directories in ~ to 700.
e. files of other types are left as they are.

We assume that there is only one level of files and directories inside ~ (except for ~/share), and there is only one level of files and directories inside ~/share.

2- If no arguments are give, the script should identify normal users in the system (UID >= 500) and for each user, reset files permissions as described above.

3- At the end of the execution, the script must produce a file named report.txt that contains a list of all files in the user's home directory including full path, owner, group and permissions for each file.

please help me if you can
# 2  
Old 10-19-2010
Look very much homework...

What have you done so far?
# 3  
Old 10-19-2010
I am very new to Linux and this is what some friend of mine give me to test what I learn
and i tried very much to solve it but till now I couldn't do anything

Last edited by testman84; 10-19-2010 at 12:53 PM..
# 4  
Old 10-19-2010
All right, what have you tried then?
# 5  
Old 10-19-2010
Start with "man find" especially -type and -path, but not -exec.

Something like this is very durable and fast, one line for each situation:
Code:
find ... -type d | xargs -n 101 chmod 765

# 6  
Old 10-19-2010
Code:
[ -d ~/share ] && find ~/share -type f -print0 | while read -d $'\0' file
do
  # if $file exists and is a regular file
  [ -f "$file" ] && chmod 744 "$file"
done


Last edited by Scott; 10-19-2010 at 03:37 PM.. Reason: Added code tags
# 7  
Old 10-19-2010
Easy to match to spec and comment (case is nice that way, but use balanced parentheses so vi % is not disabled):
(Note: files in ~ like .profile, code, scripts no longer executable)

Code:
find ~ |while read p
do
 case "$p" in
 (~/share)
   chmod 750 "$p"
   ;;
 (~/share/*)
   if [ -f "$p" ];then
     chmod 744 "$p"
   else
     if [ -d "$p" ];then
       chmod 750 "$p"
     fi
   fi
   ;;
 (*)
    if [ -f "$p" ];then
     chmod 600 "$p"
   else
     if [ -d "$p" ];then
       chmod 700 "$p"
     fi
   fi
   ;;
 esac
done

This User Gave Thanks to DGPickett For This Post:
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 to solve query

Hi I have data in the below format in two columns in excel which i will copy to notepad. test as rec1, string test as rec2, byteint test as rec3, string update date as test, datetime name as tes2 string I need to add trim function on all the string columns and keep the remaining... (10 Replies)
Discussion started by: pisikar
10 Replies

2. Shell Programming and Scripting

How to solve hang issue in script?

i have one function block in the beginning of my script and there are some commands inside that function which will perform some operations. And i am invoking that function from my main script by passing some values. Sometimes it is hanging in the middle for some value. For example: For 1st... (3 Replies)
Discussion started by: thomasraj87
3 Replies

3. Shell Programming and Scripting

Script to solve second order (polynomial) interpolation

Currently I have awk command to do linear interpolation awk ' { P=$2 I=$1 } END { j=0; s=I; t=I for(i=m;i<=n;i++) { if(I && i>t) { j++; s=I; t=I } print i, P+(i-s)*(P-P)/(t-s) } } ' m=1 n=8 infile FILE CONTENT... (8 Replies)
Discussion started by: Tzeronone
8 Replies

4. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

5. Shell Programming and Scripting

Bash or awk script to solve this problem

Hi everybody! I have written some awk scripts that return me some results I need to process. At the moment I use openOffice to process them, but I am trying to find a more efficient solution using possibly a bash or awk script. I have two files, file1 is in the format: time position ... (3 Replies)
Discussion started by: Alice236
3 Replies

6. UNIX for Advanced & Expert Users

Help! SHELL or AWK script - only the masters of the forum will solve

Hello everybody! I have no experience with shell Programmer, but I need to compare 02 files. Txt and generate an output or a new file, after the comparisons. see: If the column 1 of file1 is equal to column 1 of file2, and column 3 of file2 contains the column 4 of file1, output: column1... (4 Replies)
Discussion started by: He2
4 Replies

7. Shell Programming and Scripting

Help me to solve some question about shell Script

Factorial calculation Example output: Please enter a non-negative number: 3 3! = 3 X 2 X 1 = 6 Please enter a non-negative number: 10 10! = 10 X 9 X 8 X 7 X 6 X 5 X 4 X 3 X 2 X 1 = 3628800 Please enter a non-negative number: -1 ... (1 Reply)
Discussion started by: cenco
1 Replies

8. Shell Programming and Scripting

Help me to solve some question about shell Script

Factorial calculation Example output: Please enter a non-negative number: 3 3! = 3 X 2 X 1 = 6 Please enter a non-negative number: 10 10! = 10 X 9 X 8 X 7 X 6 X 5 X 4 X 3 X 2 X 1 = 3628800 Please enter a non-negative number:... (1 Reply)
Discussion started by: cenco
1 Replies

9. Shell Programming and Scripting

Unix shell script couldn't be executed. Pls help!

I have wrriten a script to call sql script to do some work in database. However, the script couldn't be executed. The only information was: ksh: ./updt_attrib.ksh cannot execute. Please help me to identify where the problem is. I post script here for your reference. Thanks a lot. #!/bin/ksh ... (8 Replies)
Discussion started by: duke0001
8 Replies
Login or Register to Ask a Question