Bash script performance issue and remediation

2024-06-17 5 min read Bash Performance Linux

I was looking at writing some output to files. The output did not vary much but the number of lines was huge. It was long time back so I dont remember the context of the requirement but I needed to write few million lines of text. The quickest way to do this was bash so I wrote a simple script that could do this. To my astonishment, I could see the script much more time than expected, so here is how I debugged the issue and fixed it.

Continue reading

Run X11 applications on docker or podman

2024-03-29 1 min read Linux Networking Docker Containers

Found x11docker project in github. This is a very nice project if you are trying to run GUI applications in dockers. It takes the hassle out and helps you run the GUI applications very easily in docker.

Whats more, if you are on Fedora, you are in luck. You can install this tool with

1
sudo dnf install x11docker

and if you are not on Fedora, then head over to their github. Some other distributions also have it packaged but otherwise also it is very simple to install.

Continue reading

Show Local IP

2023-12-23 1 min read Linux Networking

Show local IP

You can see the local IP of the machine with the command - ip a. However if you have to use the address in some variable in a scrit. It becomes little tricky, something like

  • Show the interfaces in one line with ‘-o’
  • Show only IPv4 address’s with ‘-4’

and the command looks like

1
ip -4 -o a show dev eth0|awk '{gsub(/\/.*/,"",$4);print $4}'

Replace eth0 with then correct interface name.

Continue reading

Openvpn files to nmcli connection

2022-11-12 1 min read Linux Networking

Openvpn files to nmcli connection

Many times you get openvpn file and when you want to connect to the VPN server, you have to start the vpn client from the cli. How you wish that this was added to NetworkManager so that you could connect to it with one click. If this is the case, then you can use these commands to do the same ane enjoy :)

1
2
nmcli connection import type openvpn file test.ovpn
nmcli connection modify test vpn.secrets 'password=mypass' vpn.user-name 'username'

You will need to modify few things in above command

Continue reading

scripting – performance improvement with file open

2020-04-20 2 min read Bash Learning Linux

Sometimes just one line of code can make all the difference. I will show you with example.

 

Here is script with 2 functions. Both are writing some lines of text to a file. First function, “a” I have used the redirection to write to file. Function “b”, I have opened a file descriptor with “>” before going into the loop and use that reference for writing to the file. (This concept remains same for any scripting or programming language).

Continue reading
Older posts Newer posts