Linux small experiment - attendance simulation program

Task:

Design an attendance simulation program to implement the following function selection interface, requiring the use of functions

          1. Sign in at work

         2. Check out after work

         3. Check absence information

         4. Exit

   After the attendance program runs, the user is prompted to input the above function selection, and the user name and password input by the user are verified; the user information is stored in userinfo.dat .

   If it is a work check-in, record the check-in information. If the check-in time is greater than 8:00 am , the user will be prompted to be late, and the lateness information will be recorded in check.dat .

   If it is to check out after work, record the check-out information. If the check-out time is less than 6:00 pm , prompt the user to leave early, and record the early leave information to check.dat .

   If the user chooses to query the absence information, the late arrival and early departure information corresponding to the user in check.dat will be found out and displayed.

   After the user selects the function to execute, the shell program continues to return to the function selection interface and waits for the next user to operate.

Code:

 

  1 #!/usr/bin/ env bash
   2  # Attendance simulation program
   3  #Author: Yu Xiuyan
   4 # date  2018 / 04 / 08 
  5  function main(){
   6      echo  " ----------- ------------------------------------------------- " 
  7      echo  "           Welcome to the attendance program!                 " 
  8  echo  " -------------------------------------- ---------------------- " 
  9  
10  createInfoFile;
 11  
12      read -p "Please enter your username: " username
 13 read -p " Please enter your password: " password
 14  
15  isLogin $username $password;
 16  
17      while [[ 1 == 1 ]];
 18      do 
19          menu;
 20          read -p " Please enter your choice: " choice
 21          case $choice in 
22              1 )
 23                  signIn $username;
 24                  ;;
 25              2 )
 26                 logOff $username;
 27                  ;;
 28              3 )
 29                  absenceConsult $username;
 30                  ;;
 31              4 )
 32                  exit1;
 33                  ;;
 34              * )
 35                  echo -e " Please select function 1 or 2 or 3 or 4!\n " 
36                  ;;
 37          esac 
38      done 
39  
40  }
 41  #menu
 42  function menu(){
 43     echo  " ------------------------------------------------ ------------ " 
44      echo  "                    1. Check in at work               " 
45      echo  "                    2. Check out after work               " 
46      echo  "                    3. Check absence information           " 
47      echo  "                    4. Exit                   " 
48      echo  " - -------------------------------------------------- --------- "
49  }
 50  
51 #Check  account password
 52  function isLogin(){
53      while read line
 54      do 
55          if [[ " $line " == " $1:$2 " ]]; then 
56              return 0 
57          fi 
58      done < userinfo.dat #Read
 59 from the file      echo  "The username or password is incorrect, Please re-enter " 
60      read -p " Please enter your account: " username
 61      read -p " Please enter your password: " password
 62  isLogin $username $password;
 63 }
 64  
65 #Sign in at  work
 66  function signIn(){
 67      hour=` date +% H`
 68      if [[ $hour -gt 8 ]]; then 
69          echo  " You are late for work! The lateness information has been recorded in check .dat. " 
70          echo  " $1 late for work ------ date: `date` " >> check.dat
 71      else 
72          echo  " check in to work successfully! " 
73      fi 
74      main;
 75  }
 76  
77 #move  out after work
 78 function logOff(){
 79      echo  " Check out after work successfully! " 
80      hour=` date +% H`
 81      if [[ $hour -lt 18 ]]; then 
82          echo  " You are leaving early now! The early leave information has been recorded In check.dat. " 
83          echo  " $1 leave work early -- date: `date` " >> check.dat
 84      fi 
85      main;
 86  }
 87  
88 #absence  check
 89  function absenceConsult(){
 90      cat check. dat| grep-n " $1 " 
91  
92  }
 93  
94 #Exit  the program
 95  function exit1(){
 96      exit 0 
97  }
 98  
99 #Create  a configuration file
 100  function createInfoFile(){
 101      if [[ ! -e userinfo.dat ]]; then 
102          touch userinfo.dat #Save username and password
 103          chmod  777 userinfo.dat
 104      fi 
105      if [[ ! -e check.dat ]]; then 
106          touch check.dat #Save late arrival and early departure information
107          chmod  777 check.dat
 108      fi 
109  
110  }
 111  
112 #Execute  the main function
 113 main

 

 

result:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325818238&siteId=291194637