• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

check

Checking Nameservers

January 15, 2023

Handy little script to see if nameserver is on an array.

#!/bin/bash
declare -a servers=("127.0.0.53" "127.0.0.52" "127.0.0.51")
client=$(cat /etc/resolv.conf | grep nameserver)
for i in "${servers[@]}"
do
  if [[ $client =~ $i ]]
  then 
    using_unbound="true"
    break
  else
    using_unbound="false"
  fi
done
echo $using_unbound "|" $client

#!/bin/bash declare -a servers=("127.0.0.53" "127.0.0.52" "127.0.0.51") client=$(cat /etc/resolv.conf | grep nameserver) for i in "${servers[@]}" do if [[ $client =~ $i ]] then using_unbound="true" break else using_unbound="false" fi done echo $using_unbound "|" $client

Filed Under: Linux Tagged With: check, nameservers

Check Mounted File Systems

July 28, 2022

Check mounted file systems using df. Displaying different options.

df 
df -h
df -Th

df df -h df -Th

To get rid tmpfs, run this.

df -Th| grep -Ev '(udev|tmpfs)'

df -Th| grep -Ev '(udev|tmpfs)'

Filed Under: Linux Tagged With: check, df, file, mounts, systems, tmpfs

Windows Check If Port is Listening

March 3, 2022

Here’s how to check if port is listening on a Windows Server.

Log in to the destination server.

netstat -ano | find "443" | find "LISTEN"
tasklist /fi "PID eq "443"

netstat -ano | find "443" | find "LISTEN" tasklist /fi "PID eq "443"

Filed Under: Misc Tagged With: check, listening, netstat, port, tasklist, windows

Run Telnet on Git Bash

October 20, 2021

Although telnet is not used regularly since insecure, it’s a handy tool for testing ports.

For example, to check if a port 80 is open, you run this command.

$ telnet servername 80

$ telnet servername 80

Git Bash does not come with telnet, but you can use the Windows version by using winpty.

$ winpty telnet servername 457
Connecting To servername...Could not open connection to the host, on port 457: Connect failed

$ winpty telnet servername 457 Connecting To servername...Could not open connection to the host, on port 457: Connect failed

If port is open, you get an empty reply, just like in Windows.

Filed Under: Linux Tagged With: check, git bash, ports, telnet, windows

Check Open Ports Remotely

August 17, 2021

Here are a few tools to check if ports are open from a remote host.

nc -zvw10 192.168.0.1 22
nmap 192.168.0.1 -p 22
telnet 192.168.0.1 22

nc -zvw10 192.168.0.1 22 nmap 192.168.0.1 -p 22 telnet 192.168.0.1 22

You may have to install netcat and nmap if missing in your distro.

yum install nc
yum install nmap

yum install nc yum install nmap

Filed Under: Linux Tagged With: check, nc, nmap, open, ports, remote, telnet

Bash Variable Empty

August 6, 2021

Here’s how to check in Bash if a variable is empty or unset.

if [ -z "${VAR}" ]; 
then
  echo 'do something'
else
  echo 'do another'
fi

if [ -z "${VAR}" ]; then echo 'do something' else echo 'do another' fi

One liner

if [ -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi

if [ -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi

The inverse

if [ ! -z "${VAR}" ]; 
then
  echo 'do something'
else
  echo 'do another'
fi

if [ ! -z "${VAR}" ]; then echo 'do something' else echo 'do another' fi

if [ ! -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi

if [ ! -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi

Filed Under: Linux Tagged With: bash, check, empty, unset, variable

Check Reboot After Updates

July 16, 2021

Here’s the command to check if the system needs a reboot after running yum update.

Must be root or run it sudo.

$ needs-restarting -r ; echo $?
Core libraries or services have been updated:
  openssl-libs -> 1:1.0.2k-21.el7_9
  kernel -> 3.10.0-1160.31.1.el7
  dbus -> 1:1.10.24-15.el7
  linux-firmware -> 20200421-80.git78c0348.el7_9
  glibc -> 2.17-324.el7_9
  systemd -> 219-78.el7_9.3
 
Reboot is required to ensure that your system benefits from these updates.
 
More information:
https://access.redhat.com/solutions/27943
1

$ needs-restarting -r ; echo $? Core libraries or services have been updated: openssl-libs -> 1:1.0.2k-21.el7_9 kernel -> 3.10.0-1160.31.1.el7 dbus -> 1:1.10.24-15.el7 linux-firmware -> 20200421-80.git78c0348.el7_9 glibc -> 2.17-324.el7_9 systemd -> 219-78.el7_9.3 Reboot is required to ensure that your system benefits from these updates. More information: https://access.redhat.com/solutions/27943 1

In this instance, it requires a reboot due to a new kernel.

Filed Under: Linux Tagged With: centos, check, reboot, redhat, update

Yum Check Update

July 9, 2021

To check which packages are available for an update.

yum check-update

yum check-update

Filed Under: Linux Tagged With: check, packages, update, yum

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023