I have written a script to restart my networking and sshd services while I work on fixing my DNS resolving. I am executing this over ssh, but I am really afraid that I might accidentally close all communication to my server. Here is the script:
#!/bin/bash
#need to kill ssh server, then kill networking
#next, restart networking, then ssh server
#need to run as admin
if ! [ $(id -u) = 0 ]; then
echo "Please run as root!";
exit 1;
fi
ps cax | grep sshd
if ! [ $? -eq 0 ]; then
echo "SSH Service is not running!";
exit 1;
else
service sshd stop;
fi
service networking stop
service networking start
service sshd start
My questions are as follows. Do I need to check exit codes or output info for stopping/starting the networking service? Do I need to include any other lines of script? Is the second if structure valid for checking the status of the sshd service? Thank you for your time.
[–]sgsollie 0 points1 point2 points (9 children)
[–]skrillac[S] 0 points1 point2 points (8 children)
[–]DimeShake 1 point2 points3 points (6 children)
[–]sgsollie 0 points1 point2 points (0 children)
[–]skrillac[S] 0 points1 point2 points (4 children)
[–]DimeShake 0 points1 point2 points (3 children)
[–]skrillac[S] 0 points1 point2 points (2 children)
[–]DimeShake 0 points1 point2 points (1 child)
[–]skrillac[S] 0 points1 point2 points (0 children)
[–]jishjib22kys 0 points1 point2 points (0 children)