Bash, if or usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash, if or usage
# 1  
Old 04-19-2010
Bash, if or usage

Trying to find a better way to check $REMOTE_USER against a list of permiited users. The only way I can get it to work is to do a bunch of or statements shown here. My list of permitted users will be a dozen or so, I was hoping to list them in a variable or a file.
Code:
if [ $REMOTE_USER = "aa1234" ] || [ $REMOTE_USER = "zc1819" ] ; then
(Load this page) removed the details of this page load
else
echo "You do not have permission to view this page";
exit;
fi

# 2  
Old 04-19-2010
If you have all the allowed users in "file":
Code:
if echo "$REMOTE_USER" | grep -qxFf file; then
    echo allowed
else
    echo forbidden
fi

# 3  
Old 04-19-2010
You could use a case statement:

Code:
case $REMOTE_USER in
    joe|bob|elvis) echo ok ;;
    *) echo fail ;;
esac

js.
# 4  
Old 04-19-2010
@alister:
Like this I think you can lose the pipe, no?
Code:
if fgrep -qx "$REMOTE_USER" file; then
    echo allowed
else
    echo forbidden
fi

# 5  
Old 04-19-2010
Thanks everyone, all of these suggestions work. Now, just to decide which one to use Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. Shell Programming and Scripting

Detail on For loop for multiple file input and bash variable usage

Dear mentors, I just need little explanation regarding for loop to give input to awk script for file in `ls *.txt |sort -t"_" -k2n,2`; do awk script $file done which sorts file in order, and will input one after another file in order to awk script suppose if I have to input 2 or... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

3. Shell Programming and Scripting

What's wrong with me for "?" usage in bash

BIN="/usr/bin/$((`grep "CONFIG_X86_32=y" config`?386:x86_64))" (8 Replies)
Discussion started by: yanglei_fage
8 Replies

4. Shell Programming and Scripting

Help with bash script - Need to get CPU usage as a percentage

I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of... (3 Replies)
Discussion started by: graysky
3 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Shell Programming and Scripting

Kill -9 within Bash script kicks out usage info

I have a start|stop|restart script for a custom app we have. After it tries to stop our process the correct way, it checks to see if it's gone, if not it tries to kill it, if that doesn't work kill -9. If I run kill -9 on the PID from the command line it kills it and all is well. If I have the... (1 Reply)
Discussion started by: mglenney
1 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. UNIX for Dummies Questions & Answers

cut usage in bash

Hello, Could you put some light on this: > echo "ref_categorie=test" | cut -c1-15- test > echo "ref_categorie=test" | cut -c1-14- =test echo "ref_categorie=test" | cut -c15- test echo "ref_categorie=test" | cut -c15 t > It's executed on AIX if that matters. The man page is not very... (2 Replies)
Discussion started by: tsurko
2 Replies

9. Gentoo

cpu%/mem% usage, scripting, dzen2: howto learn bash the hard way

I am trying to write a small (and rather simple) script to gather some info about the system and piping it to dzen2 first, i want to explain some things. I know i could have used conky, but my intention was to expand my knowledge of bash, pipes and redirections inside a script, and to have fun... (14 Replies)
Discussion started by: broli
14 Replies

10. Shell Programming and Scripting

Basic bash 'for loop' usage

Hi! I have a simple question about using a for loop. I'm trying to open up all the zip files in the currect directory with ark, but I am getting the error "bash: syntax error near unexpected token `for $i ; do ark $i ; done ; I looked in the info pages for bash, but I can't seem to figure... (2 Replies)
Discussion started by: Orange Stripes
2 Replies
Login or Register to Ask a Question