Please be aware that the usage of this script in a way where you have either put the root password in clear text stored inside the script, a call to the script or when calling the script from a terminal window, is a major security breach.
Please read the whole of this thread including post #7 with the warning and post #9 with a better version of the script where the use of sudo is made possible.
It might be clear that the use of sudo is the only recommended way of calling.**
The mods
It has been a while since I posted a script file here. So, I decided to write a new one that allows you to easily view seven of the log files located in /var/log. This script is designed to provide a useful function while demonstrating how to obtain a password from your script and showing a flexible menu display that could be called from more than one location in your script.
Copy and paste the contents of this script into a file located in the /home/your_name_here/bin folder as the file called slave.
#!/bin/bash
# SLAVE - SuSE Logfile Automated Viewer Engine
# This script file was written to allow you to view seven log files located in /var/log
# You must have root use access to view these files
# Custom Written for the openSUSE forums on 8-1-2010
PROG="SLAVE - SuSE Logfile Automated Viewer Engine"
# This Bash file requires the use of the Root User Password were PASS="root_password"
# You can place the root password in this file OR run the file with the root password on the command line.
# Example: slave password - Warning: Your root password will be displayed on the command line using this option.
PASS=""
# Menu Disply System function
# Display 9 menu items and 0 is always Exit
# Menu must have at least two choices plus exit
function print_menu {
tput clear
tput cup 3 15
tput setf 7
tput setb 2
tput bold
echo "$1"
tput sgr0
tput cup 5 15
if "$HOME" != "/root" ] ; then
tput setf 7
tput setb 1
tput bold
else
tput setf 0
tput setb 4
fi
echo "$2" " USER:"$HOME" "
tput sgr0
tput cup 7 15
echo "$5"
if $4 -ge 2 ] ; then
tput cup 8 15
echo "$6"
tput cup 9 15
echo "$3"
tput cup 11 15
fi
if $4 -ge 3 ] ; then
tput cup 9 15
echo "$7"
tput cup 10 15
echo "$3"
tput cup 12 15
fi
if $4 -ge 4 ] ; then
tput cup 10 15
echo "$8"
tput cup 11 15
echo "$3"
tput cup 13 15
fi
if $4 -ge 5 ] ; then
tput cup 11 15
echo "$9"
tput cup 12 15
echo "$3"
tput cup 14 15
fi
if $4 -ge 6 ] ; then
tput cup 12 15
echo "${10}"
tput cup 13 15
echo "$3"
tput cup 15 15
fi
if $4 -ge 7 ] ; then
tput cup 13 15
echo "${11}"
tput cup 14 15
echo "$3"
tput cup 16 15
fi
if $4 -ge 8 ] ; then
tput cup 14 15
echo "${12}"
tput cup 15 15
echo "$3"
tput cup 17 15
fi
if $4 -ge 9 ] ; then
tput cup 15 15
echo "${13}"
tput cup 16 15
echo "$3"
tput cup 18 15
fi
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 - Uses Sudo Command
function print_log {
if ! -e $1 ]
then
echo "$1 is not Present!"
echo
read -p "Press <enter> to continue..."
else
echo $2|sudo -S less $1
fi
}
# Determine if Password is set in script or provided on the command line...
if "$PASS" = "" ]
then
if "$1" = "" ]
then
echo
echo "root Password Not Found - Edit slave and add root password or you can"
echo "Run slave as: slave password, were password is the root user password."
echo
exit 1
else
PASS="$1"
fi
fi
# Main Program Loop starts here ...
while true ; do
# Setup Menu Fields
MENU=" LOG FILE SELECTION - M E N U "
EXIT="0. Exit SLAVE "
TOTL="9"
TST1="1. View boot.msg file - Messages from the kernel during the boot process. "
TST2="2. View messages file - Ongoing messages from the kernel and system log daemon when running. "
TST3="3. View warn file - All messages from the kernel and system log daemon assigned WARNING level or higher. "
TST4="4. View mail file - Messages from the mail system. "
TST5="5. View zypper.log file - Log file of zypper, a command line package manager. "
TST6="6. View Xorg.0.log file - Various start-up and runtime logs from the X Window system. "
TST7="7. View NetworkManager file - Log file from NetworkManager to collect problems with network connectivity."
TST8="8. Viewer (bash command less) Help "
TST9="9. Display Kernel Version "
# 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 $PASS ;;
"2") tput clear
FILE="/var/log/messages"
print_log $FILE $PASS ;;
"3") tput clear
FILE="/var/log/warn"
print_log $FILE $PASS ;;
"4") tput clear
FILE="/var/log/mail"
print_log $FILE $PASS ;;
"5") tput clear
FILE="/var/log/zypper.log"
print_log $FILE $PASS ;;
"6") tput clear
FILE="/var/log/Xorg.0.log"
print_log $FILE $PASS ;;
"7") tput clear
FILE="/var/log/NetworkManager"
print_log $FILE $PASS ;;
"8") tput clear
less --help ;;
"9") tput clear
uname -a
echo
read -p "Press <enter> to continue..." ;;
"0") exit 0 ;;
*) ;;
esac
done
exit 0
# End of Bash File
Then, using Dolphin, select this file and pick properties and change it to being executable. Or you can use the KDE menu Run Command:
chmod +x ~/bin/slave
Open up a terminal session and run “slave root_password” or edit the file and add your root password to the script. Please let me know if you have any comments.
Great tool !!! Just tested it a little bit. Just one thing, maybe a stupid question. When I view the bootlog…how do I get back to your main menue , or exit ? I just killed the process.
Why don’t you post it in "unreviewed HOWTO? A lot of people would benefit
Slave is using the BASH terminal command “less” to view the log files and the menu option 8 lets you look at the viewer options. Enter a q to quit the viewer and return to the main menu. Thanks for your positive comments otto_oz.
Hi James
I integrated your script in my “System” menu. When clicking on it the root password prompt will come up…works perfectly. Here pic for newbies what to do in the menu editor
otto_oz, that is very cool. Thanks for taking the time to post how you are using the script file SLAVE. I am sure the picture will be a big help to our users.
As for using ImageBam, I am not the expert, but I know that caf4926 is and uses it all of the time. Perhaps a message to her would get some help.
I would like to add that the intent of this script file was to be run as a normal user in terminal and either start slave with the root user password on the same line as an option (slave password) or to edit the slave script file and place your root password inside the script. It would also seem that it will work if you run it as root and add any bulletin_ sheet option you want.
The terminal command “sudo slave bulletin_ sheet” will also work. lol!
From a security point of view it i a big** NONO** to have your root password in readable form in your system. Doing this inside a file that can be read by a normal user makes it even worse.
The likewise big security hole is of course typing the root password in the clear when you call the script. All guidance about “do not log in as root” is rendered useless by this.
Standard size of a terminal window is 80x24 or 80x25 characters. The script should be able to fit it’s display into the standard size. Currently lines display wrapped around.
The script could be started as user root or, when it detects being run as an ordinary user, could make use of the su -c ‘<code here>’ mechanism to ask for the root password without echoing it.
Growing logfiles like ‘mail’ should be displayed with ‘tail -f’ to show in real time what’s happening.
Think of making it dynamic in the sense of letting the user select what logfiles appear in the menu.
Rename it. SLAVE reminds me too much of a script having to do with MySQL replication.
I see I have a couple of comments about the slave script. I will address these items with a new script file. Do consider that scripts are being posted in their entirety and can be easily modified by anyone as they so desire and post those results here for all to see.
Standard size of a terminal window is 80x24 or 80x25 characters. The script should be able to fit it’s display into the standard size. Currently lines display wrapped around.
One issue raised was the display size. So I have modified the script so that it is displayed in the top left corner for anyone with really small monitors, which are not all that common these days.
From a security point of view it i a big** NONO** to have your root password in readable form in your system. Doing this inside a file that can be read by a normal user makes it even worse.
The likewise big security hole is of course typing the root password in the clear when you call the script. All guidance about “do not log in as root” is rendered useless by this.
Next Issue was security. The file can be operated in one of three ways.
Add your password to the script as PASS=“your_root_password_here” using kwrite or other editor.
or
You can run the program as a normal user, but place your password on the command line as “slave your_root_password_here”.
or
Now you can run the program as root using sudo or other command as “sudo slave” and then enter your root password.
Rename it. SLAVE reminds me too much of a script having to do with MySQL replication.
I had a suggestion that the file name was too close to another file name. Since slave does not recurs itself in anyway, it can be named anything you want, You could call it S or F or U or really any single or multiple character you would like to use. With 26 letters and 10 numbers, the choices are endless I would say.
Growing logfiles like ‘mail’ should be displayed with ‘tail -f’ to show in real time what’s happening.
I think the addition of using ‘tail -f’ is a good idea, but I did not try to add that today. Perhaps another user would like to give it a try. Here is the modified for all to use. Enjoy…
#!/bin/bash
# SLAVE - SuSE Logfile Automated Viewer Engine
# This script file was written to allow you to view seven log files located in /var/log
# You must have root user access to view these files
# Custom Written for the openSUSE forums on 8-2-2010 Version 1.01
PROG="SLAVE - SuSE Logfile Automated Viewer Engine"
# This Bash file requires the use of the Root User Password were PASS="root_password"
# You can place the root password in this file OR run the file with the root password on the command line.
# Example: slave password - Warning: Your root password will be displayed on the command line using this option.
# You can also run the program as root using sudo or any other method and no password needs to be placed in this file.
PASS=""
# Menu Disply System function
# Display 9 menu items and 0 is always Exit
# Menu must have at least two choices plus exit
function print_menu {
tput clear
tput cup 1 1
tput setf 7
tput setb 2
tput bold
echo "$1"
tput sgr0
tput cup 3 1
if "$HOME" != "/root" ] ; then
tput setf 7
tput setb 1
tput bold
else
tput setf 0
tput setb 4
fi
echo "$2" " USER:"$HOME" "
tput sgr0
tput cup 5 1
echo "$5"
if $4 -ge 2 ] ; then
tput cup 6 1
echo "$6"
tput cup 7 1
echo "$3"
tput cup 9 1
fi
if $4 -ge 3 ] ; then
tput cup 7 1
echo "$7"
tput cup 8 1
echo "$3"
tput cup 10 1
fi
if $4 -ge 4 ] ; then
tput cup 8 1
echo "$8"
tput cup 9 1
echo "$3"
tput cup 12 1
fi
if $4 -ge 5 ] ; then
tput cup 9 1
echo "$9"
tput cup 10 1
echo "$3"
tput cup 12 1
fi
if $4 -ge 6 ] ; then
tput cup 10 1
echo "${10}"
tput cup 11 1
echo "$3"
tput cup 13 1
fi
if $4 -ge 7 ] ; then
tput cup 11 1
echo "${11}"
tput cup 12 1
echo "$3"
tput cup 14 1
fi
if $4 -ge 8 ] ; then
tput cup 12 1
echo "${12}"
tput cup 13 1
echo "$3"
tput cup 15 1
fi
if $4 -ge 9 ] ; then
tput cup 13 1
echo "${13}"
tput cup 14 1
echo "$3"
tput cup 16 1
fi
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 - Uses Sudo Command
function print_log {
if ! -e $1 ]
then
echo "$1 is not Present!"
echo
read -p "Press <enter> to continue..."
else
echo $2|sudo -S less $1
fi
}
# Determine if Password is set in script, provided on the command line or if the script was run as a root user...
if "$HOME" != "/root" ] ;
then
if "$PASS" = "" ]
then
if "$1" = "" ]
then
echo
echo "root Password Not Found - Edit slave and add root password or you can"
echo "Run slave as: slave password, were password is the root user password."
echo
exit 1
else
PASS="$1"
fi
fi
else
PASS="root"
fi
# Main Program Loop starts here ...
while true ; do
# Setup Menu Fields
MENU=" LOG FILE SELECTION - M E N U "
EXIT="0. Exit SLAVE "
TOTL="9"
TST1="1. View boot.msg file - Messages from the kernel during the boot process. "
TST2="2. View messages file - Ongoing messages from the kernel and system log daemon. "
TST3="3. View warn file - All messages from the kernel and system log daemon Alarms. "
TST4="4. View mail file - Messages from the mail system. "
TST5="5. View zypper.log file - Log file of zypper, a command line package manager. "
TST6="6. View Xorg.0.log file - Various start-up and runtime logs from the X Windows. "
TST7="7. View NetworkManager file - Log file from NetworkManager to collect problems. "
TST8="8. Viewer Display Help (in Viewer H=Help & Q=Quit) "
TST9="9. Display Kernel Version "
# 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 $PASS ;;
"2") tput clear
FILE="/var/log/messages"
print_log $FILE $PASS ;;
"3") tput clear
FILE="/var/log/warn"
print_log $FILE $PASS ;;
"4") tput clear
FILE="/var/log/mail"
print_log $FILE $PASS ;;
"5") tput clear
FILE="/var/log/zypper.log"
print_log $FILE $PASS ;;
"6") tput clear
FILE="/var/log/Xorg.0.log"
print_log $FILE $PASS ;;
"7") tput clear
FILE="/var/log/NetworkManager"
print_log $FILE $PASS ;;
"8") tput clear
less --help ;;
"9") tput clear
uname -a
echo
read -p "Press <enter> to continue..." ;;
"0") exit 0 ;;
*) ;;
esac
done
exit 0
# End of Bash File
Hi James
I still would encourage you to post your latest version in the “unreviewed Howtos” and encourage others to add to make it more complete.
You will get a lot of flag. Just ignore the negatives or answer in a positive fashion.
We all learn from each other.
cheers
Otto