A
A
accountnujen2021-10-17 04:44:16
bash
accountnujen, 2021-10-17 04:44:16

How to drive nc into a variable?

this is how it works

nc -z -v -w2 $IP 1992
if [ $? -ne 0 ]; then
        curl "https://api.telegram.org/$TOKEN/sendMessage?text=Не удалось соединиться&chat_id=$CHAT"
fi

and like this - no
STATUS=$(nc -z -v -w2 $IP 1992)
if [ $STATUS -ne 0 ]; then
        curl "https://api.telegram.org/$TOKEN/sendMessage?text=Не удалось соединиться&chat_id=$CHAT"
fi


Why do I need it
хочу каждые 10 минут коннектиться к камере и проверять её доступность

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-10-17
@accountnujen

Directly your question:
https://unix.stackexchange.com/questions/207957/as...

nc -z -v -w2 $IP 1992
STATUS=$?
if [ $STATUS -ne 0 ]; then
        curl "https://api.telegram.org/$TOKEN/sendMessage?text=Не удалось соединиться&chat_id=$CHAT"
fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question