Skip to content

ansible playbook: check linux process count

I am trying to write a playbook which shows failed when number of process running in linux host is not equal to 2. Following playbook works, but is there any better way of doing it? like is there any specific Ansible module to check process linux host? Answer What is your Ansible version? There is no Ansible …

How to edit a big file

Imagine a huge file that should be edited by my program. In order to increase read time I use mmap() and then only read out the parts I’m viewing. However if I want to add a line in the middle of the file, what’s the best approach for that? Is the only way to add a line and then move

Linux Shutdown and Java Shutdown Hook

When I run a Java process in background and I shut down the computer (ArchLinux), will the computer wait some seconds for the termination of my shutdown-hook in Java? Answer A shutdown hook will be called when a call to close the JVM is made. However, there is no guarantee that the hook will be called. The ho…

How to use Linux shell variable with sequence number?

I define several variables like below: And then I want to use them in a for loop like this, but failed. How to make it work? To use the variable with a sequence number. Answer I think you probably need a bash array: Sample Output You should probably avoid uppercase variable names too as they are reserved. If …

How to get stdout/stderr in logfiles immediately?

To run some Python program I use the following bash script: However I can get information after the prog is terminated only. When program is running there are not any data in these files. Can I override this behavior to get log data immediately? My OS is Raspbian. Answer I suspect the program needs to flush s…