Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

How can I check that a remote computer is online for ssh / script access?

Like this:

nc -z hostname 22 > /dev/null
echo $?

If it's 0 then it's available. If it's 1 then it's not.


Use netcat:

nc -z localhost 22

From the manpage

 -z      Specifies that nc should just scan for listening daemons,
         without sending any data to them.

What about

MACHINE=192.168.0.8
exec 3>/dev/tcp/${MACHINE}/22
if [ $? -eq 0 ]
then
    echo "SSH up"
else
    echo "SSH down"
fi

Tags:

Scripting

Ssh

Backup

Networking

Ping

Related

What does dd stand for? Changing the PS1 on an interactive bash subshell easily How can I tell what version of apache I'm running? How to clean up file extensions? How can I grep in PDF files? How do I suppress dd output? How do I debug a kernel module in which a NULL pointer appears? Byobu/screen constantly freezes in Putty Number of files containing a given string Processing bash variable with sed Partition manager that can handle LVM? How do I move applications between KDE Activities?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy