OS - 2021/22 - DN02 - resitev Starc Aljaz¶
DN2a¶
#!/bin/bash
set -euo pipefail
PRINT_PATHS=0
for i in "${@}"
do
if [[ "$i" == "-p" ]]; then PRINT_PATHS=1; fi
done
for i in "${@}"
do
if [[ "$i" != "-p" ]]; then
BINARY=$(ps -efo command= $i | awk '{print $1}')
printf "$i $(ls -la $BINARY | awk '{ print $5 }')"
if [[ $PRINT_PATHS == 1 ]]; then echo " $BINARY"
else echo ""
fi
fi
done
DN2b¶
#!/bin/bash
set -euo pipefail
for i in $(pidof $1); do
ps -p $i -o pid=,command= | awk '{printf $1" "; for (i=3; i<=NF; i++) printf $i" "; print ""; }'
done
DN2c¶
#!/bin/bash
set -euo pipefail
while true; do
printf "Vnesite ime procesa: "
read vpis
if [[ -z "$(pidof $vpis)" ]]; then
echo "-"
else
echo "OBSTAJA"
fi
done
DN2d¶
#!/bin/bash
set -euo pipefail
declare -A WEIGHTS
declare -A COUNTS
for NAME in "${@:2}"; do
WEIGHTS[$NAME]=0
COUNTS[$NAME]=0
while read MATCH; do
WEIGHTS[$NAME]=$((${WEIGHTS[$NAME]} + $(echo $MATCH | rev | cut -d' ' -f1 | rev)))
COUNTS[$NAME]=$((${COUNTS[$NAME]} + 1))
done <<< $(cat $1 | grep --line-buffered -Po "$NAME[^,.]+?([0-9]{2,3})")
# https://regex101.com/r/obyIwQ/1
done
for NAME in $(echo ${!WEIGHTS[@]} | tr " " "\n" | sort); do
echo "$NAME $((${WEIGHTS[$NAME]} / ${COUNTS[$NAME]}))"
done
Zadnja posodobitev:
May 15, 2022