But then you encounter an issue and want at least the tail part of e.g. /var/log/messages saved?
E.g. in my case because of ongoing issues with suspend.
The 1st script goes back to the moons now long gone, during the development phase of port 5.0
The 2nd script I added recently when Port 5.0 finale was released.
The 1st script works on its own, but only with adding the 2nd script I now am finally happy with how it all works together, since the 2nd script removes all older entries while adding basic info /var/log/messages would not provide, while letting /var/log/messages be still appended into the now saved to a harddrive file.
To make it more easy for you, I will change the paths that are hardcoded in my script. Please edit these to suit your needs.
At least the 2nd script is meant to be in the folder on some harddisk where you want the log saved to survive a possible system crash.
Both scripts can sit on any file system, you can use them on VFAT, NTFS, ext[234], any device the root user can write to.
Cave! To really be prepared for any kind of crash or system failure you might encounter and want to catch as much logging info about it is best you alter the standard way Porteus boots and starts up your chosen DE:
By using the "3" cheatcode as in init 3 as in "Slackware standard mode - multiuser with network" as in: boot into the virtual text console and not into your GUI.
Interestingly some folks also prefer my manual startx approach like here https://ikkiboot.tuxfamily.org/en/news.html
(highlighting by me)In case of Porteus startup problem in UEFI, choose Text Mode as startup choice, connect with the guest/guest account and then launch the GUI with the startx command.
You will thus end up at this text prompt instead:
Code: Select all
===============================================================================
Welcome to Porteus v5.0
===============================================================================
The system is up and running now.
Login as root with password toor or as guest with password guest.
If you're new to Porteus, visit http://www.porteus.org/ for more info.
After you login, try the following commands:
mc ....... to start Midnight Commander (edit/copy/move/create/delete files)
init 4 ... to run Xwindow system
Other commands you may find useful:
activate ..... to insert (install) Porteus module into the system on the fly
deactivate ... to remove (uninstall) Porteus module from the root filesystem
pns-tool ..... to setup internet connection
When finished, use "poweroff" or "reboot" command and wait until it completes
===============================================================================
porteus login:
There you find the two scripts (actually, they are 3 - one for logging /var/log/messages - you have to be root for doing this) [one for logging /home/guest/.xfce4-session.verbose-log - I explain that later, you can do that as guest] and one for altering the log the 1st script created by only adding newest info and deleting older unneeded stuff since you have been able to run the script, meaning the system could not have crashed.
tail+tee_VLM_sda2.sh
VLM is short for "/var/log/messages"; sda2 means it is meant to save the log onto sda2.
Code: Select all
#!/bin/bash
mydate=$(date +%Y-%m-%d)
echo mydate suffix I am using: $mydate
myfile=/mnt/sda2/backup/var_log_messages_$mydate
echo myfile I am using: $myfile
echo $(date +%d.%m.%Y\ %H:%M:%S) started: $0 >>$myfile
echo '# cat /etc/porteus/*' >>$myfile
cat /etc/porteus/* >>$myfile
echo '# uname -r' >>$myfile
uname -r >>$myfile
tail -fn 10 /var/log/messages|tee -a $myfile
recall that the date suffix is the date your system booted when you run tail+tee_VLM_sda2.sh first thing after bootup.
It will be running in the background and not bother you, it will keep running even when X will exit, only when all programs are terminated (either by init, e.g. a reboot or shutdown, or via REISUB, or due to electricity blackout then the logging will stop because then tee will also have stopped. But you will have the very last log that happened and got reported into /var/log/messages saved in /mnt/sda2/backup/
Let us presume today as in date +%Y-%m-%d is 2022-10-21 - thus your created log file will be /mnt/sda2/backup/var_log_messages_2022-10-21
Even when you keep your system on and only use suspend once in a while and the date changes, say to "2022-10-23" the log file will still be var_log_messages_2022-10-21 since that was the date you started tail+tee_VLM_sda2.sh.
Now you want to start your DE.
What I do: I switch to another virtual console [e.g. via Alt+Cursor-Right - or Alt+F2] log in as guest and type
Code: Select all
startx
You can also log in as guest and use "init 4" instead, then your usual greetings and GUI log in screen will appear as set up by your chosen DE.
Be it as it may, now you have a root virtual console running in the background while also having started your usual chosen DE.
Now to the 2nd script.
If you use a NTFS or VFAT partition you can do that from a normal guest terminal emulator. In XFCE, that would be xfce4-terminal .
If you use a Linux kind of partition, only root can alter the file so you also need to be root for the 2nd script.
If /mnt/sda2/backup is on a Linux partition (ext2/3/4 etcetera): Open a new tab in your favourite terminal emulator and type
Code: Select all
su -
Now you are root and stay as root. Navigate to /mnt/sda2/backup and run the 2nd script -cat-into-var_log_messages.sh - like so:
Code: Select all
root@porteus:/mnt/sda2/backup# ./cat-into-var_log_messages.sh 2022-10-21
cat-into-var_log_messages.sh
Code: Select all
#!/bin/bash
echo cat-into-var_log_messages.sh V0.2 #V0.2 added dx / fx / sx
# functions
dx ()
{
echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
/bin/df -Tm $* | grep -vE 'tmpfs|/mnt/live/run|squashfs'
}
function sx ()
{
echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
{
read firstLine;
echo "$firstLine";
while read f t s u p; do
let "s2 = $s / 1024";
let "u2 = $u / 1024";
printf '%-40s%-16s%-8s%-8s%-8s\n' $f $t $s2 $u2 $p;
done
} < /proc/swaps
}
function fx ()
{ echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________;
/bin/free -m
}
# this is fxsx:
#fx|head -n 4;t;sx|tail -n 3
if [ $# -ne 1 ]; then
echo "ERROR: give one parameter- the date suffix of the var_log_messages_ file
you want to write to
e.g. 2022-03-25"
exit 1
fi
myfile=var_log_messages_$1
echo myfile is: $myfile
if [ -w $myfile ]; then
echo File found, writeable… overwriting it with listing of activated modules and fxsx # and dx /
cat /etc/porteus/* >$myfile
uname -r >>$myfile
ls /mnt/live/memory/images/ >> $myfile
dx / >> $myfile
fx|head -n 4;sx|tail -n 3 >> $myfile
echo '____ What follows is cat $myfile: ______________________________________________'
cat $myfile
else
echo File not found or not writeable. Abort!
exit 2
fi
Code: Select all
echo $(date +%d.%m.%Y\ %H:%M:%S) started: $0 >>$myfile
Cave!
function sx is written for my needs, and it presumes there are 2 swap devices - one swap partition on the harddrive and one via /dev/zram0
When you have more than two or only one, you have to adjust the script (the "sx|tail -n 3 part) accordingly.
If you have none, remove the function sx () part and alter the line
Code: Select all
fx|head -n 4;sx|tail -n 3 >> $myfile
Code: Select all
fx|head -n 4 >> $myfile