Shell Script for User AUTH Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script for User AUTH Help
# 1  
Old 02-17-2011
Bug Shell Script for User AUTH Help

Code:
#!/usr/bin/ksh
/bin/clear

LIST_USERS="user1|user2|user"

echo "Please enter the PASSWORD:"
stty -echo
read PASSWORD
stty echo

if [ "$PASSWORD" = = "$LIST_USERS" ]; then
        echo "You have access!"
else
        echo "ACCESS DENIED!"
exit
fi

This above script is not working when I auth more then one user w/in script - any help here appreciated - I shall summarize.

Last edited by Franklin52; 02-17-2011 at 03:53 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-17-2011
I could be wrong but I believe you need to have each user quoted separately. I'm just looking at it and it looks like LIST_USERS should be

Code:
LIST_USERS="user1"|"user2"|"user"

Chances are I'm wrong tho...Just looks like quoting it your way quotes that entire string as one string of user1|user2|user and not user1, user2,user etc.

Also I believe you need only one "=" to test strings. So:
Code:
 if [ "$PASSWORD" = "$LIST_USERS" ]; then

# 3  
Old 02-17-2011
Nope I tried that - that doesn't work too.
# 4  
Old 02-17-2011
Question, why would the username (I'm assuming user1,user2,and user are usernames) equal the password?
# 5  
Old 02-17-2011
Code:
/bin/clear
echo "Please enter the PASSWORD:"
stty -echo
read PASSWORD
stty echo
LIST_USERS="user1"|"user2"|"user"
for i in $(echo "$List" | sed "s/|/ /g");do
 if [[ "$PASSWORD" == "$i" ]];then
echo "Fine!"
else
echo "Not Good!"
exit
fi
done

Even this w/o any good results.

Last edited by Franklin52; 02-17-2011 at 03:53 AM.. Reason: Please use code tags
# 6  
Old 02-17-2011
Your for loop is looking for $List, where's $List? Don't you mean $LIST_USERS?

but again i'm curious why your password variable is equal to your user variable. Do your users have the same pass as their username? also, string comparisons are done with one equals sign [ $PASSWORD = $i ]

---------- Post updated at 11:33 PM ---------- Previous update was at 11:19 PM ----------

Code:
 #!/bin/sh
/bin/clear
echo "What's your user name?"
 read usrName
usrPass=""
case $usrName in
         user1) usrPass="pass1"
         break
;;
         user2) usrPass="pass2"
         break
;;
         user3) usrPass="pass3"
         break
;;
         *) echo "Invalid username"
         exit 1
;;
esac
echo "What's your password?"
read usrPwdin
[ $usrPass != $usrPwdin ] && echo "Incorrect password" && exit 1
echo "Password accepted"
# do stuff here...

I'm still learning myself, but I whipped this up for you. Maybe it can help...
This User Gave Thanks to DC Slick For This Post:
# 7  
Old 02-17-2011
This is alomost done my requirement but, still not 100% - first of all thanks so much.

my requirement is to supply set os usernames who can excute the script against the passwd file or texting in the script itself. What do you say?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP script that detects if auth is required or not on Apache Splunk

I am currently trying to do a PHP script that detects automatically if Apache Splunk authentication is required or not but I'm having a hard time since HTTP code 303 is always coming back, even if auth is required or not. Here is the script so far; <?php /** * Apache Splunk script to... (4 Replies)
Discussion started by: syrius
4 Replies

2. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. Red Hat

Proxy auth fails in shell

hi I am using RHEL 5.5. I updated the http-proxy like this http_proxy=http://username:password@IP:port/ When i do ping www.google.com PING www.l.google.com (74.125.236.177) 56(84) bytes of data. then it goes blank. I dont know why. But in the same linux, in gui mode. In... (2 Replies)
Discussion started by: gnanagurus
2 Replies

6. Shell Programming and Scripting

Shell Script to change a user password using script

Hi Experts, I had tried to executes this script to change the user password through script: No lines in buffer #!/bin/ksh cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1 cat /etc/passwd | grep userid >> /tmp/pass.tmp2 PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2` PASS2=`q2w3e4r5` sed... (3 Replies)
Discussion started by: indrajit_renu
3 Replies

7. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

8. Shell Programming and Scripting

How do i change to super user then revert back to ordinary user ,using shell script?

Hi all, I am trying to eject the cdrom from a livecd after certain stage... Now assuming that it is possible to eject,please consider my issue!!! The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive... However if i try pfexec eject it... (3 Replies)
Discussion started by: wrapster
3 Replies

9. Shell Programming and Scripting

su to another user in shell script

Hi All, I want some help in creating a shell script. I am running a script thru user1, then I need to su to user2, run a script from that user and return back to user1 and proceed further. Please help me. Abhi (1 Reply)
Discussion started by: akdwivedi
1 Replies

10. UNIX for Dummies Questions & Answers

User Shell script

I'm very new at this -- HELP! I need to know how to terminate a users session when they exit a shell script menu? Any ideas would be much appreciated! Holli (2 Replies)
Discussion started by: HOlli
2 Replies
Login or Register to Ask a Question