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

Posted on 2014-09-09
Last Modified: 2014-09-10
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 ./

Please let me know what ideas you may have!  Thanks!
Question by:Bodhi108
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 300 total points
ID: 40313108
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.

Assisted Solution

by:Carlos Ijalba
Carlos Ijalba earned 200 total points
ID: 40314071
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.

Author Comment

ID: 40315588
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:

# 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)"
touch $SFTP_LOG
touch $LOG

# Command paths


# 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 ]
         $MAILER -s "RUN LOG: $JOB_NAME FAILED"                 $NOTIFY_LIST < $LOG
# may need to add next line --debugging exit
#   exit $RETCODE

# Mainline Code


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
   sqlplus  -silent /@abcdev << EOSQLPLUS


echo "" >> $LOG

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

# 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


echo "" >> $LOG

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

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

# Save status of and log output from sftp

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


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


# may need to add next line --debugging exit
#exit $RETCODE
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

LVL 68

Expert Comment

ID: 40315629
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

Please examine this procedure. Any hints?

Maybe it's here:


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.

Author Comment

ID: 40315686
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!

Author Comment

ID: 40315942
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!

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to recover a database from a user managed backup

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question