Questions regarding Bash Scripting.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • njames
    New Member
    • Jun 2007
    • 2

    Questions regarding Bash Scripting.

    i have some doubts regarding bash scripting ,

    1) i need to display permission of a given file in the following format :

    Owner :

    Read
    Write

    Group :

    Read
    Write

    Others :

    Read
    Execute


    so i wrote this code :

    Code:
    echo -n "Enter Filename : " ; read fname ;
    
    # check if file exists
    if [ -e $fname ]
    then
    	 
    #display fap for owner 
    
    	echo "Owner"
    
    	ls -l $fname|awk  '{print $1 }' |tee temp | cut -c2-4
    
    #display fap for group users
    	
    	echo "Group"
    
    	cat temp | cut -c5-7
    
    #display fap for other users
    
    	echo "Other"
    	
    	cat temp | cut -c8-10
    else
    	echo "FIle does not exist"
    fi
    the output i get is :

    Code:
    Owner 
    rwx
    Group
    r-x
    Others
    r--
    i want to print the words "Read" "Write" "Execute" instead of 'rwx'. If it were only for the owner , i could use the test command and -r, -w, -x options but that doesnt work for Group and Other users, how do i do that ?



    2) i need to delete all duplicate files ,

    so i wrote this,

    Code:
    find .  -maxdepth 1 -type f  -print0 | xargs -0 md5sum | sort | uniq -w 32 -c  | awk '{ print $1, $3 }' | find -ok rm {} \;
    but it is incomplete, it deletes all files , which means even the original file would be lost.


    3) Need to check if any user has logged-in more than once in different terminal, then display the no. of instances of that login.

    Sorry , no code tried for this one. I dont know where to start from.


    4) And im trying to display files that have been created today ,

    as i understand , unix keeps the track of files by the modification date and doesn't store the creation date, so how do i accomplish this task.


    i have tried my best to solve these doubts by reading numerous tutorials . but still couldn't find my answers. Please help.

    Thanks for reading the post.
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    I will give you as much info as I know.

    1) Regular expressions would be a good choice for this task. sed will probably work well.

    3) Take a look at the w, who, and finger commands

    4) Take a look at this thread to learn about determining the age of a file.

    Comment

    Working...