Why do I get kicked out of Unix session after running a Unix script?

I have a bash script that runs a few SQL Plus scripts, does a SFTP process and creates two differing log files, one for the SFTP process and one for everything else.  The script completes everything successfully, writes the log files and nothing seems to be missing from the process except after running the script from the bash prompt, it asks me for a password to log back in.  Not sure why it does this.  It doesn't bother me except I don't think it should go into production like this.  Also, I took out every single exit and it doesn't seem to change anything!

The line in the shell script is #!/bin/bash.  And I run it from the command prompt as ./xyz.sh

Please let me know what ideas you may have!  Thanks!
Abbi
Bodhi108Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Which kind of login do you see? Oracle? Shell?

Is there a "login username" statement somewhere in your script? Or an Oracle "Connect ..." statement?

Is it really a login prompt? Could it come from sudo or sftp or something of that sort?

You could add "set -xv" near the top of the script in order to get some debug info.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Carlos IjalbaSenior SysadminCommented:
Hi Bodhi108,

Without seeing the script, it will be very difficult to guess why.

As woolmilkporc suggests it could be because it jumps to another host with sftp, rsh, ssh, etc, or maybe that the prompt is a connection to a DB, in which case, the script should be changed in order to login to the DB without asking for password.

Same goes for sudo, it can be modified to run scripts without asking for passwords.

Also check that the script doesn't have the awful "exit 0" or any other exit statement at the end.
0
Bodhi108Author Commented:
I'm a advanced beginner shell programmer so I may not give you the perfect answers so I've included a shell script in which I modified the names for security reasons.  I also included a screen print to show you how it is being run and the password prompt.  

The shell script was developed by someone else who retired and I took it over.  I was given it to make sure there weren't any issues before moving it into Test.

Answering your questions to the best of my ability:
Login - shell
login to Oracle uses wallet - sqlplus  -silent /@abcdev
login prompt? - I believe it is logging me back on the unix box
debugging - I put in -x at the beginning and there are no errors and everything gets processed even the last line of code.
SFTP - uses certificates and it was working since file is being SFTP'd and does not need password.
I don't believe there are any sudo's going on in the script.

Screen Print attached:

Script below with modified names:
#!/bin/bash

# File name: yyy
# Author(s): xxxx
#
# Revisions:
# ITR#        Date        Author             Description
# ----------- ----------  -----------------  ------------------------------
# xyz        20FEB2014   Doug xxx        Initial creation
#
# Overview: This is the driver script for the xxx  Extract Process.
#           This process reads a flat file, creates a csv file for the abc dept  and then SFTP’d to abc dept.
#            The last step sends email to a select group.

# Variable set up

JOB_NAME=$(basename $0)
#DATE_YYMD=$(date '+%Y-%m-%d')
#DATE_YYMD=$(date '+%Y-%m-%d')
DATE_YYMDS=$(date '+%Y%m%d%S')

NOTIFY_LIST="$(abc /def/ghi/xyz.maillist)"
SFTP_LOG=/abc/def/ghi/${JOB_NAME}_$DATE_YYMDS.sftp
touch $SFTP_LOG
LOG=/abc/def/ghi//${JOB_NAME}_$DATE_YYMDS.log
touch $LOG

# Command paths

MAILER=/usr/abc/Mail
SFTP=/usr/bin/sftp

# Define Functions

# The EOJ Function is called to End the Job.  It performs final functions including
# Emailing the Log file.

function EOJ
{
   echo " " >> $LOG
   echo "$(date +'%Y/%m/%d %T') $JOB_NAME Ended, return code = $RETCODE" >> $LOG
   if [ ${RETCODE} -ne 0 ]
      then
         $MAILER -s "RUN LOG: $JOB_NAME FAILED"                 $NOTIFY_LIST < $LOG
      else
         $MAILER -s "RUN LOG: $JOB_NAME COMPLETED SUCCESSFULLY" $NOTIFY_LIST < $LOG
   fi
# may need to add next line --debugging exit
#   exit $RETCODE
}

# Mainline Code

RETCODE=0

echo "$(date +'%Y/%m/%d %T') $JOB_NAME Started" > $LOG
echo "$(date +'%Y/%m/%d %T') Connecting to Oracle via sqlplus" >> $LOG

# Get the job_id from the job_app table which will be used throughout this process.
# Declare the variable as Integer.

typeset -i p_job_id

#  sqlplus  -silent /@abcdev << EOSQLPLUS  >> $LOG
p_job_id=`
   sqlplus  -silent /@abcdev << EOSQLPLUS
      @get-job-id.sql
EOSQLPLUS`

SQL_RETURN_CODE=$?

echo "" >> $LOG

if [ ${SQL_RETURN_CODE} -ne 0 ]
then
   echo "$(date +'%Y/%m/%d %T') SQL script Failed, return code = $SQL_RETURN_CODE" >> $LOG
   RETCODE=$SQL_RETURN_CODE
   EOJ
else
   echo "$(date +'%Y/%m/%d %T') SQL script completed successfully, return code = $SQL_RETURN_CODE" >> $LOG
fi

# I'll pass APP_NAME to the SQL script and use it as a key to the app_log Log Framework table.  The following
# statement pulls the first 4 characters from the Job Name which are also the App Name.  I will also pass
# along the job_id which is needed as a key field to the app_log table.

APP_NAME=$(echo $JOB_NAME|awk '{print substr($0,1,4)}')

# abcdev is a tnsnames alias to an entry in an Oracle Wallet

sqlplus  -silent /@abcdev << EOSQLPLUS
   @xyz.sql $APP_NAME $LOG $p_job_id
EOSQLPLUS

SQL_RETURN_CODE=$?

echo "" >> $LOG

if [ ${SQL_RETURN_CODE} -ne 0 ]
then
   echo "$(date +'%Y/%m/%d %T') SQL script Failed, return code = $SQL_RETURN_CODE" >> $LOG
   RETCODE=$SQL_RETURN_CODE
   EOJ
else
   echo "$(date +'%Y/%m/%d %T') SQL script completed successfully, return code = $SQL_RETURN_CODE" >> $LOG
fi

echo "" >> $LOG
echo "$(date +'%Y/%m/%d %T') Begin Secure File Transfer" >> $LOG

#$SFTP its-prod-xfer-1 << SFTPEOF 1>> $SFTP_LOG 2>> $SFTP_LOG
  $SFTP its-prod-xfer-1 << SFTPEOF 1>> $SFTP_LOG 2> $SFTP_LOG
   put /abc/def/ghi/jkl/xyz.csv
   quit
SFTPEOF

# Save status of and log output from sftp

SFTP_RETURN_CODE=$?
cat $SFTP_LOG >> $LOG

# Check the sftp output for key phrases from failure messages in case
# one of the commands had an issue but the overall status was OK

echo "$(date +'%Y/%m/%d %T') End   Secure File Transfer"     >> $LOG
echo "" >> $LOG
echo "$(date +'%Y/%m/%d %T') Check sftp output for failures" >> $LOG
 
egrep -i 'failed|rejected|unable|No such file or dir|Permission denied|no address|Login incorrect|Broken pipe|Lost connection|Not connected|usage|not found' $SFTP_LOG 1>> $LOG 2>> $LOG

EGREP_STAT=$?

if [[ $EGREP_STAT -eq 0 || $SFTP_RETURN_CODE -ne 0 ]]
   then
      echo "$(date +'%Y/%m/%d %T') Transfer FAILED, see above message(s)" >> $LOG
      RETCODE=8
      EOJ
   else
      echo "$(date +'%Y/%m/%d %T') Transfer completed Successfully!" >> $LOG
fi

EOJ

# may need to add next line --debugging exit
#exit $RETCODE
Capture.PNG
ScreenPrint.JPG
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

woolmilkporcCommented:
The culprit could be here within  "xyz.sql" (not very probable, but who knows?):

sqlplus  -silent /@abcdev << EOSQLPLUS
   @xyz.sql $APP_NAME $LOG $p_job_id
EOSQLPLUS

Please examine this procedure. Any hints?

Maybe it's here:

MAILER=/usr/abc/Mail

doesn't seem to be a standard mail client program. What is it? Since this mailer is called by EOJ at the very end it seems suspicious.
0
Bodhi108Author Commented:
hmmmm....yes, I will look at /usr/abc/MAIL  Since everything runs fine and this is the last thing, it could be the culprit.  Thanks!
0
Bodhi108Author Commented:
Mail points to mailx so that is not the issue.

Found out the issue.  I could have found out the issue a lot faster if I entered an incorrect password in 3 times!  Kicking myself on that.

My authenticating keys are not set up on the servers.  So after running the job, it was asking me for the password to complete the SFTP.  If I were to enter a correct password after the 'job ran', the SFTP would happen at that point.  If I didn't enter in a password the SFTP would not happen.  So I had help in generating the RSA keys and now it no longer asks me for a password. It probably didn't happen with the previous owner of this code since his environment was already set up with the authenticating keys. I'm a new employee so not everything was set up in my environment.

Thanks for your help.  I'll give out the points now!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Server Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.