I have revised my log file viewing script SLAVE to better serve the security issues brought up by my first version. I decided to start a new thread as this version need not be red flagged for any security issues.
Here are the high points of the new script:
- Start script as normal user only. Script will re-curse itself with the sudo command.
- Script now has NINE log files you can view using the bash less command.
- The script is designed to work on a 80x25 line terminal, starting in the top left corner.
- You can save the script file as any name you wish, but internally it will be called SLAVE.
To create the SLAVE script file, highlight all of the text in the next CODE window, start kwrite or other suitable text editor and save the text as the file “slave” in your /home/username/bin folder.
#!/bin/bash
# SLAVE - SuSE Logfile Automated Viewer Engine - Version 2.00
# This script file was written to allow you to view nine log files located in /var/log & your home area
# Slave will ask for your user password, do not start slave as a root user.
# Custom Written for the openSUSE forums on 8-8-2010
PROG=" S.L.A.V.E. - SuSE Logfile Automated Viewer Engine - Version: 2.00 "
# Determine program user, save home folder location, request root password
if "$1" == "" ] ;
then
if "$HOME" == "/root" ] ;
then
echo ""
echo "Do Not Start Slave as a Root User...."
echo "Your Home Area must be saved first..."
echo "Slave will request your password....."
echo ""
exit 1
fi
echo ""
echo "$0:" " Will Require that you enter the root user Password to access most of your system log files."
echo ""
sudo "$0" "$HOME"
exit 0
fi
USER="$1"
# Menu Disply System function
# Display up to 9 menu items and 0 is always Exit
# Menu must have at least two choices plus exit
function print_menu {
# You can adjust the starting position of the Slave menu.
# Using s_line=0 & s_col=0 would place the menu in the top left corner of your screen"
# Starting Terminal Line Number for menu
s_line=0
# Starting Terminal Column Number for Menu
s_col=0
# Display Program Title
tput clear
tput cup $(( s_line )) $(( s_col ))
tput setf 7
tput setb 2
tput bold
echo "$1"
# Fetch kernel version to display
uname -r > ~/kernel.dat
read kernel < ~/kernel.dat
rm ~/kernel.dat
# Display Menu, Present User home, kernel version
tput sgr0
tput cup $(( s_line + 2 )) $(( s_col ))
tput setf 7
tput setb 1
tput bold
echo "$2" "USER:$USER" " Kernel:$kernel" " "
# Display Option for Line 1 (required)
tput sgr0
tput cup $(( s_line + 4 )) $(( s_col ))
echo "$5"
# Display Option for Line 2 (required)
if $4 -ge 2 ] ; then
tput cup $(( s_line + 5 )) $(( s_col ))
echo "$6"
tput cup $(( s_line + 6 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 8 )) $(( s_col ))
fi
# Display Option for Line 3 (optional)
if $4 -ge 3 ] ; then
tput cup $(( s_line + 6 )) $(( s_col ))
echo "$7"
tput cup $(( s_line + 7 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 9 )) $(( s_col ))
fi
# Display Option for Line 4 (optional)
if $4 -ge 4 ] ; then
tput cup $(( s_line + 7 )) $(( s_col ))
echo "$8"
tput cup $(( s_line + 8 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 10 )) $(( s_col ))
fi
# Display Option for Line 5 (optional)
if $4 -ge 5 ] ; then
tput cup $(( s_line + 8 )) $(( s_col ))
echo "$9"
tput cup $(( s_line + 9 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 11 )) $(( s_col ))
fi
# Display Option for Line 6 (optional)
if $4 -ge 6 ] ; then
tput cup $(( s_line + 9 )) $(( s_col ))
echo "${10}"
tput cup $(( s_line + 10 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 12 )) $(( s_col ))
fi
# Display Option for Line 7 (optional)
if $4 -ge 7 ] ; then
tput cup $(( s_line + 10 )) $(( s_col ))
echo "${11}"
tput cup $(( s_line + 11 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 13 )) $(( s_col ))
fi
# Display Option for Line 8 (optional)
if $4 -ge 8 ] ; then
tput cup $(( s_line + 11 )) $(( s_col ))
echo "${12}"
tput cup $(( s_line + 12 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 14 )) $(( s_col ))
fi
# Display Option for Line 9 (optional)
if $4 -ge 9 ] ; then
tput cup $(( s_line + 12 )) $(( s_col ))
echo "${13}"
tput cup $(( s_line + 13 )) $(( s_col ))
echo "$3"
tput cup $(( s_line + 15 )) $(( s_col ))
fi
# Display menu option request and get user input
tput setaf 2
tput bold
read -p "Enter your choice [0-"$4"] " CHOICE
tput clear
tput sgr0
tput rc
return $CHOICE
}
# Log File Display Function, check file exists first
function print_log {
if ! -e $1 ]
then
echo "$1 is not Present!"
echo
read -p "Press <enter> to continue..."
else
less $1
fi
}
# Main Program Loop starts here ...
while true ; do
# Setup Menu string Fields displayed for your menu
MENU=" LOG FILE SELECTION - M E N U "
EXIT="0. Exit SLAVE *** When viewing log files enter H for help and Q to quit *** "
TOTL="9"
TST1="1. View boot.msg file - Messages from the kernel during the boot process. "
TST2="2. View messages file - Messages from the kernel and system log daemon. "
TST3="3. View warn file - Kernel and system log daemon assigned WARNING or higher."
TST4="4. View mail file - Messages from the mail system. "
TST5="5. View zypper.log file - Log file of zypper: command line package manager. "
TST6="6. View Xorg.0.log file - Startup and runtime logs from the X Window system."
TST7="7. View NetworkManager file - Log for problems with network connectivity. "
TST8="8. View mkinitrd.log file - Kernel RAM disk, initrd creation logfile errors."
TST9="9. View ~/.xsession-errors file - Messages from the desktop applications. "
# Call Menu and get user input selection
print_menu "$PROG" "$MENU" "$EXIT" "$TOTL" "$TST1" "$TST2" "$TST3" "$TST4" "$TST5" "$TST6" "$TST7" "$TST8" "$TST9"
choice="$?"
# Execute User Command Here
case "$choice" in
"1") tput clear
FILE="/var/log/boot.msg"
print_log $FILE ;;
"2") tput clear
FILE="/var/log/messages"
print_log $FILE ;;
"3") tput clear
FILE="/var/log/warn"
print_log $FILE ;;
"4") tput clear
FILE="/var/log/mail"
print_log $FILE ;;
"5") tput clear
FILE="/var/log/zypper.log"
print_log $FILE ;;
"6") tput clear
FILE="/var/log/Xorg.0.log"
print_log $FILE ;;
"7") tput clear
FILE="/var/log/NetworkManager"
print_log $FILE ;;
"8") tput clear
FILE="/var/log/YaST2/mkinitrd.log"
print_log $FILE ;;
"9") tput clear
FILE="$USER""/.xsession-errors"
print_log $FILE ;;
"0") exit 0 ;;
*) ;;
esac
done
exit 0
# End of Bash File
Once the text is saved, you must set the file as executable. You can do this with Dolphin, select the file properties and change it to executable or use the following KDE menu Run Command:
chmod +x ~/bin/slave
To run SLAVE simply open up a terminal session and type the command: slave
You can also create a menu entry for slave by selecting open in a terminal session. Do not run SLAVE as a root user or with the sudo command. It will not work. I ask that you let me know if you have any other concerns or wishes with this version of SLAVE.
Thank You,