Skip to content

Instantly share code, notes, and snippets.

@Jirido
Created February 22, 2020 19:05
Show Gist options
  • Save Jirido/acf54ca02e382d026e17ac0412ecdf14 to your computer and use it in GitHub Desktop.
Save Jirido/acf54ca02e382d026e17ac0412ecdf14 to your computer and use it in GitHub Desktop.
reboot shellScript
#!/bin/bash
if
[[ "$CONNECTION_RETRIES" = "" ]]; then
export CONNECTION_RETRIES=0; export RESTARTS=0; export NMRESTART=0;\
echo "settin the damn retries to 0"
now=$(date +"%T")
echo "First try since reboot. Time is $now"
echo "ConnectionRetries $CONNECTION_RETRIES"
fi;
ping -c 1 -q 84.200.69.80 >&/dev/null; CONTACT=$?;
if
[ "$CONTACT" = "0" ];
then
export CONNECTION_RETRIES=0;\
export RESTARTS=0;\
export NMRESTART=0;\
echo 'Good contact, we go to ZERO!';
else
if
[ "$CONNECTION_RETRIES" = "0" ];
then
(( CONNECTION_RETRIES=CONNECTION_RETRIES+1 ));\
echo "ConnectionRetries $CONNECTION_RETRIES";
echo 'No good contact, but no restart. first retry.';
else
if
[ "$CONNECTION_RETRIES" != "0" ] && [ "$RESTARTS" -lt "5" ];
then
phantomjs /root/bin/reboot-hajvi.js >> /root/liskoservu/bugg-Tmp/connect_reboot_script.log ;\
(( CONNECTION_RETRIES=CONNECTION_RETRIES+1 ));\
(( RESTARTS=RESTARTS+1 ));\
SWAY="";\
((SWAY=CONNECTION_RETRIES+1));\
echo "$SWAY retries and $RESTARTS restart";\
echo 'restarting..';\
else
if
[ "$RESTARTS" = "5" ];
then
systemctl restart NetworkManager.service;\
echo '6 tries and 5 restarts.';\
wait 3;\
echo 'restarting NetworkManager and the modem.';\
wait 10;\
phantomjs /root/bin/reboot-hajvi.js;\
(( CONNECTION_RETRIES=CONNECTION_RETRIES+1 ));\
(( RESTARTS=RESTARTS+1 ));\
(( NMRESTART=NMRESTART+1 ));\
else
if
[ "$NMRESTART" != "0" ];
then
echo 'Damned this coputor! By Thye Devil.. No is time to restart!';
wait 10;
reboot;
fi
fi
fi
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment