Reputation: 551
I have this script:
#!/bin/bash
#!/usr/bin/expect
dialog --menu "Please choose the server to connect to:" 10 30 15 1 RAS01 2>temp
#OK is pressed
if [ "$?" = "0" ]
then
_return=$(cat temp)
# /home is selected
if [ "$_return" = "1" ]
then
dialog --infobox "Connecting to server ..." 5 30 ; sleep 2
telnet XXX
fi
# Cancel is pressed
else
exit
fi
# remove the temp file
rm -f temp
In the part of the code that says: # Cancel is pressed
I want to insert some type of command that will disconnect the session and close the terminal automatically. Ive tried different variations of exit
, exit 1
, exit 5
, close
, etc. but none seem to do the trick
Upvotes: 0
Views: 3011
Reputation: 10653
Here is what you can do:
kill -9 "$(ps --pid $$ -oppid=)"
But I definitely suggest you not to use this way. A better solution is to get the exit code of your script and exit if needed. For example
yourscript
:
#... ...
else
exit 1
fi
And in your ssh connection you do:
./myscript || exit
This is the correct way. Try to use it
Upvotes: 1