Skip to main content

Posts

Showing posts from 2023

Check Time zone in Linux and windows machines

In Linux, open a terminal window and type the following command: timedatectl | grep "Time zone" In Windows, open a command promot and type the following command: tzutil /g To set a new timezone in Windows, open an elevated command prompt. Check out this link to set a new Time zone: https://quickbytesstuff.blogspot.com/2014/08/view-and-set-time-zone-via-command-line.html Checking Time Zone will clear up things, if the machine timing is properly sync or not. Or why machine is having a different time with the current location. Stay safe! and Keep things up! Another year is coming! Do ASAP,  A lways  S ay  A   P rayer ... Practice O.T.G. =  O bedience  T o  G od Make time for Prayer and Meditation. Take time to kneel down and Pray! Practice F.IF.T.H (Firm In Faith Towards Heaven)

Basic Ansible understanding when statement

Ansible playbook to illustrate how "when" conditional statement works in Ansible. Ansible playbook below will run a command: "file -s /dev/sdb"  The output of the command will be saved to the variable: save_the_command_output  Yes, the name of the variable can be anything. Just changed it to something that is sensible. save_the_command_output is just a string to illustrate its functionality or usage. After registering or saving the output to a variable, another command will be executed provided the conditional statement "when" is True or the condition is meet or satified. If the conditional statement is not meet then the command will be bypass or will not be executed. On this illustration below, if the conditional statement has been meet. Then a file with a filename "condition_ok" will be written on /tmp directory. Otherwise, if the condition is not meet then no file will be created. Sample playbook below: #=================== --- -  hosts: local

Python Basics - creating virtual environment and activating

 Creating virtual environment in Python is quite important thing to know if you are venturing to the world of Python Programming. Virtual Environment in Python may sound complicated at first if you haven't played around it. Let's delve into it. Why do we need a virtual environment? When we can just installed Python directly to the system. One good thing for creating Python virtual environment, is you can have multiple environments on Python on your system and also different versions. If 2 or 3 people are using the same server or computer, it won't be ideal that each person will use same environment and mess up the work of the other person. And also if your coding is good for a specific version of Python, the syntax may not work on new versions of Python and this is where virtual environment comes into the scenario. How do we create a virtual environment in Python? It's quite straight forward, here's the command. Of course this assumes that Python has been installed

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

PowerShell Port Scanning one liner - check range of port

Netcat is one of the best tools to check if port is open or not, and Netcat does offer also a lot of features other than port scanning. However, if netcat is not available on the system or it's not allowed to be installed. In Windows environment PowerShell will come in handy. Example one-liner code below uses PowerShell to scan a specified Target IP and also a range of ports to be scanned. To test the code, change the target IP as desired and also the range of port to be tested.  1..65535 | % {Test-NetConnection  127.0.0.1-Port $_ } 442..443 | % {Test-NetConnection  8.8.8.8 -Port $_ } Sample Output of the above commands:  1..10 | % {Test-NetConnection  127.0.0.1-Port $_ } 442..443 | % {Test-NetConnection  8.8.8.8 -Port $_ } Cheers! Take care. Till next Time. Enjoy exploring the world of PowerShell and enjoy the journey of learning.. Stay safe! and Keep things up!  Do ASAP,  A lways  S ay  A   P rayer ... Practice O.T.G. =  O bedience  T o  G od Make time for Prayer and Meditation.

How to automate Python to use Telnet to check ports

 Checking ports automatically can be stressful if there are quite a few addresses and ports to be checked. And typing manually is prone to error by mistyping the IP Address and Port. This is where automation comes into play. Prepare the IP Address and Port on  a text file, and once all is prepared. Let Python do the job or the task to Telnet and check the port whether the system can successfully connect or not. The tester just need to watch or monitor the terminal or do some other task, while waiting for the Python to do its job. Simple code below shows, how to do this task. #===================================== import sys import telnetlib def get_all_ips(filename_to_check):   with open(filename_to_check, 'r') as entries:     for ip_entries in entries:       ip_and_port=ip_entries.split(" ")                 the_ip=ip_and_port[0]       the_port_num=ip_and_port[1]       the_ip=the_ip.strip()       the_port_num=the_port_num.strip()       print("IP Address is: "

Linux sudo revoke permissions

 sudo is quite a good tool in Linux world in which you can specify commands with full access without giving root permissions to everything on the system.   However, sudo can also be used to have access or root permissions to everything on the system.   Why use sudo, when it can access everything? Why not just use or switch to root?   When entering or executing a command, sudo is a safe haven to make sure you know exactly what you are doing or it can provide you a second chance to abort the command. If the command being entered isn't the right one, before entering the password or pressing enter "Ctrl + C" can be used to abort the command and stop the execution. When running on a root session, any commands executer after pressing enter. There's no way to cancel or abort the command. That's why sudo is a good practice to use, so any of change of mind before pressing enter can is still possible to cancel. And running in a non-root session, if the command is

Zip log files via script or cron job

Zipping log files to save disk space is quite a common task for system admin. Logs can be kept for a certain period of time depending on the company policy. To keep logs files and not delete them is quite a good strategy. If something goes wrong, you will be able to trace and go back in time, and check what went wrong. Zipping log files can be done manually, or via Bash or Shell script. If the folder has a standard pattern, which is quite ideal then creating a shell script to automate the zipping of log files will be easier. For example, if  the log files is on this path /mnt/log folder. And it has this pattern, YYYY-MM-DD. Creating a script to avoid manual task can be done easily. Depending on how busy the application is, log files can grow easily and may fill-up the disk quickly. If the log folder structure is based on Year, Month and Date. Then the shell script knows what pattern to look for and the task can be automated. Example Screenshot of the log folder structure: Below is a sc

Outlook keeps disconnecting and laptop no network or WiFi

Outlook is a very good tool, however if it gives some issues, it can ruin your day or your mood to work. Well, as the odds say nothing is perfect and even the flowers on the field that looks so beautiful will one day fade away. Same goes with our electronic devices, you just don’t know when it will go south. It might even give you issues when you needed it most to work properly, and sometimes that will be the time that it will not work as expected. Anyway, problems will always be there. The only question is, how will you face the issue or problem? For Outlook not responding and also the network or WiFi keeps disconnecting even though your phone or other devices or laptop has no issue to the network. It seems that the laptop has been singled out, and that’s the only device on the network that is not working. There are various approaches to solve this issue. Sometimes, it’s the same issue Outlook not responding or no network, but then different ways to resolve the problem. Yes,

Linux / WSL vi do save as or create password encryption

Vi / Vim is a powerful tool and for Linux enthusiast, this is a must tool to learn. Text file or basic editing in command line is quite important, to take notes, create a script, store text data or just anything that needs editing or creating via command line or terminal. How to create a text file in command line and put a password or encrypt the file? Text file is readable via lot of tools, cat, less, more, grep or any text editing files. One way to protect the file or its content is to encrypt the file. Screenshot below shows, how to create the file and encrypt it. Example: vi -x TestPasswordEncrypt.txt After entering the command, it will ask for an encryption key twice. And after entering the password, it will open the vi text editor, pressing "i" or the "insert" key then user can start entering text or typing on the vi window. After typing anything, press "esc" key and press :w (colon and w)  to save the file. If user need to save the file with a new f

How to use Rsync to copy file one after another at a limited bandwidth

Copying files at the same time will ultimately consume all the bandwidth. So, to avoid such issue it would be good to tell Rsync to copy only once the other previous Rsync has finished copying. Copying or transferring files from one system to another location without impacting the bandwith or consuming all available bandwidth, when using Rsync. Using Rsync in Linux to copy files and folders is a common task for Sys Admin. When using Rsync and limiting the upper bandwith or telling Rsync the maximum bandwidth to use can be achieved using the "--limit" option. --limit is in KBps (Kilo Bytes per second and not Kilo bits) --partial is another good option if there is frequent disconnection this will tell Rsync to pick-up or include the files that has been transferred or copied Here's the command on how to use Rsync in Linux to limit the bandwidth when copying: rsync -Pz --limit=30000 <source> <destination> -P = will show the progress -z = tells Rsync to compress fi

PowerShell check device uptime since last reboot

Checking how long the machine or server is running since last reboot or maintenance is sometimes necessary. To measure the device performance or stability of the server or computer. In Windows, PowerShell is quite handy to to check the uptime of the server. Here's a simple code snippet to do check how long the server has been running since its last reboot. $Last_reboot_time = Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} $Today = Get-Date $uptime = NEW-TIMESPAN –Start $Last_reboot_time.LastBootUpTime –End $Today $xdays=$uptime.Days $xhours=$uptime.TotalHours $xhours=[math]::Round($xhours,2) write-output ("Computer is up since last reboot for: $xdays day/s and  $xhours  hours") Sample output of the code below: Computer is up since last reboot for: 1 day/s and  45.98  hours Cheers! Take care. Till next Time. Stay safe! and Keep things up!  Do ASAP,  A lways  S ay  A   P rayer ... P

Reset Azure SSH Key because of SSH Key Refused error

SSH Key Refused error, is a common error if the Private key is not accepted by the system in which the other end wants to connect with or communicate. In Microsoft Azure, the VM will through an error in Putty or any application software that will be used to connect or login to the VM on Azure cloud. If the private key is not recognized or accepted by the VM. Luckily, MS Azure provides an option to reset the SSH key and generate a new one. However, when the VM is created a PEM file will be generated and the user must download this file and keep it securely. Using PuttyGen or Putty Generator the PEM can be file can be used to generate a Public Key and a Private Key. To reset SSH or resolve the Server Key Refused error, a Public Key is needed or required by Azure. Screen shot below shows, on how to reset the SSH Public key. First, select the Virtual Machine that the SSH key needs to be resetted or changed. Upon selecting the Virtual Machine, choose or select the "Reset Password"

WMIC restart wireless network via command line in Windows

How to restart WiFi or Wireless using command line in Windows? If the wireless devices, laptops or computers are connected to a domain such as active directory, or a centralized control. The command below can be created using a batch file and deploy to all controlled devices or computers. The command below, has been tested on a Windows 11 laptop and works fine. If nothing goes wrong, the command executes very fast. Here's the command, must be executed on an elevated command prompt or administrator prompt. wmic service where caption="WLAN AutoConfig" call stopservice && timeout 3 && wmic service where caption="WLAN AutoConfig" call startservice Timeout command is used in between stop and start, as this would give the first command to stop the service and after 3 seconds, another command is executed to start the service. Without the timeout command, the second command might not run  properly, since the first is still executed on the background. Jus

How to view windows folder in GB or MB or in human readable sizes

With the era of WSL, Windows Subsystem for Linux is quite helpful. You can now run Linux commands on Windows with ease, or without installing any virtualization software. Of course, having VirtualBox installed with Linux is a different story, since you can have a pure Linux environment. Anyway, WSL provides an easy way to view size or capacity of Windows folder without any scripting using PowerShell or installing any Sysinternal tools. How to view folder sizes in human readable format in Windows using WSL? If WSL has been installed and working correctly, open Windows Terminal an awesome command-line shell application, in which you can run multiple Windows in one screen. And you can also position different windows terminal, either horizontally or vertically and Terminals can be resized the way you wan it. Grab windows terminal from Microsoft Store and for the prize of free. Once the Windows Terminal is open, just cd or browse to the directory where you need to check folder sizes. Just p

How to rip or convert old auido CDs to MP3 or digital format

Old habits are hard to break as they said, however, music of your generation old favorites music of yesteryears will always stay with you. Such music, are hard to forget since the mold your young life or even such songs inspired you to get through difficult times and be who you are today. Or just simply a music of wonderful memories with friends and love ones. Anyway, how to convert or rip CDs to digital format such MP3, WMA,  M4A or any other format that the converter supports. To convert CDs, a CD drive or reader is needed. A built-in CD drive or an external USB-Disk Drive that can read CDs or DVDs. In Windows 11 or Windows 10, these are the steps: Step 1: Insert the Audio CD to the drive Step 2: In the search are beside the windows logo, type: Media and from the search result choose or select the "Media Player". Step 3: In the top left hand side of the Media Player, you will see the Album of the insert CD, it will either show the album name, or if Media Player will not be