Advertisement
dzocesrce

[OS] Time spent on the OS Server

Jan 20th, 2024 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 0 0
  1. #!/bin/bash
  2. #if the number of arguments is not 1, as it should be, show USAGE message and exit.
  3. if [ $# -ne 1 ]
  4. then
  5.     echo "USAGE: `basename $0` br_indeks"
  6.     exit 1
  7. fi
  8. #Create a file with the given name, but delete it first if a file with that name already exists.
  9. if [ -f out.txt ]
  10. then
  11.     rm out.txt
  12. fi
  13. touch out.txt
  14. #select all the rows that start with the first argument
  15. #leave out their 10th column only
  16. #substitute the each brace type with empty space as we don't need them
  17. #make two dots as our new internal field separator and initialize the total variable to calculate total time spent on the OS server
  18. #send the calculation to our newly promoted script varible user_time
  19. user_time=`last | grep ^$1 | awk 'print $10;' | sed -e 's/(//' -e 's/)//' | awk -F: 'BEGIN {total=0;} {total+=$1*60+$2;} END {print total;}'`
  20. #send user_time'z value as a text for out.txt
  21. echo "$user_time" >> out.txt
  22. #list the text in out.txt on the console
  23. cat out.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement