Sponsored Content
Homework and Emergencies Homework & Coursework Questions How to read user keyboard input inside the case? Post 302728369 by femchi on Wednesday 7th of November 2012 05:29:40 PM
Old 11-07-2012
How to read user keyboard input inside the case?

I need to Write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. with automated following tasks:

Copy directory tree
Delete files or directories
Output Information (this part is done )

*Copy directory tree
The “Copy directory tree” selection should prompt for two arguments: src & dest.
The script then copies all the files from src, including all the subdirectories, to dest,
creating all the necessary sub-directories.
The script must perform necessary argument validation, assuming that the first argument may be either a directory name or the name of a regular file, while the second may be only a directory name.

my problem with this assignment is I can not read user input inside the "case" options.
I think I need to ask user to enter src and dest for copying the files.

this is my code so far

Code:
#!/bin/sh
clear
	echo "\t `date "+%d/%m/%Y"`"
	echo "\t Hostname Machine: `hostname`"
	echo "\t user: `whoami` "
	echo "\t M A I N - M E N U"
	echo "\t 1.Copey Directory Tree"
	echo "\t 2.Delete Files or Directories"
	echo "\t 3.Output Information"
while true ; do
	echo -n "\t Please enter an option [ 1 - 4 ] : "
	read opt

	case "$opt" in
		1) echo "Enter the source and destination for copying files" ;; 
		
		#read src dest ;;
		#echo "$src" ;;
		#echo "$dest" ;;

		2)  ;;

		3) echo "\t the number of possible users on the system: `cat /etc/passwd |wc -l` \n\t the number of current user on the system : `who | wc -l`\n\t the number of processes running: `ps -e | wc -l`"  ;;


		*) exit ;; 
	esac
done


Langara College , Vancouver , Canada , Hengameh Hamavand , CPSC 1280
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input inside while read loop

Hi all Does anyone have a script that will allow me to stop inside a while read loop. I want to pause the loop until a enter is pressed. e.g. While read line do echo something if LINECOUNT > 40 then read ENTER?"PRESS ENTER TO CONT..." ... (3 Replies)
Discussion started by: jhansrod
3 Replies

2. Shell Programming and Scripting

read command (input) inside the while loop

Hi, 'read' command is not working inside the while loop, How can I solve this? Rgds, Sharif. (2 Replies)
Discussion started by: sharif
2 Replies

3. UNIX for Dummies Questions & Answers

Testing for correct user input from keyboard

What script can I use to catch errors in a shell script if user inputs alpha numeric characters instead on integers from the keyboard? (0 Replies)
Discussion started by: Pauline mugisha
0 Replies

4. Shell Programming and Scripting

To ignore user input case.

hi, i will like to know whether awk command can ignore case? i written a script that will take in user input and search for data on the 1st field from a text file. echo -n "Title:" read title awk -F":" '$1~/'"$title"'/{print $0}' Filename read ans return ... (5 Replies)
Discussion started by: Cheranime
5 Replies

5. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

6. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies

7. Programming

Keyboard User Input in awk language ?

Hi, does someone know how to make a keyboard data input in the AWK programming language ? Regards Zabo (6 Replies)
Discussion started by: Zabo
6 Replies

8. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

9. UNIX for Beginners Questions & Answers

Case inside While read File

Hi Experts, Need your guidance for case statement. I tried many way but no success yet.Now my existing code is doing something like below. Each Line of the input file contains one test case.#!/bin/bash FILE=$1 while read LINE; do do COMMAND done < $FILE Now I want to modify the code... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies

10. Shell Programming and Scripting

Bash read input in case statement not working as expected

I'm having an issue with bash read input when using a case statement. The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here. defaultans=8hrs read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Discussion started by: woodson2
5 Replies
CGCLEAR(1)							 libcgroup Manual							CGCLEAR(1)

NAME
cgclear - unload the cgroup filesystem SYNOPSIS
cgclear [-e] [-l <filename>] [-L <directory>] [...] DESCRIPTION
Without parameters, this command moves all the tasks inside the various cgroups to the root cgroup, deletes all the cgroups and finally unmounts the cgroup filesystem from the system. If one or more config files are specified, only groups defined in the config files are removed. The files are processed in reverse order, i.e. the last file on command line is processed first, so cgclear can have the same command line arguments as appropriate cgconfigparser. -l, --load=<filename> specifies the config file to read. This option can be used multiple times and can be mixed with -L option. -L, --load-directory=<directory> specifies the directory, which is searched for configuration files. All files in this directory will be processed in alphabetical order as they were specified by -l option. This option can be used multiple times and can be mixed with -l option. -e specifies that only empty groups should be removed. If a group defined in a config file has tasks inside or has a subgroup, it won't be removed. This option works only with -l or -L options. ENVIRONMENT VARIABLES
CGROUP_LOGLEVEL controls verbosity of the tool. Allowed values are DEBUG, INFO, WARNING or ERROR. SEE ALSO
cgconfigparser(1) Linux 2009-10-23 CGCLEAR(1)
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy