Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. !/bin/bash
  2. clear
  3. main () {
  4. while [ 1 ]
  5. do
  6.  
  7. echo "Welcome $LOGNAME, to my Menu Program"
  8. echo "1. Show the calendar for an specific year"
  9. echo "2. Show current users logged in"
  10. echo "3. Display the current directory path"
  11. echo "4. Change directory"
  12. echo "5. Long list of files in current directory"
  13. echo "6. Display current time, date and calendar"
  14. echo "7. Start VI editor"
  15. echo "8. Email a file to an user"
  16. echo "9. Exit this program"
  17.  
  18. read -r -p 'Please input an option: ' option
  19.  
  20. case $option in
  21. 1) show_calendar;;
  22. 2) show_user;;
  23. 3) current_directory;;
  24. 4) change_directory;;
  25. 5) list_files;;
  26. 6) display_time;;
  27. 7) start_vi;;
  28. 8) get_user;;
  29. 9) echo "Bye $LOGNAME"; exit 0;;
  30. esac
  31. done
  32. }
  33.  
  34.  
  35. show_calendar () {
  36.  
  37.  
  38. read -r -p 'Please enter a month [1-12]: ' month
  39. read -r -p 'Please enter a year [1-9999]:' year
  40. # also testing if the result is a valid number,
  41. # for more, see: /msg greybot faq valid
  42. # if [[ $year != "" && $year != *[![:digit:]]* ]] && ((100 < year && year < 9999))
  43. if ((year >= 0 && year <= 9999)) && ((month >= 0 && month <= 12))
  44. then
  45. cal "$month" "$year"
  46. else
  47. echo "Entry not valid (Make sure you input [mm-yyyy]"
  48.  
  49. fi
  50.  
  51. read -r -p "Please [enter] to continue..."
  52. clear
  53.  
  54. }
  55.  
  56. show_user () {
  57. finger | more
  58. read -r -p 'Please [ENTER] to continue...'
  59. clear
  60. }
  61.  
  62. current_directory () {
  63. pwd
  64. read -r -p 'Please [ENTER] to continue...'
  65. clear
  66. }
  67.  
  68. change_directory () {
  69. read -r -p 'please enter your directory ' dir
  70. if [ -d "/$dir" ]
  71. then
  72. cd "/$dir"; echo "You're in `pwd` and these are your files"
  73. sleep 1.5; ls | more -d
  74. elif [ -d "/home/$dir" ]
  75. then
  76. cd "/home/$dir"; echo "You're in `pwd` and these are your files"
  77. sleep 1.5; ls | more -d
  78. elif [ -d "$HOME/$dir" ]
  79. then
  80. cd "$HOME/$dir"; echo "You're in `pwd` and these are your files"
  81. sleep 1.5; ls | more -d
  82. else
  83. echo "$dir name does not exist"
  84. fi
  85. read -r -p 'Please [ENTER] to continue...'
  86. clear
  87. }
  88.  
  89. list_files () {
  90. ls -l | more;
  91. read -r -p 'Please [ENTER] to continue...'
  92. clear
  93. }
  94.  
  95. display_time () {
  96. date; cal
  97. read -r -p 'Please [ENTER] to continue...'
  98. clear
  99. }
  100.  
  101. start_vi () {
  102. read -r -p 'Please input name of your file ' file
  103. if [ -d $file ]
  104. then
  105. echo " $file is a directory "
  106. elif [ -e $file ] && [ -r $file ]
  107. then
  108. vi $file
  109.  
  110. elif [ ! -f $file ]
  111. then
  112. vi $file
  113. else
  114. echo "No a regular file or unreadable"
  115. fi
  116. read -r -p 'Please [ENTER] to continue...'
  117. clear
  118.  
  119. }
  120.  
  121. get_user () {
  122. echo 'Please input a user '
  123. read user
  124. grep $user /etc/passwd > /tmp/user
  125. sleep .8
  126. if [ -s /tmp/user ]
  127. then
  128. sleep 0.3;
  129. else "$user not in the system"
  130. # read -r -p 'Enter a file name'
  131. # read file
  132. # read -r -p 'Enter a subject'
  133. # read subject
  134. # else "$user not in the system"
  135. fi
  136. read -r -p 'Enter a subject: ' subject
  137.  
  138. read -r -p 'Enter a file: ' file
  139. if [ $file = *.txt ]
  140. then
  141. mail -s "$subject" "$user" < "$file"
  142. else
  143. echo "Attach .txt files only"
  144. fi
  145.  
  146. rm /tmp/user
  147.  
  148. read -r -p 'Please [ENTER] to continue...'
  149. clear
  150. }
  151.  
  152. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement