Sponsored Content
Top Forums Shell Programming and Scripting Unix Shell basic loop massive n00b Post 302552089 by thurft on Thursday 1st of September 2011 03:15:56 PM
Old 09-01-2011
Error Unix Shell basic loop massive n00b

hey guys
I would really appreciate some help, i need to do a project for a job that requires minimal UNIX scripting and im REALLY stuck

basically Im stuck at what i believe is something really simple but i just dont have a clue how to do it efficiently and properly and i REALLY appreciate some help

Basically i have a loop at which someone has to enter a string of 3 numbers.

-I want the code to check that the string is numbers only
-check that the numbers have not been already signed to someone else in the users.db file
-restrict the number of numbers to only 3.

- each time the user inputs the number wrong i want it to be allowed to correct and tell why he has to re enter it.

This is the best i could came up with but IM REALLY suck and im at a short UNIX course (1 week) for a job....

Can anyone please tell how do i make the loop properly??

this is the best i could came up with... and i KNOW is crap... but i just dont know best........ I would really appreciate some guidance plz

Code:
#!/bin/bash
echo -e  "Create a new record\n"

fSID (){
read -p "Please enter staff ID: " cSID
}

fSID

gcSID=$(grep $cSID users.db | cut -d ":" -f1 | tr [":"] [" "])
wcSID=$(echo $cSID | wc -c) 

case "$cSID" in
      [!0-9]*         ) echo -e "The staff ID should contain only digits\n "
	  sleep 0.5
	  fSID;;
                  
esac  
    while [ $wcSID -gt 4 ]; do 

  read -p "Please enter a value: " cSID 
wcSID=$(echo $cSID | wc -c) 
echo $wcSID
done 
read -p "u passed to stage 2! gratz" st2


Last edited by pludi; 09-01-2011 at 05:09 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Absolute n00b questions about Unix / Linux

Hi All, I have absolutely no experince with either one, and would LOVE to start from somewhere! So please guide me to some web sites (beside these great forums of course!) that I can obtain n00b information. (Books, links, resources, etc.) What software OS? should I begin with? I have heard... (2 Replies)
Discussion started by: CodeHunter
2 Replies

2. UNIX for Dummies Questions & Answers

A basic question of FOR loop

Hi, have a basic query. Please see the below code: list="one two three" for var in $list ; do echo $var list="nolist" Done Wht if I want to print only first/ last line in the list Eg one & three Regards er_ashu (3 Replies)
Discussion started by: er_ashu
3 Replies

3. Shell Programming and Scripting

unix shell basic

need some help badly. if i had a file with content of few lines like the followings. 1183724770.651 0.049 137.157.56.169 200 415 GET http://venus/client/clients.xml "text/xml" 1183724770.651 0.049 141.183.101.250 200 415 GET http://venus/client/clients.xml "text/xml" using what command... (1 Reply)
Discussion started by: akagi07
1 Replies

4. Programming

Creating a basic UNIX shell script for chatting

Hey guys, This is quite simply what I'm trying to make: A program that runs in a UNIX terminal that you can output text messages to from another machine. These text messages would be prepended with a customized prompt. I'd also like to have the window spew out random dumps of flavor text not... (1 Reply)
Discussion started by: AcerAspirant
1 Replies

5. Shell Programming and Scripting

Shell Scripting n00b

Hey Guys! I was hoping for some help with a simple script I'm trying to use. I have the script set up to pull some simple information out of a database .txt file and sed it into a preexisting template for assignment cover letters. The problem seems to be someplace in the sed statement but I... (5 Replies)
Discussion started by: BFeicht
5 Replies

6. Shell Programming and Scripting

Help required on basic Unix Bourne Shell Script

Howdy People :), I'm a newbie & its my first question here. I've started learning Unix Bourne Shell scripting recently and struggling already :p Can someone PLEASE help me with the following problem. Somehow my script is not working. Display an initial prompt of the form: Welcome to... (1 Reply)
Discussion started by: methopoth
1 Replies

7. Shell Programming and Scripting

which is the Very basic certification on unix shell scripting?

Hi, I am very new to this forum, can any one tell me which is the very basic certification on unix shell scripting? please give me an advice on this. (1 Reply)
Discussion started by: Manjesh
1 Replies

8. Shell Programming and Scripting

Shell pipeline help for a n00b

I need to read input from a file, and make sure nothing prints after column 72. basically, ignore input after character 72 until the next newline character. Any help is appreciated. I have been searching forever! (10 Replies)
Discussion started by: Gbear
10 Replies

9. UNIX for Dummies Questions & Answers

Basic loop awk/shell script question..

Hi, Sorry if this is a newbie question. I guess you can use either awk or shell script for this sequence of operations, but knowing very little about either of them I'm not sure how I should try to write this. The basic objective is to copy certain files that are scattered all over my... (10 Replies)
Discussion started by: pc2001
10 Replies

10. Shell Programming and Scripting

Basic FOR loop with break

Oracle Linux : 6.4/bash shell In the below I want to break out of the loop when it enters the 5th iteration. #!/bin/bash for i in 1 2 3 4 5 6 do echo "$i" if echo "Oh Nooo... i = $i. I need to stop the iteration and jump out of the loop" then break fi done But, it only... (3 Replies)
Discussion started by: John K
3 Replies
at(1)							      General Commands Manual							     at(1)

NAME
at, batch - Runs commands at a later time SYNOPSIS
at [-c | -s | -k] [-m] [-f file] [-q queuename] time [date] [+increment] [command | file]... at [-c | -s | -k] [-m] [-f file] [-q queuename] -t [[cc]yy] MMddhhmm [.ss] at -l -o [-q queuename] [user...] at -l [job_number] at -r [-Fi] job_number... | [-u user] at -n [user] batch The at and batch commands read from standard input or accept as arguments the names of commands to be run at a later time. The at command lets you specify when the commands are to be run. The batch command runs jobs when the system load level permits. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: at: XCU5.0 batch: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
[Tru64 UNIX] Requests that csh be used for executing this job. Specifies the name of the file to use instead of stdin. The specified file contains the list of commands to be executed. [Tru64 UNIX] Suppresses delete verification. [Tru64 UNIX] Specifies interactive delete. [Tru64 UNIX] Requests that ksh be used for executing this job. Reports your scheduled jobs. [Tru64 UNIX] If the root user issues the command with this option, all of the queued at commands are listed with the name of the user who issued each one. The root user can also request a report of scheduled jobs for the specified user only. Mails a message about the successful execution of the command. Standard output and standard error are also mailed if they are generated and are not redirected. This is the default for standard output and standard error. Without the -m option, there is no notification of job completion, and no mail if standard output and standard error were not generated. [Tru64 UNIX] Requests the number of files in the queue for the current user. The root user can specify a different user with the user argument. [Tru64 UNIX] Lists jobs in sched- uled order. This option is useful only when used with the -l option. Specifies the queue you want to use. When used with the -l option, limits the search to the specified queue. Values for queuename are limited to the lower case letters a through z. By default, at jobs are scheduled in queue a and batch jobs are scheduled in queue b. Since queue c is reserved for cron jobs, it can not be used with the -q option. Removes a job previously scheduled by at or batch, where job_number is the number assigned by at or batch. If you do not have root user authority, you can remove only your own jobs. The atrm command is available to the root user to remove jobs issued by other users or all jobs issued by a specific user. This option can be used in combination with the -i, -f, and -u options. [Tru64 UNIX] Requests that the Bourne shell be used for executing this job (default). [Tru64 UNIX] Submits the job to be run at the specified time. (See the SYNOPSIS section for the correct time format.) Deletes all jobs for the specified user. This option must be used with the -r option as fol- lows: at -r -u user OPERANDS
[Tru64 UNIX] The operands associated with the at command specify the time at which the job should be run. They are described in the sec- tion Specifying a Time and Date. DESCRIPTION
Both at and batch mail you the standard output and standard error from the scheduled commands, unless you redirect that output. They also write the job number and the scheduled time to standard error. If a filename specified on an at command line is executable (that is, has the x permission for the user in question), at assumes that it is a command and the job consists of this command only. If the file is not executable, at assumes that you want its contents to be the instructions for the job (same as BSD at). [Tru64 UNIX] If at cannot find the file at all, the specification is passed to the date parser. If the specification is not recognized by the date parser, the user receives the error Unknown word. [Tru64 UNIX] The at command defaults to the Bourne shell. Use the -c option to specify the C shell, or the -k option to specify the Korn shell. Variables in the shell environment, the current directory, umask, and ulimit are retained when the commands run. The value of SHELL is set to be consistent with the shell actually used. Open file descriptors, traps, and priority are lost. You can use at if your login name appears in the /usr/lib/cron/at.allow file, if that file exists, or if there is no at.allow file and your name is not in the /usr/lib/cron/at.deny file. The at.allow and at.deny files contain one user name per line. Note that /usr/lib/cron is symbolically linked to /var/adm/cron. If neither the at.allow nor the at.deny file exists, only someone with root user authority can submit a job. To allow global access to at, the system administrator can remove the at.allow file and create a zero-length at.deny file. Specifying a Time and Date You must specify a time argument with these commands. You can specify optionally the date argument. These arguments are affected when the DATEMSK environment variable is set. The next subsection describes the effect of this environment variable. The required time argument can be one of the following: A number followed by an optional suffix. The at command interprets 1- and 2-digit numbers as hours. It interprets 4 digits as hours and minutes. The LC_TIME environment variable specifies the order of hours and minutes. The default order is the hour followed by the minute. You can also separate hours and minutes with a : (colon). The default order is hour:minute. In addition, you can specify a suffix of am, pm, or zulu. If you do not specify am or pm, at uses a 24-hour clock. The suf- fix zulu indicates that the time is UTC (Coordinated Universal Time). The at command also recognizes the following keywords as special times: noon, midnight, now, A for a.m., P for p.m., N for noon, and M for midnight. The time argument specifies a time in the future. For example, if the current time is 9:02 p.m., and you specify a time of 9P, the command is executed at 9 p.m. the next day. However, if the current time is 8:58 p.m. and you specify 9P, the command is executed in two minutes. The LC_TIME environment variable controls the key- words that at recognizes. Keywords are defined on a locale basis. You can specify the date argument as either a month name and a day number (and possibly a year number preceded by a comma), or a day of the week. The LC_TIME environment variable specifies the order of the month name and day number (by default, month followed by day). The at command recognizes two special days, today and tomorrow by default. The special day today is the default date if the specified time is later than the current hour; the special day tomorrow is the default if the time is earlier than the current hour. If the specified month is less than the current month (and a year is not given), next year is the default year. The optional increment can be one of the following: A + (plus sign) followed by a number and one of the following words: minute[s], hour[s], day[s], week[s], month[s], year[s] (or their locale specific equivalents). The special word next followed by one of the following words: minute[s], hour[s], day[s], week[s], month[s], year[s] (or their local specific equivalents). Job numbers are specified as follows: user.xxxxxxxxx.y [Tru64 UNIX] The user argument identifies the user who scheduled the job; xxxxxxxxx is a 9-digit number (encoded time for the job); and y indicates the job type or queue name as follows: Argument Job Type a at job b batch job e ksh job f csh job Setting the DATEMSK Environment Variable [Tru64 UNIX] If the DATEMSK environment variable is set, it points to a template file that the at command uses to determine the valid time and date arguments instead of the values described in the previous section. Specifically, noon, midnight, now, next, today, tomorrow, and increment are not recognized when the DATEMSK environment variable is set. [Tru64 UNIX] The entries in the template file used by the DATEMSK environment variable provide an expansive set of date formats available in different languages depending on the setting of the environment variable LANG or LC_TIME. The setlocale(3) reference page contains the list of field descriptors allowed in the template file. This list is a sublist of the field descriptors supported by the calendar command which are listed on the date(1) reference page. EXIT STATUS
The following exit values are returned: The at command successfully submitted, removed, or listed all specified jobs. An error occurred. EXAMPLES
To schedule a command from a terminal, enter a command similar to one of the following: at 5 pm Friday uuclean at now next week uuclean at now + 2 days uuclean The preceding commands can be scheduled as shown only if uuclean is in the current directory. To run uuclean at 3:00 in the after- noon on January 24, enter any one of the following commands: echo uuclean | at 3:00 pm January 24 echo uuclean | at 3pm Jan 24 echo uuclean | at 1500 jan 24 To list the jobs you have sent to be run later, enter: at -l To cancel jobs, enter: at -r julie.586748399.a This cancels job julie.586748399. Use at -l to list the job numbers assigned to your jobs. To execute a command when the system load level permits, enter: batch nroff infile > outfile <Ctrl-d> where <Ctrl-d> is the End-of-File character. Assume a template file, /var/tmp/AT.TEMPL, contains the following: %I %p, the %est of %B of the %Y run the following job %I %p, the %end of %B of the %Y run the following job %I %p, the %erd of %B of the %Y run the following job %I %p, the %eth of %B of the %Y run the following job %d/%m/%y %H:%M:%S %I:%M%p To invoke the at command when the DATEMSK environment variable is set to /var/tmp/AT.TEMPL, and the template file any of the follow- ing are valid: at 2 pm, the 3rd of July of the year 2000 run the following job at 3/4/99 at 10:30:30 at 2:30pm FILES
Main cron directory List of allowed users List of denied users Spool area History information for cron Queue description file for at, batch, and cron SEE ALSO
Commands: atq(1), atrm(1), calendar(1), csh(1), cron(8), date(1), kill(1), mail(1), binmail(1), ksh(1), mailx(1), Mail(1), nice(1), ps(1), Bourne shell sh(1b), POSIX shell sh(1p) Functions: setlocale(3) Standards: standards(5) Files: queuedefs(4) System Administration Network Administration Command and Shell User's Guide at(1)
All times are GMT -4. The time now is 10:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy