Skip to main content

Posts

Showing posts from August, 2023

Ansible comment all existing lines and add new lines

Backing up every configuration before any change is a good idea.  With the Git tool, every revision or change can be keep track and changes can be reversed. However, not everything is in Git. For example, in Linux configuration on /etc configuration or other important location or files is not under Git. To keep track of the changes, old school method can still be applied. Making another copy of the file, or just simply commenting every line and adding changes or new configuration after commenting the existing lines or configuration; are forms of backup. Existing configuration can still be seen, and can put back if there's a need to reverse the configuration. In an environment where there is hundred or more virtualized machines, Ansible is a way to go.  Ansible can do the task to comment all the existing lines and apply new configurations. Ansible script below, are references from multiple sources found on the web to create this Ansible script below. Here's the Ansible, save it

Check multiple IPs via bash one-liner loop using ping or dig

Ping multiple Linux servers via Bash script. Pinging a Linux server sounds a very common and simple task for any SysAdmin. However, if there are quite a few IP Addresses to check, it's quite daunting as typing on the terminal window is quite tedious and prone to error or mistype. Bash script is a way to go for this type of task. Just prepare all the IP Addresses that needs to be checked in a single text file. Do a loop to check all the IP Addresses on the text file and just watch the Bash do its job. Here's a simple code to do it: for ipx in $(cat ipx.txt); do ping -c 3 $ipx; done ipx.txt <<< should contain all IP Addresses to be checked Example of ipx.txt contents: 1.2.3.4 4.5.6.7 10.10.10.1 .... .... etc.. Above command can also be used to check DNS Reverse record using dig. Example: for ipx in $(cat ipx.txt); do dig -x $ipx; done The above will perform a reverse DNS lookup. There's a lot of uses cases that can be done, with the above command. That's it. Enjo