LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-08-2017, 12:12 PM   #1
AMoNdj
LQ Newbie
 
Registered: Jul 2012
Location: Prague
Posts: 5

Rep: Reputation: Disabled
CASE/ESAC logs out automatically any user


Hello people,

Long time no writing how's everyone doing?

Got a question, I've created a simple bash script that does nothing else than displaying IP address, software version, number of users connected, if a specific daemon is running, and if there are any "yum" updates. I've moved the script onto /etc/profile.d and was working all fine (displayed everything properly at every user's login) until I ran an update on the system, after that it just kept automatically logging off any user that was logging in (ex. User insert username, User insert password, everything fine, script login.sh executed, once done, the script close the session automatically).
[NOTE: This script runs on RHEL 7.3]

After some analysis and test, I've found out that is the "CASE/ESAC" the main problem of this script, commenting it out, the script works without problems, here is the part of the code:

Code:
##################################################################
# Yum Update check
YUMTMP="/tmp/yum-check-update.$$"
YUM="/usr/bin/yum"
$YUM check-update >& $YUMTMP
YUMSTATUS="$?"
HSNAME=$(/bin/hostname)

case $YUMSTATUS in
0)
# no updates!
MESG="\e[1;32mNo update(s) available\e[0m"
echo -e $MESG
exit 0
;;
*)
DATE=$(date)
NUMBERS=$(cat $YUMTMP | egrep '(.i386|.x86_64|.noarch|.src)' | wc -l)
if [ $NUMBERS \> 1 ];
then
        MESG="\e[1;31m!!!There are $NUMBERS updates available!!!\e[0m\n\nThe available updates are:"
else
        MESG="\e[1;31m!!!There is $NUMBERS update available!!!\e[0m\n\nThe available update is:"
fi
echo -e $MESG
UPDATES=sudo tail -n +2 $YUMTMP
echo ""
;;
esac

# clean up
rm -f /tmp/yum-check-update.*
anyone knows why is doing this, and if exist another way to make it run (or just simply change the CASE/ESAC into a simple IF/THEN statement)?

Thank you all for your help
 
Old 05-08-2017, 12:35 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
You're telling it to exit if there are no updates with this line:

Code:
exit 0
You don't need that line in the section that started with "0)" - it will skip the section starting with "*)" so long as it has already matched that previous section. That means when there are no updates it will skip to the end and do the cleanup.

The "exit 0" where you have it is exiting at that point so not only is the user logging out but the cleanup at the bottom isn't getting run.
 
1 members found this post helpful.
Old 05-08-2017, 12:41 PM   #3
AMoNdj
LQ Newbie
 
Registered: Jul 2012
Location: Prague
Posts: 5

Original Poster
Rep: Reputation: Disabled
weird, so how come it was working without problems till the update? I mean, when there were no updates it was just showing the message "NO UPDATES AVAILABLE", and logging in without problems, but, after the update, it logs off the user
 
Old 05-08-2017, 12:48 PM   #4
AMoNdj
LQ Newbie
 
Registered: Jul 2012
Location: Prague
Posts: 5

Original Poster
Rep: Reputation: Disabled
forgot to say, the user kept being disconnected even if there were updates on the system
 
Old 05-08-2017, 12:58 PM   #5
AMoNdj
LQ Newbie
 
Registered: Jul 2012
Location: Prague
Posts: 5

Original Poster
Rep: Reputation: Disabled
yep, seems that the "exit 0" was the bad boy, and found out that our devs did some change in the security, and this was mixed with the "exit 0" statement, hence why the user kept logging off even if there were no updates!
Now everything works as it should, will give it another couple of tests though

Thank you for the help
 
Old 05-08-2017, 01:08 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
Glad I could help.

Another oddity I noticed is you have the ";;" at the end of your last (which is second for you) condition that case is testing. Typically you don't need it there - it just needs to be at the end of all the other conditionals (you only have one other) but not the last. i.e. You should have the ";;" before the "*)" but don't need the other ";;" above esac.
 
1 members found this post helpful.
Old 05-10-2017, 10:47 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,863

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
Following on from MensaWater, the ';' here is redundant
Code:
if [ $NUMBERS \> 1 ];
in fact you should be using a diff operator & I recommend [[ ]]
Code:
if [[ $NUMBERS -gt 1 ]]
http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
http://tldp.org/LDP/abs/html/comparison-ops.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automate case/esac bash script blason Programming 5 07-30-2016 10:10 PM
case esac in shell script vadirajcs Programming 16 08-10-2011 07:43 AM
case...esac how to implement in my requirement!To find the URL status. anishkumarv Linux - Newbie 5 03-12-2011 12:12 PM
i want to make a script with case.esac Alexander.s Linux - Newbie 3 12-14-2004 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration