I have a course work questio which i like some input on, i have achieved the desired out put but the main problem is the script should be 15 lines and mine is 20 :(
That said i know it can be done in far less using sed and awk, but cant use them at all for this question. can you guys please read through my script and give me suggestions please. i have tried two scripts:
FIRST SCRIPT
the out put is as follow:
READ WRITE EXECUTE
owner keyvan.ahmadi yes yes no
group yes no no
everybody yes no no
the only problem with above script as i already mentioned is, its 20 lines and it needs to be 15 lines.
SCRIPT 2
Now the second script has two problems
1- well it dosent work :) and when run it gives the following output:
READ WRITE EXECUTE
owner 52 yes
2- its 16 lines even if it worked which it dosent :(
As i have said before i have managed to do it using sed & awk:
But i cant use it, beacuse my lecturer throw a temper tantrum at me and look at me as i have just killed his fav pet or something.
So any help guys & gals will be greatly appriciated.
keyvan
That said i know it can be done in far less using sed and awk, but cant use them at all for this question. can you guys please read through my script and give me suggestions please. i have tried two scripts:
FIRST SCRIPT
Code:
#!/bin/bas int=1 user=$(ls -l $1 | cut -d " " -f3) echo " READ WRITE EXECUTE" while [ $int -le 9 ] do int=$[$int+1] case "$int" in 2)echo -n "owner $user " ;; 5)echo echo -n "group " ;; 8)echo echo -n "everybody " ;; esac perm=$(ls -l $1 | cut -c$int) case "$perm" in -)echo -n "no " ;; *)echo -n "yes " ;; esac done
READ WRITE EXECUTE
owner keyvan.ahmadi yes yes no
group yes no no
everybody yes no no
the only problem with above script as i already mentioned is, its 20 lines and it needs to be 15 lines.
SCRIPT 2
Code:
#!/bin/bash int=1 for perm in `ls -l $1|cut -c2, 3,4,5,6,7,8,9,10 --output-delimiter " "` do case "$int" in 1)echo -n -e "READ WRITE EXECUTE\nowner `ls -l $1 | cut -d " " -f5` " ;; 4)echo -n -e "\ngroup `ls -l $1 | cut -d " " -f4` " ;; 7)echo -n -e "\neverybody " ;; esac case "$perm" in -)echo -n "no " ;; *)echo -n "yes " ;; esac done echo
1- well it dosent work :) and when run it gives the following output:
READ WRITE EXECUTE
owner 52 yes
2- its 16 lines even if it worked which it dosent :(
As i have said before i have managed to do it using sed & awk:
Code:
#!/bin/bash
if [ -f $1 ]
then
ls -l $1 | sed -e '1,9s/x/YES /g;1,9s/w/YES /g;1,9s/-/NO /g;1,9s/r/YES /g' | awk -F' ' '{print "\t\t\tREAD\tWRITE\tEXECUTE\nOWNER "$12"\t"$2"\t"$3"\t"$4"\nGROUP "$13"\t\t"$5"\t"$6"\t"$7"\nEVERYBODY\t\t"$8"\t"$9"\t"$10}' > Report
else
:
echo "Cannot find file."
fi
So any help guys & gals will be greatly appriciated.
keyvan
Comment