Results 1 to 6 of 6
Hi.
I'm trying to make a simple script. This is what I've got now:
Code:
if [ "$PAM_USER" != "root" -a "$PAM_SERVICE" != "su" -a "$PAM_TYPE" == "open_session" ];
However, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-29-2013 #1
Help with bash variables
Hi.
I'm trying to make a simple script. This is what I've got now:
However, this only runs the script if $PAM_USER is NOT root or $PAM_SERVICE is NOT su. What I'd like to do is run the script when those two variables are not met at the same time.Code:if [ "$PAM_USER" != "root" -a "$PAM_SERVICE" != "su" -a "$PAM_TYPE" == "open_session" ];
For instance, if $PAM_USER is "user1" and $PAM_SERVICE is "su", I'd like the script to run. Or otherwise, if $PAM_USER is "root" and $PAM_SERVICE is "sshd" aswell.
Any ideas? Thanks!
- 01-29-2013 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 152
Something like this should do:
(Ideally you'd use some sort of exclusive-or, but bash doesn't seem to have it.)Code:if [ \( "$PAM_USER" == "root" -o "$PAM_SERVICE" == "su" \) -a ! \( "$PAM_USER" == "root" -a "$PAM_SERVICE" == "su" \) ];
Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)
- 01-29-2013 #3
I assume it's not as easy as:
Right?Code:if [ "$PAM_USER" != "root" -o "$PAM_SERVICE" != "su" -a "$PAM_TYPE" == "open_session" ];
- 01-29-2013 #4Linux Newbie
- Join Date
- Mar 2010
- Posts
- 152
That doesn't do what you described - but then I note that you didn't describe anything in your first post about PAM_TYPE, so I don't know what you want to do with that.
Also, I (deliberately) don't know about bash's operator precedence in this case - IMHO you should use brackets to clarify, both to yourself and to bash.Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)
- 01-29-2013 #5
PAM_TYPE should make the script continue if it equals to "open_session" and end the script in case the value returned by $PAM_TYPE is not "open_session".
I thought maybe I could make a first if with PAM_TYPE and then, insert a second if inside that runs the script whenever any of those two variables are met, but not when both are met?
Sorry, I don't know very much about bash programming... In fact nothing at all, so your help is greatly appreciated ^^
- 01-30-2013 #6Linux Newbie
- Join Date
- Mar 2010
- Posts
- 152
Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)




