How to keep staying on remote server after executing a shell script with if then exit end statement?

i have a "if .. then exit end " in s shell script on remote servers.
now the connection to the remote server got killed after i run this script on the remote servers. How do i run this script on remote hosts and still keep remote connections alive after executing the script.

Thank you.

Welcome on board!

We know nothing about your script so how to you expect as to answer other than comment out the "if .. then exit end " ?

....
if [ $# -le 0 ]
then
        echo "Usage: $0 product_name APPLICATION_ID"
        exit 1
fi
....

It works fine and will keep staying on remote servers on old environment , but the connections got killed when i run the same script on a new environment.

Then, please, tell us the differences between the "old environment" and the "new environment". Or the difference calling the script in either.

There is says to exit, so before you maybe never satisfied the if condition, while testing comment out the exit or change to:

 echo " exit 1 "

and before the if so we understand:

echo "\$# value is : " $# 

the purpose of this code is checking parameter existence. if we do not pass any parameter to this script, the script will terminate and print ....Usage:

if [ $# -le 0 ]
then
        echo "Usage: $0 product_name APPLICATION_ID"
        exit 1
fi

-------------------------
also i have update the code to

echo "\$# value is : " $#
if [ $# -ne 1 ]
then
    echo "Usage: $PROG hostname"
    #exit 0
    echo " exit 1 " 
fi        

$>.  sync_af  

$# value is :  0
Usage:  hostname
 exit 1         

==============
It works on old data centers. but not on new data center .
thank you

---------- Post updated at 02:51 PM ---------- Previous update was at 02:44 PM ----------

$> check_df

#!/bin/ksh
# This script checks the percentage of disk usage 
# and will send an email if disk usage is more than 80%(default).
# You can reset the threshold by assigning a value to threshold variable @ line 19 

CURDIR=`dirname $0`
. $CURDIR/commands

if [ $# -le 0 ]
then
        echo "Usage: $0 product_name APPLICATION_ID"
        exit 1
fi

SERVER=$1
PROGRAM=`basename $0`
PROG="${2}+$PROGRAM"

typeset -i threshold=80
typeset -i USAGE
tmpfile=/home/dba/oracle11g/amreview/bin/$PROGRAM.$$.tmp
touch $tmpfile

for Disk in `df -P| grep '%' | grep '^/' | awk '{print $6}'`
do
  INFO=`/bin/df -h -P $Disk| awk '{print $5,$6}'`  
  INFO=`echo $INFO | awk '{print $3,$4}'`
  USAGE=`echo $INFO | cut -d% -f1`
  if (( USAGE > threshold ))
  then
      echo "Warning :DISC usage :$INFO " >>$tmpfile
  fi
done

if [ -s $tmpfile ]
then 
    $CURDIR/writelog -p $PROG -s 4 -S $SERVER -f $tmpfile
fi

/bin/rm $tmpfile

is threshold supposed to be a variable? and USAGE?
so why

if (( USAGE > threshold ))

do you have no $ for USAGE and threshold ?

i think i find out how make it work and how it does not work. but for the accurate reason ? may someone tell me?

at working directory
$> ./check_df
it works fine. exit and still stay at the remote host.

at working directory
$> . check_df
exit and the remote session is killed.

I see no reason why you get kicked out of your remote server looking at the code except for this:

$>.  sync_af  

do you mind explaining me ?

You posted faster than me...
that is what I supposed to be the culprit and you just comfort me it is that,
dot space program means replacing your current shell ( logging shell here ) by the program/shell script - once it ends it exits you from your session...

1 Like

$ is not needed, because of (( ... )). But you can add a $ if this makes you happy.

1 Like