1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Questions regarding Bash Scripting.

Discussion in 'Unix' started by jimmy, Jun 4, 2007.

  1. jimmy

    jimmy New Member

    Joined:
    Jun 4, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    You are the best
     

Share This Page