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" |
cloud engineer
by Ulysses
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"
by Ulysses
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.
by Ulysses
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
by Ulysses
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
by Ulysses
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.
by Ulysses
To check which packages are available for an update.
yum check-update |
yum check-update
by Ulysses
Here’s the command to check if instance is domain joined.
realm discover domain.com |
realm discover domain.com
To check if AD user is working.
id user@ad.example.com |
id user@ad.example.com
To check if AD group is working.
getent group ad-group |
getent group ad-group
by Ulysses
This is a Powershell script to restart a service if it’s down.
$ServiceName = 'GCEAgent' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne 'Running') { Start-Service $ServiceName write-host $arrService.status write-host 'Service starting' Start-Sleep -seconds 60 $arrService.Refresh() if ($arrService.Status -eq 'Running') { Write-Host 'GCE Agent Service is now Running' } } else { Write-Host 'GCE Agent Service is Running' } |
$ServiceName = 'GCEAgent' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne 'Running') { Start-Service $ServiceName write-host $arrService.status write-host 'Service starting' Start-Sleep -seconds 60 $arrService.Refresh() if ($arrService.Status -eq 'Running') { Write-Host 'GCE Agent Service is now Running' } } else { Write-Host 'GCE Agent Service is Running' }