I have an utility created that prints output using printk. For eg.
printmsg.c:
void main() {
printk(KERN_DEBUG "Message alert id:XXXX!\n");
printk(KERN_DEBUG "Message alert id:YYYY!\n");
return;
}
If run this utility on the system, it prints the message like below on the console
#./printmsg
Message alert id:XXXX!
Message alert id:YYYY!
Whereas, if i run this application to pipe the output to grep, it doesn't work.
#./printmsg | grep XXXX
Message alert id:XXXX!
Message alert id:YYYY!
I am aware that the printk messages to kernel log buffer and dmesg to print the log buffer. With dmesg options to print output on stdoutput.
However, i am looking for an option to pipe the output to grep instantly when the utility runs and the output dumps on the console.
Limitation: printk can't be compromised here.
You need to construct your shell script on this way:
and this is because (with high probability)
printkfunction send message to STDERR, not STDOUT