Санкт-Петербургский Государственный Институт Точной Механики и Оптики

(Государственный Университет)

Лабораторная работа №3

по курсу «Многопользовательские ОС»

Студенты: Иванов

Колпаков

Группа: 354

Преподаватель: Афанасьев Д.Б.

Санкт-Петербург

2001

1. Задание.

Вывести всех пользователей, имеющих право чтения заданного файла.

2. Решение

#!/bin/sh

if test "$#" -eq 0

then

echo Usage: `basename $0` filename

exit

fi

file=$1

own_name=`ls -l $file | cut -d" " -f5`

own_group=`ls –l $file | cut -d: -fкакое_то_поле`

rights=`ls -l $file | cut -d" " -f1`

#getting user rights

#right_tmp=`ls -l $file | awk '{print substr($rights,2,1)}'`

right_tmp=`echo $rights | awk '{print substr($0,2,1)}'`

#if user have rights, output user

case $right_tmp in

r) echo $own_name;;

*) echo Owner can not read the file;;

esac

#getting groups rights

#right_tmp=`ls -l $file | awk '{print substr($rights,5,1)}'`

right_tmp=`echo $rights | awk '{print substr($0,5,1)}'`

case $right_tmp in

r)

for i in `niscat passwd.org_dir | awk -F: '{print $1}'`

do

groups $i | awk '/$own_group/ {if ("'$i'" != "'$own_name'") {print "'$i'"}}'

done

;;

*) echo Group can not read the file;;

esac

#getting all other rights

#right_tmp=`ls -l $file | awk '{print substr($rights,8,1)}'`

right_tmp=`echo $rights | awk '{print substr($0,8,1)}'`

case $right_tmp in

r)

for i in `niscat passwd.org_dir | awk -F: '{print $1}'`

do

groups $i | awk '!/$own_group/ {if ("'$i'" != "'$own_name'") {print "'$i'"}}'

:

done;;

*) echo Other can not read the file;;

esac