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 after start) is executed. If it's 'stop', then the part after stop) is executed. If it's 'restart', then the part after restart) is executed.
Line by line for that first part:
#! /bin/sh
Hey, it's a shell script! Specifically, execute this script using the sh shell.
test –f /usr/bin/sshd || exit 0
Is there a file called /usr/bin/sshd? If not, exit with a 0 return status.
case “$1” in
Check the value of $1, the first command-line option.
start)
If $1 is 'start'...
echo –n “Starting sshd: sshd”
Print "Starting sshd: sshd".
/usr/sbin/sshd
Execute /usr/sbin/sshd.
echo “.”
Print ".".
;;
Exit the case statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With