Sponsored Content
Top Forums UNIX for Dummies Questions & Answers while loop not taking the not equal to condition Post 302222860 by joeyg on Thursday 7th of August 2008 05:19:10 PM
Old 08-07-2008
Question perhaps it is the logic?

You have or between each. I think you may want and logic.

simplified coding:
Code:
Enter a code
read ans
if [ $ans != "s" ] || [ $ans != "S" ]
 then
 echo "no more"
fi

Thus, enter "s"
if [ s != "s" ] || or [ s != "S" ]
becomes
if [ 0 ] || [ 1 ]
which is a 1

Often, when doing multiple conditions, != is with or while = is with and.
Thus, perhaps better if
Code:
if [ $ans != "s" ] && [ $ans != "S" ]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem taking input from file with for loop

I am trying to take input from a file and direct it into a bash script. This script is meant to be a foreach loop. I would like the script to process each item in the list one by one and direct the output to a file. # cat 1loop #!/bin/bash # this 2>&1 to redirect STDERR & STDOUT to file... (4 Replies)
Discussion started by: bash_in_my_head
4 Replies

2. Solaris

Infinite for loop is taking too much CPU usage %

Hi All, I wrote one simple for loop shell script which prints number..but this loop is infinite...but its taking lot of CPU (15.7) %. if i am using sleep cmd then cpu usage become 0.4 %. Is there anyway to reduce this CPU usage without using sleep cmd? i dont want 2 use sleep cmd... (7 Replies)
Discussion started by: pa.chidhambaram
7 Replies

3. Shell Programming and Scripting

For Loop Taking Too Long

I'm new from UNIX scripting. Please help. I have about 10,000 files from the $ROOTDIR/scp/inbox/string1 directory to compare with the 50 files from /$ROOTDIR/output/tma/pnt/bad/string1/ directory and it takes about 2 hours plus to complete the for loop. Is there a better way to re-write the... (5 Replies)
Discussion started by: hanie123
5 Replies

4. UNIX for Advanced & Expert Users

Comparison and For Loop Taking Too Long

I'd like to 1. Check and compare the 10,000 pnt files contains single record from the /$ROOTDIR/scp/inbox/string1 directory against 39 bad pnt files from the /$ROOTDIR/output/tma/pnt/bad/string1 directory based on the fam_id column value start at position 38 to 47 from the record below. Here is... (1 Reply)
Discussion started by: hanie123
1 Replies

5. Shell Programming and Scripting

if condition in a while loop

Gurus, I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error. #!/bin/ksh . /home/.i_env ... (14 Replies)
Discussion started by: svajhala
14 Replies

6. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

7. Shell Programming and Scripting

If not equal to then loop

How do I go about amending this simple script that prompts for a yes/no response so that if neither Y or N are entered it will loop back back to the original prompt #!/bin/ksh echo "Enter yes of no" read answer if then echo "You selected yes" elif then echo "You selected no" elif... (5 Replies)
Discussion started by: gmears
5 Replies

8. Shell Programming and Scripting

grep not equal to condition

I have below files under dir_a and dir_b and i want to sort out number of dir_a and dir_b files seperately and if i do the grep it should retrun 2 files in dir_a and 1 file in dir_b. /dir_a/12345678 /dir_a/87654321 /dir_a/dir_b/12345687 But i am getting cat file|grep dir_a|wc -l 3... (6 Replies)
Discussion started by: prash358
6 Replies

9. Shell Programming and Scripting

While loop problem taking too long

while read myhosts do while read discovered do echo "$discovered" done < $LOGFILE | grep -Pi "|" | egrep... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. Shell Programming and Scripting

Help with taking variable of for loop in textfile

Hi, I am new to unix/linux scripting. I have a text file, listlib.txt where the content: lib1_23 lib34_a ab_li_lab I need to generate a file (.log) of each cell. I am planning to create a (.csh) script that will have for loop with variable taken from listlib.txt. As for now, i have no... (4 Replies)
Discussion started by: mmaz
4 Replies
PAM::FAQ(3pm)						User Contributed Perl Documentation					     PAM::FAQ(3pm)

NAME
Authen::PAM::FAQ - Frequently-Asked Questions about Authen::PAM. SYNOPSIS
perldoc Authen::PAM::FAQ VERSION
This document is currently at version 0.05, as of May 4, 2005 DESCRIPTION
1. Can I authenticate a user non interactively? Yes, you can although not in a very clean way. The PAM library has a mechanism, in a form of a conversation function, to send and receive text data from the user. For details of the format of the conversation function consult the Authen::PAM manual. This function receives a list of code/string pairs. There are two codes (PAM_TEXT_INFO and PAM_ERROR_MSG) for displaying the associated string to the user and two codes (PAM_ECHO_ON and PAM_ECHO_OFF) for getting input from the user. As you can see the codes are rather general and you can not be completely sure when you are asked for a user name and when for a password. However, the common practice is that PAM_ECHO_ON is used for a user name and PAM_ECHO_OFF is used for a password. So, what you can do is to write your own conversation function which ignores the PAM_TEXT_INFO and PAM_ERROR_MSG codes and returns the user name for the code PAM_ECHO_ON and the password for the code PAM_ECHO_OFF. If you pass the user name in the initialization function then usually you will not be asked for it. Here is a simple example how to do this: use Authen::PAM; use POSIX qw(ttyname); $service = "login"; $username = "foo"; $password = "bar"; $tty_name = ttyname(fileno(STDIN)); sub my_conv_func { my @res; while ( @_ ) { my $code = shift; my $msg = shift; my $ans = ""; $ans = $username if ($code == PAM_PROMPT_ECHO_ON() ); $ans = $password if ($code == PAM_PROMPT_ECHO_OFF() ); push @res, (PAM_SUCCESS(),$ans); } push @res, PAM_SUCCESS(); return @res; } ref($pamh = new Authen::PAM($service, $username, &my_conv_func)) || die "Error code $pamh during PAM init!"; $res = $pamh->pam_set_item(PAM_TTY(), $tty_name); $res = $pamh->pam_authenticate; print $pamh->pam_strerror($res)," " unless $res == PAM_SUCCESS(); The Authen::PAM module comes with a default conversation function which you can find in the file PAM.pm. 2. Can I change a password non interactively? All the discussion of the previous question also applies here. There is however one serious complication. When changing a password it is quite possible that the PAM library will send you at lest two PAM_ECHO_OFF prompts - one for the old password and one or two for the new one. Therefore, the first thing you should do is to see what sequence of prompts is produced by your service. Then the conversation function should include some state variable to distinguish the different prompts. Here is an example: use Authen::PAM; $service = "passwd"; $username = "foo"; $oldpassword = "old_pass"; $newpassword = "new_pass"; sub my_conv_func { my @res; while ( @_ ) { my $code = shift; my $msg = shift; my $ans = ""; $ans = $username if ($code == PAM_PROMPT_ECHO_ON() ); if ($code == PAM_PROMPT_ECHO_OFF() ) { $ans = $oldpassword if ($state == 0); $ans = $newpassword if ($state == 1); $ans = $newpassword if ($state == 2); $state++; } push @res, (PAM_SUCCESS(),$ans); } push @res, PAM_SUCCESS(); return @res; } ref($pamh = new Authen::PAM($service, $username, &my_conv_func)) || die "Error code $pamh during PAM init!"; $state = 0; $res = $pamh->pam_chauthtok; print $pamh->pam_strerror($res)," " unless $res == PAM_SUCCESS(); If you are running the script as root then most likely you will not be prompted for an old password. In this case you can simply return the new password at the ECHO_OFF prompt. The $msg variable contains the text of the input prompt which you can use for additional test or for debugging purposes, e.g. if ($code == PAM_PROMPT_ECHO_OFF() ) { if ($state>=1 || $msg=~/new/i) { # are we asked for a new password $ans = $newpassword; } else { $ans = $oldpassword; } $state++; } 3. Why are the constants PAM_AUTHTOK and PAM_OLDAUTHTOK not avaliable? The PAM_AUTHTOK and PAM_OLDAUTHTOK items can be used to pass authentication tokens (passwords) from one module to another. However, they are avaliable only to PAM modules and not to PAM applicatinos. If you have a special setup in which you really need to preset the password from the application (e.g. using a radius server) then you can use the pam_set_authtok module avaliable from http://www.uni-hohenheim.de/~schaefer/linux/pam/pam_set_authtok.html <http://www.uni- hohenheim.de/~schaefer/linux/pam/pam_set_authtok.html>. SEE ALSO
Authen::PAM AUTHOR
Nikolay Pelov <NIKIP at cpan.org> COPYRIGHT
Copyright (c) 1998-2005 Nikolay Pelov. All rights reserved. This file is part of the Authen::PAM library. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2005-06-30 PAM::FAQ(3pm)
All times are GMT -4. The time now is 10:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy