#!/bin/bash # Jack-Benny Persson # LX13 # Exercise 7 lab 8 (Write a script to show logged in users in a HTML table # Binaries Awk="/usr/bin/awk" Sed="/bin/sed" Printf="/usr/bin/printf" Who="/usr/bin/who" # Variables Outfile="/home/jake/loggedin.html" # Sanity check if [ ! -w `dirname $Outfile` ]; then echo "Can't write to `dirname $Outfile`" exit 1 fi for Bin in $Awk $Sed $Printf $Who; do if [ ! -x $Bin ]; then echo "Can't execute $Bin" exit 1 fi done ### Main ### exec 1> $Outfile # Print the HTML header for us $Printf "
User | TTY | Date" $Printf " | Time | \n" $Printf ""; ORS="\n |
/' | sed '/[0-9]$/s/$/<\/td>/' | sed '$d' # End the table and HTML $Printf " |