Скачиваний:
9
Добавлен:
09.05.2014
Размер:
5.54 Кб
Скачать
#/usr/bin/bash

#lab3

echo "print file name..."
read file_name


if user_per=$(ls -l "$file_name" | awk '{print substr($1,2,1)}' | tee system_3.log)
then
:
else
echo "file $file_name doesnt exist" | tee script_3.log
fi
group_per=$(ls -l "$file_name" | awk '{print substr($1,5,1)}')
other_per=$(ls -l "$file_name" | awk '{print substr($1,8,1)}')

if [[ "$user_per" = "r" && "$group_per" = "r" && "$other_per" = "r" ]] # rrr
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
cat /etc/passwd nispasswd | awk -F: '{print $1}' # all users

elif [[ "$user_per" = "r" && "$group_per" = "r" && "$other_per" = "-" ]] # rr-
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}' | tee -a script_3.log)
tmp_gr=$(ls -l "$file_name" | awk '{print $4}' | tee -a script_3.log)
tmp_idgr=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $3}' | tee -a script_3.log)
declare -i i
declare -i tmp_grlistnum
tmp_grlistnum=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print NF}')
tmp_grlistnum=tmp_grlistnum+1
i=1
while [ "$i" != "$tmp_grlistnum" ]
do
cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '$'"$i"'!~'"/^$tmp_us"'$/{print $'"$i"'}'
i=i+1
done
echo "root"
if [[ "$tmp_us" != "root" ]]
then
echo "$tmp_us"
fi
cat /etc/passwd nispasswd | awk -F: '$1!~'"/^root"'$/{print}' |awk -F: '$1!~'"/^$tmp_us"'$/{print}' | awk -F: '$4~'"/^$tmp_idgr"'$/{print $1}'

elif [[ "$user_per" = "r" && "$group_per" = "-" && "$other_per" = "-" ]] # r--
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}' | tee -a script_3.log)
echo "root"
if [[ "$tmp_us" != "root" ]]
then
echo "$tmp_us"
fi

elif [[ "$user_per" = "-" && "$group_per" = "-" && "$other_per" = "-" ]] # ---
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
echo "root"

elif [[ "$user_per" = "-" && "$group_per" = "r" && "$other_per" = "-" ]] # -r-
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}' | tee -a script_3.log)
tmp_gr=$(ls -l "$file_name" | awk '{print $4}' | tee -a script_3.log)
tmp_idgr=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $3}' | tee -a script_3.log)
declare -i i
declare -i tmp_grlistnum
tmp_grlistnum=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print NF}')
tmp_grlistnum=tmp_grlistnum+1
i=1
while [ "$i" != "$tmp_grlistnum" ]
do
cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '$'"$i"'!~'"/^$tmp_us"'$/{print $'"$i"'}'
i=i+1
done
echo "root"
cat /etc/passwd nispasswd | awk -F: '$1!~'"/^root"'$/{print}' | awk -F: '$1!~'"/^$tmp_us"'$/{print}' | awk -F: '$4~'"/^$tmp_idgr"'$/{print $1}'

elif [[ "$user_per" = "-" && "$group_per" = "-" && "$other_per" = "r" ]] # --r
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}' | tee -a script_3.log)
tmp_gr=$(ls -l "$file_name" | awk '{print $4}' | tee -a script_3.log)
tmp_idgr=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $3}' | tee -a script_3.log)
declare -i tmp_grlistnum
tmp_grlistnum=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print NF}')
declare -i i
i=0
while [ "$i" != "$tmp_grlistnum" ]
do
i=i+1
tmp_grlist[$i-1]=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print $'"$i"'}')
done
cat /etc/passwd nispasswd | awk -F: '$1!~/^'"root"'/{print}' | awk -F: '$1!~/^'"$tmp_us"'/{print}' | awk -F: '$4!~/^'"$tmp_idgr"'/{print}' > $HOME/tmpfile
i=0
while [ "$i" != "$tmp_grlistnum" ]
do
cat $HOME/tmpfile | awk -F: '$1!~/^'"${tmp_grlist[$i]}"'/{print}' > $HOME/tmpfile
done
cat $HOME/tmpfile | awk -F: '{print $1}'
echo "root"
rm -f $HOME/tmpfile

elif [[ "$user_per" = "r" && "$group_per" = "-" && "$other_per" = "r" ]] # r-r
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}' | tee -a script_3.log)
tmp_gr=$(ls -l "$file_name" | awk '{print $4}' | tee -a script_3.log)
tmp_idgr=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $3}' | tee -a log_lab3)
declare -i tmp_grlistnum
tmp_grlistnum=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print NF}')
declare -i i
i=0
while [ "$i" != "$tmp_grlistnum" ]
do
i=i+1
tmp_grlist[$i-1]=$(cat /etc/group nisgroup | awk -F: "/^$tmp_gr/"'{print $4}' | awk -F, '{print $'"$i"'}')
done
cat /etc/passwd nispasswd | awk -F: '$1!~/^'"root"'/{print}' | awk -F: '$1!~/^'"$tmp_us"'/{print}' | awk -F: '$4!~/^'"$tmp_idgr"'/{print}' > $HOME/tmpfile
i=0
while [ "$i" != "$tmp_grlistnum" ]
do
cat $HOME/tmpfile | awk -F: '$1!~/^'"${tmp_grlist[$i]}"'/{print}' > $HOME/tmpfile
done
cat $HOME/tmpfile | awk -F: '{print $1}'
echo "$tmp_us"
if [[ "$tmp_us" != "root" ]]
then
echo "root"
fi
rm -f $HOME/tmpfile

elif [[ "$user_per" = "-" && "$group_per" = "r" && "$other_per" = "r" ]] # -rr
then
echo 'file read permissions: '"$user_per$group_per$other_per" > script_3.log
tmp_us=$(ls -l "$file_name" | awk '{print $3}'| tee -a script_3.log)
cat /etc/passwd nispasswd | awk -F: '$1!~'"/^$tmp_us/"'{print}' | awk -F: '{print $1}'
if [[ "$tmp_us" = "root" ]]
then
echo "root"
fi
fi





Соседние файлы в папке задание №3 — 4