Advertisement
dzocesrce

[OS] Time Logged in

Jan 22nd, 2024
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.60 KB | None | 0 0
  1. #!/bin/bash
  2. #almost the same as the auditorium one
  3. if [ $# -ne 3 ]
  4. then
  5.     echo "USAGE: `basename $0` index month day"
  6.     exit 1
  7. fi
  8. INDEX=$1
  9. MONTH=$2
  10. DAY=$3
  11. #just like grep, with sed /p with can print the lines that contain the ceratin string with -n meaning printing only the lines of interest
  12. time_logged_in=`last | grep ^$INDEX | sed -n '/$MONTH *$DAY /p' | awk 'print $10' | sed -e 's/(//' -e 's/)//' | awk -F: 'BEGIN {time=0} {time+=60*$1+$2} END {print time}' `
  13. if [ -d loggedin.txt ]
  14. then
  15.     rm loggedin.txt
  16. fi
  17. touch loggedin.txt
  18. echo "$time_logged_in" >> loggedin.txt
  19. cat loggedin.txt
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement