DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 9th August 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,977
Default Logging OpenBSD virtual machine console output

A shell script to start an OpenBSD VM and log the console input/output to an unique log file
The name of the logs start with the VM name followed by DDMM_HHMMSS.log
Code:
18259 Aug  1 04:15 vmlogs/alix_new0731_221336.log
11549 Aug  9 04:39 vmlogs/alix_new0809_043239.log
This name is created with:

Code:
LOGFILE="${LOGDIR}/${VMNAME}$(date -j   "+%m%d_%H%M%S").log"
For customizing this format, see date(1) and strftime(3)
Some alternatives shown on the shell command line:
Code:
$ date -j   "+%m%d_%H:%M:%S"                                  
0809_05:37:05

$ date -j   "+%m%d_%H_%M_%S" 
0809_05_37_56

$ date -j   "+%b%d_%H_%M_%S"
Aug09_05_43_59
The following snippet from the script shows how you could start the script:
Code:
# if variable VMNAME is not defined you will be prompted to select a VM

# USAGE options:

# 1) $ env VMNAME=alix_new ./dovm.sh
# 2) $ export VMNAME=alix_new ; ./dovm.sh
# 3) Define the shell variable VMNAME in the script
# 4) Just run './dovm.sh' and select a stopped VM from a menu
# 5) If you place it in your $HOMEDIR/bin directory: $ dovm.sh
Using the interactive method 4:
Code:
$ dovm.sh
  
   ID   PID VCPUS  MAXMEM  CURMEM     TTY        OWNER    STATE NAME
    1     -     1    1.0G       -       - adriaan:wheel  stopped df-us
    2     -     1    1.0G       -       - adriaan:wheel  stopped siralas-clone
    3     -     1    1.0G       -       - adriaan:wheel  stopped hetzner
    4     -     1    500M       -       - adriaan:wheel  stopped alix_new
Select 'ID' number of VM to start : 3
Script started on Tue Aug  9 05:56:44 2022
Connected to /dev/ttypb (speed 115200)
Using drive 0, partition 3.
Loading......
probing: pc0 com0 mem[638K 1022 a20=on]
disk: hd0+
>> OpenBSD/amd64 BOOT 3.53

com0: 115200 baud
switching console to com0
>> OpenBSD/amd64 BOOT 3.53
[snip]
root@df-us[~]shutdown -hp now
Shutdown NOW!
shutdown: [pid 33853]
                                                                               
*** FINAL System shutdown message from root@df-us.utp.xnet ***               
System going down IMMEDIATELY                                                  
                                                                               
                                                                               
root@df-us[~]
System shutdown time has arrived

root@df-us[~]syncing disks... done
vmmci0: powerdown

The operating system has halted.
Please press any key to reboot.
Instead of rebooting we press '~." ( tilde followed by a dot) to exit the console.
Code:
[EOT]
Script done, output file is /home/adriaan/vmlogs/hetzner0809_055644.log
You will then see a hint to use col(1) to sanitize 'download progress meter' lines:
Code:
    ------------------------------------------------------------------------------
HINT: You can use col(1) to filter out backspaces on messy lines like this:
    ------------------------------------------------------------------------------
    [snip]
    ^MGet/Verify SHA256.sig     0% |                          |     0
    --:-- ETA^MGet/Verify SHA256.sig   100% |**************************|
    2144       00:00 Signature Verified ^MGet/Verify bsd            0%
    |                          |     0       --:-- ETA^MGet/Verify bsd
    8% |**                        |  1792 KB    00:11 ETA^MGet/Verify
    bsd           17% |****
    [snip]

    For example:

    $ col -b <df-us0724_023205.log | less

    [snip]
    Get/Verify SHA256.sig   100% |**************************|  2144       00:00 ETA
    Signature Verified
    Get/Verify bsd          100% |**************************| 22339 KB    00:11 ETA
    Get/Verify bsd.rd       100% |**************************|  4498 KB    00:02 ETA
    [snip]

    Neat huh?
You can disable this hint by setting the variable SHOW_COL_HINT to 0:
Code:
#SHOW_COL_HINT=0
SHOW_COL_HINT=1
Attached Files
File Type: txt dovm.sh.txt (2.9 KB, 0 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 9th August 2022 at 04:32 AM.
Reply With Quote
Reply

Tags
virtual machine, virtualization, vmctl, vmm

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Machine J65nko OpenBSD General 8 9th May 2019 12:21 AM
Running Virtual Machine Manager on OpenBSD Host! mbzadegan OpenBSD Packages and Ports 1 22nd May 2017 10:01 AM
Create OpenBSD guest for Linux KVM (Kernel-based Virtual Machine) with 'virt-install' J65nko Guides 4 11th December 2014 04:30 AM
can't login on virtual console spermwhale_warrior OpenBSD General 3 19th July 2014 05:05 PM
Network failure and output dumping onto console JMJ_coder NetBSD General 17 17th May 2008 02:27 AM


All times are GMT. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick