Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.86 KB | None | 0 0
  1. getMonthIndex() {
  2.         months=("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")
  3.         i=0
  4.         while [ $i -le ${#months[@]} ]; do
  5.                 if [ "${months[$i]}" == "$1" ]; then
  6.                         (( i++ ))
  7.                         monthIndex=$i
  8.                         break
  9.                 fi
  10.                 (( i++ ))
  11.         done
  12. }
  13.  
  14. if [ $# -eq 0 ]; then
  15.         n=-1
  16. fi
  17.  
  18. while [ $# -gt 0 ]; do
  19.         case $1 in
  20.                 -h)
  21.                         echo ""
  22.                         echo "Meno programu (C) meno autora"
  23.                         echo "Usage: <meno_programu> <arg1> <arg2> ..."
  24.                         echo "<arg1>: xxxxxx"
  25.                         echo "<arg2>: yyyyy"
  26.                         n=-2;;
  27.                 -n)
  28.                         shift
  29.                         if [ $(echo $1 | grep -Ec '^[0-9]+$') -eq 0 ]; then
  30.                                 echo "Error: '-n': neplatna hodnota" > /dev/stderr
  31.                                 exit
  32.                         fi
  33.                         n=$1;;
  34.                 *)
  35.                         echo "Error: neplatny argument" > /dev/stderr
  36.                         exit;;
  37.         esac
  38.         shift
  39. done
  40.  
  41. IFS=$'\n'
  42. actualUser="x"
  43. counter=1
  44.  
  45. test() {
  46.         (( counter++ ))
  47.         if [ "$user" != "$actualUser" ]; then
  48.                 if [ $n -eq -1 ] || [ $counter -gt $n ]; then
  49.                         echo "$actualUser $counter"
  50.                 fi
  51.                 actualUser="$user"
  52.                 counter=0
  53.         fi
  54. }
  55.  
  56. if [ $n -gt -2 ]; then
  57.         for data in $(last | tail -r | tail -n +3 | grep -v 'still logged in$' | cut -c -10,43- | tr -s ' ' | sort -k 1); do
  58.                 user="$(echo $data | cut -d' ' -f1)"
  59.                 if [ "$actualUser" == "x" ]; then
  60.                         actualUser="$user"
  61.                 fi
  62.                 #month="$(echo $data | cut -d' ' -f3)"
  63.                 #getMonthIndex $month
  64.                 #month=$monthIndex
  65.                 #day="$(echo $data | cut -d' ' -f4)"
  66.                 timeFrom="$(echo $data | cut -d' ' -f5)"
  67.                 timeFromHours="$(echo $timeFrom | cut -d: -f1)"
  68.                 #timeFromMinutes="$(echo $timeFrom | cut -d: -f2)"
  69.                 timeTo="$(echo $data | cut -d' ' -f7)"
  70.                 timeToHours="$(echo $timeTo | cut -d: -f1)"
  71.                 timeToMinutes="$(echo $timeTo | cut -d: -f2)"
  72.  
  73.                 if [ $timeFromHours -ge 22 ] || [ $timeFromHours -le 5 ]; then
  74.                         if [ $timeToHours -ge 22 ] || [ $timeToHours -le 5 ]; then
  75.                                 if [ $timeToHours -eq 5 ] && [ $timeToMinutes -gt 0 ]; then
  76.                                         continue
  77.                                 fi
  78.                                 test
  79.                         fi
  80.                 fi
  81.         done
  82. fi
  83.  
  84. test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement