Sponsored Content
Homework and Emergencies Homework & Coursework Questions Understanding Getopts in an otherwise easy assignment Post 302892906 by ByronicX on Saturday 15th of March 2014 04:54:54 PM
Old 03-15-2014
Understanding Getopts in an otherwise easy assignment

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

In the command line I will be given files or words which will be USER ID's or a file of USER ID's. I am to let the user of the script know when any of these individuals log in. I can do it a certain why, which is unacceptable.

I could do this without the getopts command, instead I would just write to files and grep each line (each line would be a user ID) and finger it to see if they are on or not.

My problem is after looking all over for information on getopts, it's not making sense to me. I've been messing around with this exampe:

Code:
while getopts ":afz" option;
do
    case $option in
        a)
            echo recieved -a
            ;;
        f)
            echo recieved -f
            ;;
        z)
            echo recieved -z
            ;;
        *)
            echo "invalid option -$OPTARG"
            ;;
        esac
    done


2. Relevant commands, code, scripts, algorithms:

Mainly getopts is encouraged to be used.


3. The attempts at a solution (include all code and scripts):

With the getopts I've been messing with, I realize if I type anything but -a, -f, or -z I will get the *) option which is "invalid option". if I type -z -a or -f, it will of course echo the received thing. My problem is how can I make -a -z -f options to see if file is readable, or to see if the user is a valid userid, or to see if they are even on. Basically, I am obviously not putting 2 and 2 together to see how getopt is handy in this case. I'm assuming if i make -z -a or -f various options like I stated, it ought to work, but honestly, I don't know how to do this, very frustrating.

What I'm asking perhaps, is if I can see an example that is related to my issue, and perhaps an explanation to allow me to complete this.

If I could see how this getopts thing is used for such a case, I'm sure I could do it, because I can do it without getopts!

I've been looking at alternative solutions, but due to scoping issues, I see no other option but to write to a file (which is not allowed for this assignment). and parse the file line by line using finger/grep.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
USML, St. Louis, Unix Programming, actually this link has it all:
//*******/~antognolij/cs2750.html
replace ******* with umsl.edu
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to do my assignment?????

my lecturer want to do an assignment about telnet server..first, he want us to download the telnet server..then he want we do about copy files and share files by using the telnet server....what is that??? and one more thing is how to do 'ping'???? (1 Reply)
Discussion started by: amelia
1 Replies

2. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

3. What is on Your Mind?

New Assignment

All Sys Administrators, With due respect I would like to know what should be BEST Things to do when LEAVING one job , and what Precaution MUST be taken while taking over new JOB?? Please Discuss in detail the STEP to be taken for both the TIME ?? (3 Replies)
Discussion started by: vakharia Mahesh
3 Replies

4. Shell Programming and Scripting

using getopts

Hi, I have a program where I want to use getopts. I want to use "-i" option and then optionally supply arguments. If user dosent supply arguments, then also it should work. Please tell me how to proceed. Here is some code, this is not right code btw but a sample to understand what I want to... (1 Reply)
Discussion started by: som.nitk
1 Replies

5. Programming

Help understanding pointer assignment in c

after some years of pause, im returning to c. char *varname = "asd"; int *number = 4; the above code is wrong, because its assigning a value to an unreserved space, or because its changing the address the pointer is pointing ? thanks for the replys!! (3 Replies)
Discussion started by: broli
3 Replies

6. Shell Programming and Scripting

RE value assignment

Hi all How do I assign a pattern to a variable after a match is found using a regular expression in PERL? For example using a regular expression (RE) and matching as given if ($_ =~ /(?:\s*+\s*,)*\s*+\s*/) I want to assign the pattern matched by the RE to a variable. e.g. given the... (4 Replies)
Discussion started by: my_Perl
4 Replies

7. Homework & Coursework Questions

Assignment Help

1. List commands to create the directory hierarchy $HOME/a/b/c in vi to replace all occurences of TMP with tmp in lines 1 through 10 in vi to replace first occurence of CPU_file with DISK_file at line 15 2. Explain with a very simple example, usage of "ls -a" 3. What do the... (2 Replies)
Discussion started by: jessesaini
2 Replies

8. Shell Programming and Scripting

Help Assignment !! :D

Q-1 Write a shell script in Unix that lists files from your current working directory · By modification time when called with lm · By access time when called with la. By default, the script should show the listing of all the files in the current directory. Q-2 Write a... (1 Reply)
Discussion started by: Vishank Parikh
1 Replies

9. Homework & Coursework Questions

Help Assignment !! :D

Q-1 Write a shell script in Unix that lists files from your current working directory · By modification time when called with lm · By access time when called with la. By default, the script should show the listing of all the files in the current directory. Q-2 Write a shell script which... (1 Reply)
Discussion started by: Vishank Parikh
1 Replies

10. UNIX for Dummies Questions & Answers

Need a little help with assignment

Hello all im currently working on this assignment and a little stump on how to check for an argument heres the instructions: Step 4: Modify your script so that if there is an argument called TestError you display the following error message with your usage statement. TestError found Example:... (1 Reply)
Discussion started by: bsn3971
1 Replies
DEBCONF-MERGETEMPLATE(1)					      Debconf						  DEBCONF-MERGETEMPLATE(1)

NAME
debconf-mergetemplate - merge together multiple debconf template files SYNOPSIS
debconf-mergetemplate [options] [templates.ll ...] templates DESCRIPTION
Note: This utility is deprecated. You should switch to using po-debconf's po2debconf program. This program is useful if you have multiple debconf templates files which you want to merge together into one big file. All the specified files will be read in, merged, and output to standard output. This can be especially useful if you are dealing with translated template files. In this case, you might have your main template file, plus several other files provided by the translators. These files will have translated fields in them, and maybe the translators left in the english versions of the fields they translated, for their reference. So, you want to merge together all the translated templates files with your main templates file. Any fields that are unique to the translated files need to be added in to the correct templates, but any fields they have in common should be superseded by the fields in the main file (which might be more up-to-date). This program handles that case properly, just list each of the translated templates files, and then your main templates file last. OPTIONS
--outdated Merge in even outdated translations. The default is to drop them with a warning message. --drop-old-templates If a translation has an entire template that is not in the master file (and thus is probably an old template), drop that entire template. SEE ALSO
debconf-getlang(1) AUTHOR
Joey Hess <joeyh@debian.org> 2012-09-10 DEBCONF-MERGETEMPLATE(1)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy