Bash script for checking telnet service status


cat monitor.sh 
#!/bin/bash
source /etc/profile
cd /home/koala/Vagrant/windows-server-2019
(echo > /dev/tcp/192.168.178.220/23) > /dev/null 2>&1
if [ $? -ne 0 ]; then
  vagrant halt
  vagrant up
fi

Comments

  1. Louis said:

    apt install netcat

    function restart () { pushd /home/koala/Vagrant/windows-server-2019 > /dev/null vagrant halt vagrant up popd }

    function check () { until nc -vz -w ; do : ; done restart }

    check

  2. Louis said:

    apt install netcat

    function restart () {
    pushd /home/koala/Vagrant/windows-server-2019 > /dev/null
    vagrant halt
    vagrant up
    popd
    }
    
    function check () {
    # polling until it's offline
    until nc -vz -w <timeout> <ip> <port> ; do : ; done
    restart
    }
    
    check
    
  3. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.