Create links to start and kill a daemon named labd. The daemon should be the las
ID: 3637147 • Letter: C
Question
Create links to start and kill a daemon named labd. The daemon should be the last one to start and the first to be killed at runlevel 5. Make sure you create an emoty file named labd in etc/init.d so the link will work.Explanation / Answer
#!/bin/bash # start_daemon.sh echo $$ > /tmp/daemon_pid now=`date '+%H'` # stop running at 11:00pm while [ $now -lt 23 ] do # this is a pointless example tail /var/log/auth.log |grep -i error >> /tmp/errors.log sleep 5 now=`date '+%H'` done rm -f /tmp/daemon_pid #!/usr/bin/perl # check_daemon.pl my $msg = "The daemon is dead, head for the hills!! "; if (-s '/tmp/daemon_pid') { my $pid = `cat /tmp/daemon_pid`; print $msg unless `ps -ef |grep $pid`; } else { print $msg; } #!/bin/bash # kill_daemon.sh if [ -s /tmp/daemon_pid ] then kill -9 `cat /tmp/daemon_pid` rm -f /tmp/daemon_pid fi demo: prompt> ./start_daemon.sh & [1] 11647 prompt> ./check_daemon.pl prompt> ./kill_daemon.sh [1]+ Killed ./start_daemon.sh prompt> ./check_daemon.pl The daemon is dead, head for the hills!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.