遊客:  註冊 | 登錄 | 幫助





標題: [求助] 唔識寫呢個script in Linux.....
msr     Rank: 3
青出藍
性別 保密
UID 1322

精華 0
帖子 57
積分 141   詳情

閱讀權限 40
註冊 2006-7-19
來自
狀態 離線

 
 
 
 
發表於 2007-6-6 11:44 AM  資料  個人空間  短訊  加為好友 
唔識寫呢個script in Linux.....

有個朋友問我點寫script in linux...可能放低本書太耐唔記得晒...我想各位高手指點下...佢話呢份係assignment...星期五due...我睇完好似好易...又好好難咁...請大家幫下手...順便喚醒我失去既記憶... 唔該晒!!

Clear the terminal window and presents a menu with the following options:
a) Add a user
b) Delete a user
c) Reset a password
d) Check Disk Quota
e) Exit

For a), the admin should be prompted for:
New user's user name
New user's full name
New user's account expiration date
New user's group
Ask the admin to confirm all details before creating the account

For b), the adim should be prompted for:
The user's user name
Ask the admin to confirm the name before deleting the account

For c), the admin should be prompted for:
The user's user name
Ask the admin to confirm the user name
The new password

For d), the admin should be prompted for:
The user's user name
Ask the admin to confirm the user name
Display a summary of the disk space used in the user's home directory

The menu should continue to execute until "e" is pressed

我都要搵返d書去睇下...大家都幫下手...唔該晒

頂部

mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-6-8 06:46 AM  資料  個人空間  短訊  加為好友 
Hmm.. shell script 我唔係好熟﹐幫您唔到添!  sorry 呀!  (

頂部



snaku     Rank: 8Rank: 8Rank: 8Rank: 8
超級版主
性別 男
UID 2

精華 0
帖子 133
積分 175   詳情

閱讀權限 180
註冊 2006-1-27
來自
狀態 離線

 
 
 
 
發表於 2007-6-8 10:48 AM  資料  個人空間  短訊  加為好友  Gmail Yahoo!
The point is to show how to write unix shell script. So I wrote the menu by using function. You can just fill in the sub menu function for a, b, c, and d which should be quite straight forward.

Hope this helps

#!/bin/bash
# simpmenu, A very simple menu
# menu() defines a function to display menu
menu () {
# clear the screen
clear
echo
echo "a. Add a user"
echo "b. Delete a user"
echo "c. Reset a password"
echo "d. Check Disk Quota"
echo "e. Exit"
echo Select by pressing a number and then ENTER ;
}

# A function that asks the user to press enter
# and waits for the ENTER Key
PressEnter () {
  echo Press Enter
  read x
}

#
# Function for adding user
#
adduser () {
  #
  # put your adduser code below
  #
  PressEnter
}
#
# Function for user deletion
#
deleteuser ()
{
  #
  # put your delete user code below
  #
  PressEnter
}

#
# Function for reset password
#
resetpassword () {
  #
  # put your reset password code below
  #
  PressEnter
}

#
# Function for displaying disk quota
#
diskquota () {
  #
  # put your code below to display disk quota
  #
  PressEnter
}
while  true
do
# 1. display the menu
  menu

# 2. read a line of input from the keyboard
  read answer

# 3. Execute one of the defined functions based on the
#    number entered by the user.

  case $answer in
      a) adduser ;;
      b) deleteuser ;;
      c) resetpassword ;;
      d) diskquota ;;

#      If the user selects 0 to exit then break out
#      of this loop
      e) break ;;
  esac

done

# Clear the screen on the way out
clear

頂部

msr     Rank: 3
青出藍
性別 保密
UID 1322

精華 0
帖子 57
積分 141   詳情

閱讀權限 40
註冊 2006-7-19
來自
狀態 離線

 
 
 
 
發表於 2007-6-8 01:29 PM  資料  個人空間  短訊  加為好友 
唔該晒...不過我都同個朋友都究竟左...可以叫勉強做完...不過冇你地個咁好...再一次thank you

頂部

mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-6-13 02:46 AM  資料  個人空間  短訊  加為好友 
等我都學下野先!  

msr, 您可唔可以 post 埋您朋友既 solution 出黎俾我比較下?  

頂部

msr     Rank: 3
青出藍
性別 保密
UID 1322

精華 0
帖子 57
積分 141   詳情

閱讀權限 40
註冊 2006-7-19
來自
狀態 離線

 
 
 
 
發表於 2007-6-13 12:42 PM  資料  個人空間  短訊  加為好友 
可以..不過要問佢先..等多幾日

頂部

快速美言
           


當前時區 GMT+8, 現在時間是 2024-11-27 05:02 AM

    Powered by Discuz!  © 2001-2007 Comsenz Inc.   
Processed in 0.020454 second(s), 8 queries

清除 Cookies - 聯繫我們 - LIPS Corner 新天藍 - Archiver