Sponsored Content
Top Forums UNIX for Dummies Questions & Answers If user input matches file contents Post 302759525 by DBnixUser on Tuesday 22nd of January 2013 12:28:01 PM
Old 01-22-2013
If user input matches file contents

I was wondering how I can read values from a file and then proceed if those values
match a user input. For example (a simple one), a user inputs their name, then we check if that name is in a file of usernames. If it is, it says proceed, if not, then it says you are not authorized.

Code:
userlist=`cat /home/user1/user_list.txt`
echo "Enter your username:"
read username
if [[ $username = $userlist ]];then
    echo "You may proceed"
else
   echo "You are not authorized"
exit
fi

userlist.txt:
Code:
bjames
jbryant


Last edited by Scrutinizer; 01-22-2013 at 02:08 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

3. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

4. Shell Programming and Scripting

Take user input and then append to another file

Hi, I have below line from the config file $__MR_CONFIG = 'userinput'; I want to get the value from the user for the "userinput" and then append the full line to another file. Can you please let me know how can I proceed on this? I am new to unix and your help is greatly appreciated.... (3 Replies)
Discussion started by: nav123
3 Replies

5. UNIX for Dummies Questions & Answers

how to place input from user into a file

as the title, how can i allow a user to key in one's name, birthday and email address and save it into a specific file i have created earlier? thank you so much for any reply. (3 Replies)
Discussion started by: branred
3 Replies

6. Solaris

Processing user input in .sh file

Hi, I am new to shell scripting. script should accept the user value and then compare that value with the null. If null then assign the value "*" to the variable else will use the user inputed value. How to do this ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

7. Shell Programming and Scripting

remove contents including the tag if pattern matches

Hi all, Can anyone help me on this. I have several WP sites that are affected by sql injections. But the contents are different as follows western union india belgaum western union india bolegaon western union india barhaj western union india budhana western union india belda western... (6 Replies)
Discussion started by: sanjuabraham
6 Replies

8. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

9. UNIX for Dummies Questions & Answers

User input while reading from a file

I am not able to capture the user input in this script(bash).There is prompt for user input.Could some one help me capture user input while reading afile? while read line do echo "$i" path1=$line path2=`echo $line|sed s/new_dir/old_dir/` echo "Do you want to replace?";... (4 Replies)
Discussion started by: parijat guh
4 Replies

10. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies
USERLIST(8)						      Finger-type Userlisting						       USERLIST(8)

NAME
       userlist - Userlisting of who's on your system.

SYNOPSIS
       userlist

DESCRIPTION
       This  program simply gives you a listing of who is connected to your system.  It is used primarily in the sorted listing of cfingerd, which
       utilitizes the same method of display for a more uniform output between systems.  (It also made more sense to do it  this  way  instead	of
       having jumbled up display listings in sorted finger displays.  Besides, it made more sense to do this than use finger.  :)

       This program functions with the same types of things in mind that cfingerd does.  If the user has a .nofinger file, their username will not
       be displayed in the userlisting.

       Example output is shown as:

	Username Real Name	Idletime TTY Remote console
	username I'm real ...	9d 23:59   0 (remote.site.com)

       where it would display the user's login name, the user's real name, their idle time given in the format "dd hh:mm", their  TTY,	and  their
       remote location (or where they're telnetting from).

       If  the	username  is  over  8  characters, the program will not search for their information in the passwd file, since it may be too long.
       Besides, it checks getpwnam, anyway.  :)

OPTIONS
       -c     Give standard CFINGERD (custom) output.

       -n     List only people idle less than one day.

ADDITIONAL
       Although userlist is not required to run as suid root, it is a good idea.  The reason is it checks each users' directory  for  a  .nofinger
       file.  If indeed that user has a .nofinger file in his/her directory, that user will not be shown in the userlisting.

       If  you change the program to run as nobody.nobody, you are free to do so.  But you will also show the users if they are online, regardless
       of whether or not they have a ".nofinger" file (as long as their directory is NOT world-readable.)

CONTACTING
       If you like this program, have any suggestions on how it could be modified, or have bug reports, please write to: khollis@bitgate.com.

       Your continued Public Domain support is appreciated!  Thanks.

SEE ALSO
       cfingerd.conf(5), cfingerd(8), finger(1).

cfingerd 1.4.2							  29 August 1999						       USERLIST(8)
All times are GMT -4. The time now is 06:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy