Monday, January 20, 2014

Unix and Shell Programming - Greet the User Based On System Time and User Time

with 0 Comment
clear
while true
do
echo "Greeting Command"
echo "------------------------"
echo
echo "Menu"
echo "-------"
echo "1.System Time"
echo "2.User Time"
echo "3.Exit"
echo "Enter your choice"
read ch
case $ch in

1)
echo "System Time"
echo "----------------"
hournow='date|cut -c 12-13'
echo "current date is:"
echo
date
echo
hr='date|cut -c 12-19'
echo
echo "Current Time is:"$hr
echo
user1='echo $HOME|cut -d"/" -f  3'
echo
case $hournow in
[0-1][0-1]|0[2-9])echo "Good Morning Mr/Ms:$user1";;
1[2-5])echo "Good afternoon Mr/Ms:$user1";;
1[6-9])echo "Good Evening Mr/Ms:$user1";;
*)echo "Good Night Mr/Ms:$user1";;
esac
;;

2)
echo "User Time"
echo "------------"
echo "Enter the time[hh:mm:ss]:"
read time1
echo
hr='echo $time|cut -c 1-2'
echo "The time is:"$time1
user='echo $HOME|cut -d "/" -f 3'
case $hr in
[0-1][0-1]|0[2-9])echo "Good Morning Mr/Mrs:$user1";;
1[2-5])echo "Good Afternoon Mr/Mrs:$user1";;
1[6-9])echo "Good Evening Mr/Mrs:$user1";;
*)echo "Good Night Mr/Mrs:$user1";;
esac
;;

3)
echo "Exit"
echo "---"
exit
;;
esac
done

------------
OUTPUT:
------------
Greeting Command
------------------------
Menu
-------
1.System Time
2.User Time
3.Exit
Enter your choice
1
System Time
----------------
Current date is:

Thu Oct 11 17:03:29  IST 2012
Current Time is : 17:03:29

Good Evening Mr/Ms:smca13

Enter your choice
2

User Time
-------------
Enter the time[hh:mm:ss]:
04:30:35

The time is:04:30:35
Good Night Mr/Mrs:smca13

Enter your chocie
3
Exit

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive