S.L.A.V.E. - SuSE Logfile Automated Viewer Engine - Version 2.00

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:

  1. Start script as normal user only. Script will re-curse itself with the sudo command.
  2. Script now has NINE log files you can view using the bash less command.
  3. The script is designed to work on a 80x25 line terminal, starting in the top left corner.
  4. 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,

The usage of $0 to restart yourself would have been my solution. Congrats.

Very good. I like it that way.

The only “serious bug” lol! I found: when I exit it leaves me with a green cursor.

Thanks guys for your response it is nice to know that more than one person thinks the script is useful.

To get rid of the green cursor on program exit change the following code:

  "0") exit 0 ;;
  *) ;; 

To:

  "0") tput clear 
       exit 0 ;;
  *) ;;

If there is ANY reason to add or change the log files being viewed, just let me know. I did look at using the tail -f command, but I never figured out how that could be fitted into this program. But I will look at it more for the future. Lastly, the verbage I used when you login with your password is too long and wordy and it should be reduced. If I post a newer version in the future, I will make that change.

Also consider that any user here can make a change and post it here with what is good about their modifications. The whole idea in my mind is to do something useful, like viewing openSUSE log files, while learning how to write bash script files. Here, we can all help each other.

Thank You,

If there is ANY reason to add or change the log files being viewed, just let me know.

Just for my personal use: I included the apache logfiles because I check them quite often.

So vodoo I don’t use apache. I have an apache folder, but no files within. If you added them to slave in lue of log files you don’t need, that was indeed the intent of my post here.

I have modified my older fewrup script, which was used to edit system files using kdesu in a file manage without root permissions, to instead use “sudo list” for root owned logfiles you wist to view with bash list. So, you can right click on the file, if you can see it and pick logview, like you might pick kwrite, from your file manager menu. It works for system files and non system files, as long as you can see the folder contents as a normal user.

It is something else I could post here, though every time a script needs a root password, it seems like I get some kind of grief over it even though I don’t have anything to do with files being assigned to root that a standard user needs to look at.

Thank You,

Whoa! Never blindly write to(or remove) any file as root! It might be a symlink.


@@ -55,5 +55,3 @@
 # Fetch kernel version to display
-uname -r > ~/kernel.dat
-read kernel < ~/kernel.dat
-rm ~/kernel.dat
+kernel=$(uname -r)

The code section in question is reading the kernel version to a file, which I create, reading it back in as a variable, then removing the file I just created, all in the home area of root.

# Fetch kernel version to display
uname -r > ~/kernel.dat
read kernel < ~/kernel.dat
rm ~/kernel.dat

This allows placing the kernel version on the same line as other information and not on a line by its self. This bit of code and the reference to $kernel can be removed if you so desire.

Thank You,

Yes, but why create/write/delete a file, when you can set the variable directly from the output of uname?

kernel=$(uname -r)

does all this in one line.

This works like a champ GeoBaltz, thanks for the tip. The master copy is changed should I re-post it again. The snippet change is as follows:

# Fetch kernel version to display

# uname -r > ~/kernel.dat
# read kernel < ~/kernel.dat
# rm ~/kernel.dat

kernel=$(uname -r)

I remarked out the three original lines and made your addition just after them.

Thank You,

I have just revised SLAVE to view five more log files, for a total of 14 now. After modifying the menu display function for mmcheck, I am now using the same new function to display the SLAVE menu as well. As always, if you have any suggestions or problems with SLAVE, please let me know.

Just as before, copy and past the text in the following code block into a text file and save it in your home area as the file slave (~/bin/slave).

#!/bin/bash

#: Title       : SLAVE - SuSE Logfile Automated Viewer Engine - Version 2.10
#: Date Created: Sun Aug 08 20:20:31 CDT 2010
#: Last Edit   : Sat Oct 30  8:56:03 CDT 2010
#: Author      : J. McDaniel
#: Version     : 2.10
#: Description : openSUSE Log File Viewer
#: Options     : none

# This script file was written to allow you to view 14 log files located in /var/log & your home area
# Slave will ask for your root user password, do not start slave as a root user.

# Custom Written for the openSUSE forums on Saturday October 30, 2010

# Copy and paste this text as the file slave into the ~/bin folder.
# Run the terminal command: chmod +x ~/bin/slave, to make the file executable
# Open up a terminal session and type: slave, to start the program

PROG=" S.L.A.V.E.   -   SuSE Logfile Automated Viewer Engine   -   Version: 2.10 "

# 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 "Root User Permissions are required, Please Enter the ..."
    echo
    sudo "$0" "$HOME"
    exit 0
fi

USER="$1"

# Menu Disply System function
# Display up to $3 menu items and <enter> is always Exit 
# Menu should have at least two choices plus exit

function print_menu {

# You can adjust the starting position of the mmcheck 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"

# Determine Kernel Version
kernel=$(uname -r)

# 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   " 
tput sgr0

# Display All Menu Options 1 through $3
maxnum=$3
counter=0

while  $(( counter )) -lt $(( maxnum + 1 )) ] ; do
  let counter=counter+1
  tput cup $(( s_line + 3 + counter )) $(( s_col ))
  echo "$4"
  shift
done

# Display menu option request and get user input
tput setf 7
tput setb 4
tput bold
tput cup $(( s_line + 4 + counter )) $(( s_col ))
echo "All Log Files are being Viewed using the CLI LESS Command: Q=Quit & H=Help "
tput setf 2
tput setb 0
tput bold
tput cup $(( s_line + 6 + counter )) $(( s_col ))
read -p "Enter Your Choice [1-"$maxnum"]  OR  Just Press <enter> to Quit S.L.A.V.E.: " CHOICE
tput clear
tput sgr0
tput rc
return $CHOICE
}

# Log File Display Function, check if file exists first

function print_log {

if  ! -e $1 ]
  then
    echo "$1 is not Present!"
    echo
    read -p "Press <enter> to continue..."
  else
    tput clear
    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 "
TOTL="14" 
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 localmessages file - Messages from the kernel and system log daemon."
TST4="4 . View warn file - Kernel and system log daemon assigned WARNING or higher."
TST5="5 . View mail file - Messages from the mail system.                          "
TST6="6 . View mail.info file - Messages from the mail system.                     "
TST7="7 . View zypper.log file - Log file of zypper: command line package manager. "
TST8="8 . View Xorg.0.log file - Startup and runtime logs from the X Window system."
TST9="9 . View NetworkManager file - Log for problems with network connectivity.   "
TSTA="10. View mkinitrd.log file - Kernel RAM disk, initrd creation logfile errors."
TSTB="11. View  ~/.xsession-errors file - Messages from the desktop applications.  "
TSTC="12. View /var/log/samba/log.smbd - Samba smbd message file.                  "
TSTD="13. View /var/log/samba/log.nmbd - Samba nmbd message file.                  "
TSTE="14. View /var/log/samba/log.swat - Samba swat message file.                  "

# Call Menu and get user input selection

print_menu "$PROG" "$MENU" "$TOTL" "$TST1" "$TST2" "$TST3" "$TST4" "$TST5" "$TST6" "$TST7" "$TST8" "$TST9" "$TSTA" "$TSTB" "$TSTC" "$TSTD" "$TSTE"
choice="$?"

# Execute User Command Here

case "$choice" in

  "1") FILE="/var/log/boot.msg"
  print_log $FILE ;;

  "2") FILE="/var/log/messages"
  print_log $FILE ;;

  "3") FILE="/var/log/localmessages"
  print_log $FILE ;;

  "4") FILE="/var/log/warn"
  print_log $FILE ;;

  "5") FILE="/var/log/mail"
  print_log $FILE ;;
 
  "6") FILE="/var/log/mail.info"
  print_log $FILE ;;

  "7") FILE="/var/log/zypper.log"
  print_log $FILE ;;

  "8") FILE="/var/log/Xorg.0.log"
  print_log $FILE ;;

  "9") FILE="/var/log/NetworkManager"
  print_log $FILE ;;

  "10") FILE="/var/log/YaST2/mkinitrd.log"
  print_log $FILE ;;

  "11") FILE="$USER""/.xsession-errors"
  print_log $FILE ;;

  "12") FILE="/var/log/samba/log.smbd"
  print_log $FILE ;;

  "13") FILE="/var/log/samba/log.nmbd"
  print_log $FILE ;;

  "14") FILE="/var/log/samba/log.swat"
  print_log $FILE ;;

  "0") tput clear
    exit 0 ;;
  *) ;;

esac

done 
exit 0

# End of Bash File

Next, you need to mark the slave script as executable. Open a terminal session and run this command:

chmod +x ~/bin/slave

Finally, to use slave, open another terminal session and type the command:


slave

You can create an icon on your desktop to run slave by doing the following tasks. Open a text editor and copy the following text in and then save the file as slave.desktop in your home area Desktop folder (~/Desktop/slave.desktop).

[Desktop Entry]
Comment[en_US]=
Comment=
Exec=~/bin/slave
GenericName[en_US]=Log File Viewer
GenericName=Log File Viewer
Icon=Terminal
MimeType=
Name[en_US]=Slave
Name=Slave
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=
X-SuSE-translate=true

Once saved in the right place with the correct name an icon should appears on your desktop called slave. I picked an icon with a big S on it, but you could change it to anything you wanted.

Thank You,

Nice Advent,jdmcdaniel3 !

Just want to confirm you in your work here!Nice,to have a slave at ones side,
doing the dirty jobs!I`m not able to take too much advantage from the logs,yet.
But regarding something perhaps unusual “on the fly”,can save (virtual) life!
But,which “menu-entry” do you mean,and how can I get one,by opening what?
Thanks for spending your time to support our laziness!

Greetings!

lostinspace

Nice Advent,jdmcdaniel3 !

Just want to confirm you in your work here!Nice,to have a slave at ones side,
doing the dirty jobs!I`m not able to take too much advantage from the logs,yet.
But regarding something perhaps unusual “on the fly”,can save (virtual) life!
But,which “menu-entry” do you mean,and how can I get one,by opening what?
Thanks for spending your time to support our laziness!

Greetings!

lostinspace
So, if you would like an icon on your desktop that runs slave, you can create one by doing a copy and paste of the text in the code block into your favorite text editor and saving the file as slave.desktop into your Desktop folder. I use KDE and I use Folder view which allows this to work. Not sure how you do this in gnome.

[Desktop Entry]
Comment[en_US]=
Comment=
Exec=~/bin/slave
GenericName[en_US]=Log File Viewer
GenericName=Log File Viewer
Icon=Terminal
MimeType=
Name[en_US]=Slave
Name=Slave
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=
X-SuSE-translate=true

Having a desktop icon is not required to run salve, but if you make one, you do not need to open a separate terminal session to run salve.

Thank You,

Hi jdmcdaniel3 !

The hints for creating an icon you`ve had already given.I mean the menu-entry!

You wrote :

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.

Greetings!

lostinspace

To create a KDE menu entry for you to use to run Slave (by that I mean, no other users can use it if Slave is in your home area bin folder as suggested), right click on the SUSE menu icon in bottom left corner and select Menu Editor. Open Up System (Select the plus) and highlight Monitor. Right click on Monitor and select New Item. Give this new item the name of Slave. In the Command line enter the command of ~/bin/slave. You can put anything you want into the Description and Comment fields. Select the “?” where the icon goes and select an icon for use with Salve. Under Applications I found one under Terminal that had a big S on it, but you can use anything. Select the Advanced Tab. Check the **Run in Terminal **check box so that a terminal session will be started to use slave. Finally, press the Save button on the top left corner. Now, to run Slave, you go Menu / System / Monitor / Slave and Wam, you are in.

Thank You,

Hello jdmcdaniel3 !

The K-menu did you mean!I thought,you spoke about a menu in the terminal!That
would be nice,to have it there in one of the menus,or in a new one,called"Files",
for example.But there is quick access on the command-line.
Up to now,I don`t know,how to change the content of the menu-bar.
Thanks up to here!

Greetings!

lostinspace

Hello jdmcdaniel3 !

The K-menu did you mean!I thought,you spoke about a menu in the terminal!That
would be nice,to have it there in one of the menus,or in a new one,called"Files",
for example.But there is quick access on the command-line.
Up to now,I don`t know,how to change the content of the menu-bar.
Thanks up to here!

Greetings!

lostinspace
Well the only thing left is the actual bash script menu inside SLAVE. I have used the same basic thing in mmcheck and in START. See here:

S.T.A.R.T. - SuSE Terminal Audio Reporting Tool

MMCHECK - Check Your Multimedia in 10 Steps - Script File, as proposed by RedDwarf

If you would like to create a bash script file that has a menu, you need only to copy the menu system out of one of these scripts. Also use the most recent version as these scripts have evolved a lot from the original version, but feel free to copy any portion for your on usage.

Thank You,

First: Thanks a million$$$ !!!
Second: As long as you’re open to suggestions…
What about adding the /var/log/utmp and /var/log/btmp, etc. files???
Again, thank you for your selfless dedication to efficiency!!!
Have A Healthy, Prosperous Day!
—rob

I have not considered looking at login file records as most systems seem to be single user. It might be a good thing for a server or any multi-user system of course. For anyone who does not know about these, you can read about the group here: Utmp - Wikipedia, the free encyclopedia and you can look at them by opening up terminal and using the following commands:

sudo last -f /var/run/utmp

OR

sudo last -f /var/log/btmp

utmp is located in /var/run and not in /var/log, not that this matters as I would always look up its real location before I did anything. Thanks for the very kind words and I shall consider your request.

Thank You,