Repetitive Tasks’ Exercise

Since my skill in programming and scripting is fairly poor, then for that matters i encourage myself to learn bash scripting, one of scripting language that is easy to learn. Well, yes, since i start learning this script, soon i realize that i got more advantage from it. With knowledge in bash scripting, i get more ease to finish my every day task on computing, beside my system administration task too.

I think people which need to go more on linux nor any other operating system that utilized bash, should consider to learn bash scripting, its a quite fun to learn and see your life on computing will be more easy to do.

This week i learn more about repetitive task on bash, and there are exercise need to be done. For your info, this script run on Nexenta alpha5 which powered by OpenSolaris kernel, but i think it will not too differ in any operating systems.
Exercise:

  • Prints a list of servers to check, such as Apache, the SSH server, the NTP daemon, a name daemon, a power management daemon, and so on.
  • For each choice the user can make, print some sensible information, like the name of the web server, NTP trace information, and so on.
  • Optionally, build in a possibility for users to check other servers than the ones listed. For such cases, check that at least the given process is running.


I did like this:

#!/bin/bash

# wichdaemon-new.sh
# This script will show some server listed on the machine.
# User can pick one of them, then it will try to give some information
# sense information about the choice.

while true; do
echo “Please choose one of the listed below: ”
cat << servers
X
automountd
cron
kcfd
cupsd
esd
fmd
inetd
lockd
statd
nmbd
nscd
picld
powerd
rpcbind
sendmail
smbd
sshd
syseventd
syslogd
utmpd
vold
servers

echo
echo -n “Your choice, (press q to quit or check another by pressing o): ”
read serv

MESSAGE=”Please make sure you type the name correctly!”

if [ $serv == “q” ]; then
echo “Quit Now!”
break
elif [ $serv == “syslogd” ]; then
ps -ely | grep $serv
if [ $? == 0 ]; then
echo “$serv is running”
echo
echo “This is some information related to $serv…”
tail /var/log/syslog
else
echo “$serv not running”
fi
elif [ $serv == “utmpd” ]; then
ps -ely | grep $serv
if [ $? == 0 ]; then
echo “$serv is running”
echo
echo “This is some information related to $serv…”
last | more
else
echo “$serv not running”
fi
elif [ $serv == “o” ]; then
echo -n “Please type another server: ”
read another
ps -ely | grep $another
if [ $? == 0 ]; then
echo “$another is running”
else
echo “$another not running”
echo $MESSAGE
fi
else
ps -ely | grep $serv
if [ $? == 0 ]; then
echo “$serv is running”
else
echo “$serv not running”
echo $MESSAGE
fi
fi
sleep 3
done

Yes, this is a dirty script, but im trying my best🙂 Hope next will be more good…!!!😉

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: