Thursday, 7 January 2016

Start-up Scripts Bash

Q:- Write a startup script using Bash Scripting



Bash Code


#!/sbin/sh

itr=1
echo "Enter 1 To start sshd"
echo "Enter 2 To stop sshd"
echo "Enter 3 To restart sshd"
echo "Enter 4 To exit"
while [ $itr -gt 0 ]
do
read ch

case "$ch" in
1)
echo -n "Starting sshd: sshd"
/usr/sbin/sshd
start sshd status 
echo "."
;;
2)
echo -n "Stopping sshd: sshd"
kill `cat /var/run/sshd.pid`
echo "."
;;
3)
echo -n "Stopping sshd: sshd"
kill `cat /var/run/sshd.pid`
echo "."
echo -n "Starting sshd: sshd"
/usr/sbin/sshd
echo "."
;;
4)
echo "Bye!!"
itr=0;;
*)
echo "Usage: /etc/init.d/sshd start|stop|restart"
exit 1
;;
esac
done

output  :

[root@pict b]# bash Assgn9.sh
Enter 1 To start sshd
Enter 2 To stop sshd
Enter 3 To restart sshd
Enter 4 To exit
1
Starting sshd: sshd.
3
Stopping sshd: sshd.
Starting sshd: sshd.
2
Stopping sshd: sshd.
4
Bye!!

No comments:

Post a Comment