Can anyone please tell me what exactly this script does?
#! /bin/sh
test –f /usr/bin/sshd || exit 0
case “$1” in
start)
echo –n “Starting sshd: sshd”
/usr/sbin/sshd
echo “.”
;;
stop)
echo –n “Stopping sshd: sshd”
kill `cat /var/run/sshd.pid`
echo “.”
;;
restart)
echo –n “Stopping sshd: sshd”
kill `cat /var/run/sshd.pid`
echo “.”
echo –n “Starting sshd: sshd”
/usr/sbin/sshd
echo “.”
;;
*)
echo “Usage: /etc/init.d/sshd start|stop|restart”
exit 1
;;
esac
I want to know what exactly this part:
#! /bin/sh
test –f /usr/bin/sshd || exit 0
case “$1” in
start)
echo –n “Starting sshd: sshd”
/usr/sbin/sshd
echo “.”
;;
does because the other part is the same!
Please 😉
Which other part is the same? The way that script works is it checks the value of
$1, which is the first parameter to the script supplied on the command-line. If it’s ‘start’, then the part afterstart)is executed. If it’s ‘stop’, then the part afterstop)is executed. If it’s ‘restart’, then the part afterrestart)is executed.Line by line for that first part:
Hey, it’s a shell script! Specifically, execute this script using the
shshell.Is there a file called
/usr/bin/sshd? If not, exit with a 0 return status.Check the value of
$1, the first command-line option.If
$1is ‘start’…Print “
Starting sshd: sshd“.Execute
/usr/sbin/sshd.Print “
.“.Exit the
casestatement.