Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Permissions - passing a file as the argument

  • 10-09-2007 12:07PM
    #1
    Closed Accounts Posts: 91 ✭✭


    this is the only way i can think of to do this but there must be a better way or else im gonna end up writing 200 lines of copy and pasting code.


    echo ' READ WRITE EXECUTE'


    own=$(ls -al $1 |cut -c2)

    if ($own==r) then
    first=yes
    else
    first=no
    endif
    echo $first



    Im writing a script that takes a file as an argument and it basically checks the permissions the owner and group and everbody has for the file passed in.
    I need the output to look something like this

    READ WRITE EXECUTE
    OWNER LEE.BALLANCORE YES YES NO
    GROUP USERS YES NO NO
    EVERYBODY NO NO NO


Comments

  • Closed Accounts Posts: 91 ✭✭magnia


    i got this to work but not exactly the way i wanted it to. can anyone think of how to improve it?


    #!/bin/bash

    echo ' r w x'

    own=$(ls -al $1 |cut -c2)
    if [ $own = "r" ] ; then first=y; else first=n; fi
    # echo $own

    own1=$(ls -al $1 |cut -c3)
    if [ $own1 = "w" ] ; then second=y ; else second=n; fi
    # echo $own1

    own2=$(ls -al $1 |cut -c4)
    if [ $own2 = "x" ] ; then third=y; else third=n; fi
    # echo $own2
    echo OWNER $first $second $third

    own3=$(ls -al $1 |cut -c5)
    if [ $own3 = "r" ] ; then fourth=y; else fourth=n; fi
    #echo $own3

    own4=$(ls -al $1 |cut -c6)
    if [ $own4 = "w" ] ; then fifth=y; else fifth=n; fi
    #echo $own4

    own5=$(ls -al $1 |cut -c7)
    if [ $own5 = "x" ] ; then sixth=y; else sixth=n; fi
    # echo $own5
    echo GROUP $fourth $fifth $sixth

    own6=$(ls -al $1 |cut -c8)
    if [ $own6 = "r" ] ; then seventh=y; else seventh=n; fi
    #echo $own6

    own7=$(ls -al $1 |cut -c9)
    if [ $own7 = "w" ] ; then eighth=y; else eighth=n; fi
    #echo $own7

    own8=$(ls -al $1 |cut -c10)
    if [ $own8 = "x" ] ; then ninth=y; else ninth=n; fi
    #echo $own8
    echo OTHER $seventh $eight $ninth


  • Registered Users, Registered Users 2 Posts: 1,421 ✭✭✭Steveire


    Can you use python? The stat module might be useful.

    http://www.ibm.com/developerworks/aix/library/au-python/


Advertisement