How to debug multiple files simultaneously and save the output.
search cancel

How to debug multiple files simultaneously and save the output.

book

Article ID: 298161

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction


How to debug multiple files at the same time with the Linux tail command and write the output to a file for further analysis?


Environment

Product Version: 4.0

Resolution


This document explains how to debug multiple files from the same directory and save the output in a separate location, furthermore, it will provide an example to extract the file to your local machine if needed.

This example was done using a Bosh director, however, the steps are the same for any other VM. If working on a Bosh-managed virtual machine you are required to initially install the Bosh Command Line Interface (CLI), you can follow this
link to complete this pre-requisite. The last step demonstrates how to extract the file for a Bosh-managed VM.

 

Step 1) SSH into the virtual machine you want to get the logs from and ensure you switch to 'root' with the sudo -i command. Since the example is based on a Bosh director virtual machine, you can follow this document in order to perform the Bosh director ssh procedure.




Step 2) Access the directory where the log files are located. For this example, we are going to use a Bosh director virtual machine.


cd /var/vcap/sys/log/director/



Step 3) Run the following command in order to start the 'tail', note that the last part of the command (see below) will write the file (.log, .txt) to a directory in the same virtual machine, /tmp is used as an example, stop the test with CTL + c when the task is finished:
 

tail -f <file_1>.log <file_2>.log <file_3>.log <file_4>.log > /tmp/<FILE_NAME>


Example:





Step 4) Once ready, you can see the content of the file with the  cat /tmp/test.log  command:
 

bosh/0:/var/vcap/sys/log/director# cat /tmp/test.log 
==> worker_1.stdout.log <==
	before or while processing the request.: (conn: 3560) SELECT NULL
D, [2023-11-24T20:53:28.940809 #30096] [] DEBUG -- Director: (0.000235s) (conn: 3780) SET standard_conforming_strings = ON
D, [2023-11-24T20:53:28.941054 #30096] [] DEBUG -- Director: (0.000129s) (conn: 3780) SET client_min_messages = 'WARNING'
D, [2023-11-24T20:53:28.941210 #30096] [] DEBUG -- Director: (0.000108s) (conn: 3780) SET DateStyle = 'ISO'

==> worker_2.stdout.log <==
	before or while processing the request.: (conn: 4060) SELECT NULL
D, [2023-11-24T20:53:30.079542 #30110] [] DEBUG -- Director: (0.000355s) (conn: 4100) SET standard_conforming_strings = ON
D, [2023-11-24T20:53:30.079952 #30110] [] DEBUG -- Director: (0.000259s) (conn: 4100) SET client_min_messages = 'WARNING'
D, [2023-11-24T20:53:30.080185 #30110] [] DEBUG -- Director: (0.000162s) (conn: 4100) SET DateStyle = 'ISO'

==> access.log <==
10.225.31.129 - - [24/Nov/2023:20:53:35 +0000] "GET /info HTTP/1.1" 200 555 "-" "rest-client/2.1.0 (linux x86_64) ruby/3.2.2p53" 0.006 0.005 .
10.225.31.129 - - [24/Nov/2023:20:53:35 +0000] "GET /deployments HTTP/1.1" 200 881 "-" "rest-client/2.1.0 (linux x86_64) ruby/3.2.2p53" 0.031 0.032 .
10.225.31.129 - - [24/Nov/2023:20:53:35 +0000] "GET /deployments/cf-bbdb38dbc29865b8e80f/vms HTTP/1.1" 200 2364 "-" "rest-client/2.1.0 (linux x86_64) ruby/3.2.2p53" 0.078 0.078 .

==> director.stdout.log <==
D, [2023-11-24T20:53:46.125658 #26] [] DEBUG -- Director: (0.000501s) (conn: 3720) SELECT * FROM "deployments" WHERE ("name" = 'haproxy') LIMIT 1
D, [2023-11-24T20:53:46.127352 #26] [] DEBUG -- Director: (0.000696s) (conn: 14640) SELECT "teams".* FROM "teams" INNER JOIN "deployments_teams" ON ("deployments_teams"."team_id" = "teams"."id") WHERE ("deployments_teams"."deployment_id" = 1) ORDER BY "name" ASC


Note: From the output, you can see the multiple files write as the data gets triggered and there is a '==> <FILE_NAME> <==' mark to indicate to which file the output is coming from.



Step 5) In order to extract the file for further analysis change the owner to vcap with the chown vcap <FILE_NAME> command.






Step 6) Close the session from the virtual machine you collected the file from, then run the following scp command from your computer in order to move the file to any of your local directories as needed:

scp -o StrictHostKeyChecking=no vcap@<DIRECTOR_IP>:"/tmp/<FILE_NAME>" .





Note: If you need to perform the same procedure on a Bosh-managed virtual machine, the command to extract the file will look as follows:


bosh -d <deployment ID> scp <vm ID>:/tmp/<FILE_NAME> ~/Documents