Getting dmesg in the terminal - linux-kernel

Is it possible to get dmesg logs in terminal automatically each time a log comes to /var/log/messages
just to avoid typing dmesg or dmesg <args>

Run tail-f /var/log/messages in the terminal.

Related

How can I prevent my terminal from breaking?

I am using a watch command(in a shell script) in my docker image.
Command:
watch -d -t -g ls -la ${DIR_TO_WATCH} && sleep 5 && ${COMMAND} | tee
This command is watching a directory and if there is any change in the directory structure, we perform certain actions.
I am using this docker image in my helm chart.
Now, when I deploy the chart and check the logs of that pod, my terminal breaks and it will not be user friendly anymore.
Command:
kubectl logs -f pod-name -n name-space
After this, we need to reset terminal settings to get the terminal behave normal.
Is there anything that can be done to prevent this?
Best Regards,
Akshat
Solved this by sending output of watch to /dev/null.
watch -d -t -g ls -la ${DIR_TO_WATCH} > /dev/null && sleep 5 && ${COMMAND} | tee
The reason, according to my understanding, behind broken terminal was:
Two different command's logs(logs from watch and ${COMMAND}) were showing up on the same terminal at the same time, which resulted in creating a new terminal over the default one(which I am not sure how), causing the default terminal to break.
While ${COMMAND} logs were crucial for me, I did not need to view or monitor logs from watch. Hence, I sent the log outputs of watch to /dev/null and it solved my problem.
Please correct me if my understanding or approach is wrong.
Thank you.

Where can I find a screen (terminal multiplexer) that was created and detached with a startup-script? (GCP)

I am using GCP to run a game server and added a startup script to the VM to automatically run the gameserver in a screen, so if needed I can access the console to the server by re-attaching, the screen is starting and I am able to connect to the server so I know its their but I cannot find the screen using screen -ls
My startup script is:
#! /bin/bash
cd /home/minecraft
screen -dm java -Xmx3G -Xms2G -jar ./BTeam.jar nogui
After running screen -ls to find the screen to re-attach to it says there are no sockets to attach to.
Any help is appreciated.
Are you able to find screen running if you run
ps aux | grep -i screen
If so, please post the ENTIRE line that results from it (that isn't "grep -i screen")
Thanks!

kubectl message appearing every time when I start the terminal

I have uninstalled minikube through this post and now every time I open the terminal this message appears:
kubectl: command not found
Command 'minikube' not found, did you mean:
command 'minitube' from deb minitube
Try: sudo apt install <deb name>
I have no idea what is going on. Can someone help me to stop this message from appearing?
You probably have entries in your ~/.bashrc file that are both calling minikube or/and kubectl. Just edit/remove those entries. For example:
vi ~/.bashrc
In the vi editor:
/kubectl
dd
/minikube
dd
:wq

Log to syslog / console in macOS from Docker container?

I set my Docker container set to send logs to the hosts logs on CentOS 7 (with --log-driver syslog). I'd like to replicate this on macOS (Sierra). But it doesn't show up anywhere, seemingly.
$ docker run --log-driver syslog -it busybox sh
/ # logger "Hello world!"
/ # exit
And:
$ sudo cat /var/log/system.log | grep "Hello world"
Password:
$
What configuration is necessary to make it possible for any Docker system logging command for any arbitrary container to appear in a log file on macOS?
I can view these types of default system logging if I do not configure log-driver. But Ruby's syslog implementation must log differently.
$ docker run --log-driver syslog -it centos /bin/bash
# yum install ruby -y
# ruby -e "require 'syslog/logger'; log = Syslog::Logger.new 'my_program'; log.info 'this line will be logged via syslog(3)'"
# exit
$ sudo tail -n 10000 /var/log/system.log | grep "syslog(3)"
$
It depends on how you are logging your message.
As mentioned in "Better ways of handling logging in containers " by Daniel Walsh:
One big problem with standard docker containers is that any service that writes messages to syslog or directly to the journal get dropped by default.
Docker does not record any logs unless the messages are written to STDIN/STDERR. There is no logging service running inside of the container to catch these messages.
So a simple echo should end up in syslog, as illustrated by the chentex/random-logger image.
From Docker for Mac / Log and Troubleshooting, you can check directly if you see any logs after your docker run:
To view Docker for Mac logs at the command line, type this command in a terminal window or your favorite shell.
$ syslog -k Sender Docker
2017:
Check the content of ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/log.
Syslog driver was added in PR 11458
2022:
Brice mentions in the comments:
In Docker Desktop for macOs 4.x the logs are now here
$HOME/Library/Containers/com.docker.docker/Data/log/,
# eg
$HOME/Library/Containers/com.docker.docker/Data/log/vm/console.log

Xcode: View Console History After Cleared?

How can I see the Xcode console history? I accidentally cleared it by running the application again and am wondering if I can get back what was cleared.
Xcode console output is logged in the system log. You can search the system log from the console with grep:
# view last 2000 lines of the system log
sudo tail -n2000 /private/var/log/system.log
# search system log for YourApp
sudo grep YourApp /private/var/log/system.log
# watch the system log as it's being written and filter for YourApp
sudo tail -f /private/var/log/system.log | grep YourApp
Xcode 11:
In the Navigator, press the "Report navigator" button (the speech bubble), then click on your previous run sessions. You can see all your previous console logs.

Resources