How can I avoid terminal messages screwing up vim? - linux

Sometimes I use vim in TTY1/2/etc. I am experiencing a problem with this. Messages such as the following keep flooding my terminal:
[ 1050.29303] wlp3s0: failed to set TX queue parameters for AC 2
[ 1059.29340] wlp3s0: failed to set TX queue parameters for AC 2
[ 1020.12309] wlp3s0: failed to set TX queue parameters for AC 2
[ 1029.12899] something_else: some other logging message here
[ 1292.21300] yet_another_thing: hey look a distraction
This can be quite disruptive, especially when I'm using vim to work, and sometimes it even results in me screwing up my text without realizing it. Is there any way to eliminate messages like this, at least when using vim? Using :redraw, editing the messed up lines, etc. don't seem to make the messages disappear.

Your sample of lines looks like kernel messages.
You can turn off output of dmesg messages by typing in terminal
sudo dmesg -D
This is a temporary solution and will work until the system is rebooted. For permanent disabling edit /etc/sysctl.conf file to set kernel.printk parameter.
kernel.printk = 1 4 1 3
I've set the first digit to 1 as the third was 1. Read more about kernel.printk and klogctl(3) {see description of SYSLOG_ACTION_CONSOLE_OFF command}

You can redirect output to a file in sh script.
In bash this would be using the redirect operator >.
If what you are trying to get rid of is standard output, the redirection arrow is defaulted to that. If the output is error output, this would be file descriptor 2 so the operand would be 2>
for example if I was going to run a python script in the background while using vim I could run the script like this
$ python3 script.py >stdoutput.txt 2>errors.txt

Related

Run AT commands from adb shell on Redmi 7

I tried this:
echo -e "ATD123456789;\r" > /dev/smd0
and then when I ran:
cat /dev/smd0
I got this output:
ATD123456789;
Is that what I'm supposed to see? The phone didn't respond to the command.
Update: The phone made a call when I used smd7 or smd11. The problem is I'm trying to send SMS messages using AT+CMGS and it's not working.
Update2: I run this command:cat /dev/smd7 & echo -e "AT+CMGS=24;\r" > /dev/smd7.
Then I enter the PDU message and I get this: /system/bin/sh: 079...771B: not found
As you probably know, the command
ATD<number>;\r
performs a voice call to the destination number <number> (without the semicolon ; the call type would depend o the current settings of AT+FCLASS command).
By default the OK result code would be received as soon as it starts remotely ringing, so after some seconds. But it would take even more if there are network problems or the remote number is unavailable/doesn't exist.
The default timeout of ATD command during a voice call is 30s, and can be changed by issuing ATS7 command. For example, to set a 1 minute timeout:
ATS7=60
The answer you get is the command echo: in fact the modem, by default, echoes every character sent to its AT port (the echo can be desabled through ATE0 command and aenabled again with ATE1). Receiving it **is the proof that the modem is correctly powered on and that it communicates correctly.
So, even though I'm aware that's not the only thing you expect to seee (you would like to see an answer!) you are actually supposed to see it.
Some pieces of advice in order to receive your answer:
Start providing simplier commands with shorter timeouts. For example the very basic AT.
Make sure to wait at least the maximum command timeout
Set the cat command in background and before starting providing commands:
cat /dev/smd0 &
echo -e "AT\r" > /dev/smd0
OK
Note: I'm not aware of any timeout in cat command.
To have an interactive session you can use:
strace 2>/dev/null -e inject=ioctl:retval=0 microcom /dev/smdXX
Without the strace command, microcom returns an ioctl error.
Strace makes microcom think the ioctl succeeded and so it allows it to continue and run.

How do I print the first few lines of a makefile (-Wall -g flags)?

How do I get the first n lines of the output of a makefile (specifically, my complier is g++). Either a script in linux or in the makefile would work (if you could provide both, that'll be even better).
I have tried
make | head -n 5
but it's not working.
Currently, the process I go through is tedious; I'm piping the output to a text file before using head on it (then having to delete the file).
Given that the messages from the compiler appear on standard error rather than standard output, you need to redirect both:
make 2>&1 | head -n 20
(I think 5 lines will be too small to be useful.)

how to avoid linux command messages in linux

How can I avoid messages that are shown on shell after I enter a command in ubuntu?
For example dd command in linux outputs something like " n bytes copied ...." and I want to avoid these outputs.
Any help?
You can redirect output with the '>' operator:
dd ... 1>/dev/null
1 is the standard output (stdout), 2 the standard error (stderr).
See http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html for a complete explanation of IO redirection.

How can I perform some commands on Intersystem cache from shellscript?

I want to perform some commands on Intersystem cache from shell script. One solution which I know is through making a config file but the problem is I dont know how to use config file through shell script. Is there any other solution for this...
for example what I have to run on cache is
csession instancename
zn "area"
area>D ^%RI
Device:some/device/path
Next: It should take enter
This can be accomplished from a Linux shell, simply keep a log of the commands you need to perform and then put them into a script. Here's an example of logging into Cache and writing "Hello world" -- note that this also assumes you need to authenticate.
echo -e "username\npassword\nW \"Hello world\"\nH\n" | csession instance
Note that every command you would have run manually is in there and separated by "\n", this is the character that represents the "Enter" key.
It is possible (for some operating systems) to run the Cache terminal in batch mode. For example:
echo: off
wait for:Username
send: SYS<CR>
wait for:Password
send: XXX<CR>
echo: on
logfile: Somepath\myFile.log
send: ZN "AREA"
wait for:AREA>
send: D ^%RI
wait for:Device:
send: some/device/path
wait for:Next:
send: <CR>
This is documented in the Intersystems cache terminal documentation, especially the using terminal in batch mode section and the terminal scripts section.
This is a very old question .. as I came across the same thing and so with a little R&D I found a work around to this problem. Which is very cool and simple.
Let's say I have this file (can be with any extension with each command in separate line)
myScript.scr
zn "%SYS"
for e="a","b","c" { w e,! }
So passing it to cache terminal in case of UNIX is using csession with linux PIPE (|) operator
cat myScript.scr | csession {instance_name}
Eg.
cat myScript.scr | csession CACHE
output
a
b
c
Note:
• Don't separate a command in multiple lines else `csession` will through <SYNTAX> error. (See how I wrote the *for* loop)
• Extra knowledge - Intersystem Ensemble supports *Cache Terminal Batch Mode* in Windows case... While in linux there is no cterm to take the scripts..
• But linux gives you a work around to do this ;).
Hope this helps you guys!! cheers :D

Bash output stream write to a file

so i am running this on bash:
# somedevice -getevent
What this command does is it just keeps running, and everytime my device sends a certain data, say it detects change in temperature, it outputs something like this
/dev/xyz: 123 4567 8910112238 20
/dev/xyz: 123 4567 8915712347 19
/dev/xyz: 123 4567 8916412345 22
/dev/xyz: 123 4567 8910312342 25
/dev/xyz: 123 4567 8910112361 18
/dev/xyz: 123 4567 8910112343 20
And this just keeps running and as soon as it has any cause it outputs something. So there is no end to execution.
No the echo is working perfectly, however when i am trying to use the '>' operator this doesn't seem to write to file.
so for instance
#somedevice -getevent > my_record_file
this doesn't work properly, my_record_file only gets data written to it in intervals, however i want to be written immediately.
Any ideas?
The output is being buffered because the C standard library changes the output buffering mode depending on whether or not stdout is a terminal device. If it's a terminal device (according to isatty(3)), then stdout is line-buffered: it gets flushed every time a newline character gets written. If it's not a terminal device, then it's fully buffered: it only gets flushed whenever a certain amount of data (usually something on the order of 4 KB to 64 KB) gets written.
So, when you redirect the command's output to a file using the shell's > redirection operator, it's no longer outputting to a terminal and it buffers its output. A program can change its buffering mode with setvbuf(3) and friends, but the program has to cooperate to do this. Many programs have command line options to make them line-buffered, e.g. grep(1)'s --line-buffered option. See if your command has a similar option.
If you don't have such an option, you can try using a tool such as unbuffer(1) to unbuffer the output stream, but it doesn't always work and isn't a standard utility, so it's not always available.
The command somedevice probably uses the "Standard Input/Output Library", and in that library, the buffering is on by default. It is switched off when the output does to a terminal/console.
Can you modify the somedevice program? If not, you can still hack around it. See http://www.pixelbeat.org/programming/stdio_buffering/ for details.
You can try 'tee':
somedevice -getevent | tee -a my_record_file
The '-a' option is to append instead of just replacing the content.
This is probably because your "somedevice -getevent" command's stdout is being block-buffered. According to this, stdout is by default line-buffered (i.e. what you want) if stdout is a terminal, and block-buffered otherwise.
I'd have a look at the manual for your somedevice command to see if you can force the output to be unbuffered or line-buffered. If not, stdbuf -oL somedevice -getevent > my_record_file should do what you want.

Resources