Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !/bin/bash
- clear
- main () {
- while [ 1 ]
- do
- echo "Welcome $LOGNAME, to my Menu Program"
- echo "1. Show the calendar for an specific year"
- echo "2. Show current users logged in"
- echo "3. Display the current directory path"
- echo "4. Change directory"
- echo "5. Long list of files in current directory"
- echo "6. Display current time, date and calendar"
- echo "7. Start VI editor"
- echo "8. Email a file to an user"
- echo "9. Exit this program"
- read -r -p 'Please input an option: ' option
- case $option in
- 1) show_calendar;;
- 2) show_user;;
- 3) current_directory;;
- 4) change_directory;;
- 5) list_files;;
- 6) display_time;;
- 7) start_vi;;
- 8) get_user;;
- 9) echo "Bye $LOGNAME"; exit 0;;
- esac
- done
- }
- show_calendar () {
- read -r -p 'Please enter a month [1-12]: ' month
- read -r -p 'Please enter a year [1-9999]:' year
- # also testing if the result is a valid number,
- # for more, see: /msg greybot faq valid
- # if [[ $year != "" && $year != *[![:digit:]]* ]] && ((100 < year && year < 9999))
- if ((year >= 0 && year <= 9999)) && ((month >= 0 && month <= 12))
- then
- cal "$month" "$year"
- else
- echo "Entry not valid (Make sure you input [mm-yyyy]"
- fi
- read -r -p "Please [enter] to continue..."
- clear
- }
- show_user () {
- finger | more
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- current_directory () {
- pwd
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- change_directory () {
- read -r -p 'please enter your directory ' dir
- if [ -d "/$dir" ]
- then
- cd "/$dir"; echo "You're in `pwd` and these are your files"
- sleep 1.5; ls | more -d
- elif [ -d "/home/$dir" ]
- then
- cd "/home/$dir"; echo "You're in `pwd` and these are your files"
- sleep 1.5; ls | more -d
- elif [ -d "$HOME/$dir" ]
- then
- cd "$HOME/$dir"; echo "You're in `pwd` and these are your files"
- sleep 1.5; ls | more -d
- else
- echo "$dir name does not exist"
- fi
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- list_files () {
- ls -l | more;
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- display_time () {
- date; cal
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- start_vi () {
- read -r -p 'Please input name of your file ' file
- if [ -d $file ]
- then
- echo " $file is a directory "
- elif [ -e $file ] && [ -r $file ]
- then
- vi $file
- elif [ ! -f $file ]
- then
- vi $file
- else
- echo "No a regular file or unreadable"
- fi
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- get_user () {
- echo 'Please input a user '
- read user
- grep $user /etc/passwd > /tmp/user
- sleep .8
- if [ -s /tmp/user ]
- then
- sleep 0.3;
- else "$user not in the system"
- # read -r -p 'Enter a file name'
- # read file
- # read -r -p 'Enter a subject'
- # read subject
- # else "$user not in the system"
- fi
- read -r -p 'Enter a subject: ' subject
- read -r -p 'Enter a file: ' file
- if [ $file = *.txt ]
- then
- mail -s "$subject" "$user" < "$file"
- else
- echo "Attach .txt files only"
- fi
- rm /tmp/user
- read -r -p 'Please [ENTER] to continue...'
- clear
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement