23
9
I'm launching a distant script through SSH like this:
ssh user@ipaddress '~/my_script.sh'
Everything is going fine but once the script is finished, the connection is not closed. I Have to press CTRL-C to break the current connection.
I've tried the "exit" command in '~/my_script.sh' and it's useless. I've tried the "logout" command in '~/my_script.sh' and I get a message:
logout: not login shell: use exit
...
Any idea how I could do to close automatically and properly the SSH once the script is done?
(Modification for clarification :) Here's what's inside my script :
#!/bin/sh
path_sources_qas=/sources/QuickAddress/
path_qas_bin=/usr/bin/qas
umount_disque_qas()
{
# Umount du disque 'qas' s'il n'avait pas été 'umount' :
nom_disque_monte=`cat /etc/mtab | grep qas | awk '{ print $2}'`
if [ "$nom_disque_monte" != "" ]
then
echo "For safety, umount : $nom_disque_monte"
umount $nom_disque_monte
fi
}
# Umount twice (we never know if a st***d guy mounted it twice) :
umount_disque_qas
umount_disque_qas
echo "--------------------------------"
echo "Install ISO quick address..."
nom_fichier_iso=`ls -t $path_sources_qas | awk '{if (NR==1) {print $1}}'`
echo "Mount disk $nom_fichier_iso..."
mount -o loop -t iso9660 $path_sources_qas/$nom_fichier_iso /mnt/qas
echo "Done."
# All the folders are like this :
# /usr/bin/qas/Data.old.10
# /usr/bin/qas/Data.old.11
# /usr/bin/qas/Data.old.12
# ...
echo "--------------------------------"
echo "Stopping QuickAdress server..."
cd $path_qas_bin/apps/
./wvmgmtd shutdown qaserver:2021
sleep 3
echo "Done."
# Get last number of the folder:
num_dernier_dossier_backup=`ls -Atd $path_qas_bin/Data.old* | awk '{if (NR==1) {print $1}}' | awk -F . '{print $NF}'`
# Add 1 :
let "num_dernier_dossier_backup += 1"
# Full name :
nom_dossier_backup=Data.old.$num_dernier_dossier_backup
echo "--------------------------------"
echo "Saving Data to $nom_dossier_backup..."
cd $path_qas_bin
mv Data $nom_dossier_backup
echo "Done."
echo "--------------------------------"
echo "Copying new folder Data..."
cd $path_qas_bin
cp -r /mnt/qas/Data .
echo "Done."
echo "--------------------------------"
echo "Deleting unused datas..."
cd $path_qas_bin/apps/
rm -f $path_qas_bin/Data/frxmos.dap
echo "Done."
echo "--------------------------------"
echo "Restart server..."
cd $path_qas_bin/apps/
./qaswvd &
sleep 3
echo "Done."
sleep 3
echo "--------------------------------"
echo "Check: server state: you should read 'OK':"
./wvmgmtd srvlist
echo "Done."
echo "--------------------------------"
echo "Check: active licences (only one here):"
./wvmgmtd licencelistread qaserver:2021
echo "Done."
echo "--------------------------------"
echo "Check: counters: number of addresses left:"
./wvmgmtd counterinforead qaserver:2021
echo "Done."
echo "--------------------------------"
echo "Check: Datasets avalaibles:"
./wvmgmtd datalistread current qaserver:2021
echo "Done."
echo "--------------------------------"
echo "Check: "meters" for "licence by click":"
./wvmgmtd meterslistread current qaserver:2021
echo "Done."
echo "--------------------------------"
echo "Removing virtual disk..."
umount_disque_qas
echo "Done."
echo "All done"
echo "Click 'Ctrl-C' to quit."
exit
When I launch it through SSH, it runs and at the end, I read "All done." so this means it reaches the last 2 lines.
Any idea how I could do to close automatically and pr
1What's in the script? – Ignacio Vazquez-Abrams – 2010-11-05T13:31:15.387
@Olivier: Do you forward any ports (including the agent and X)? The ssh connection is closed when the command terminates and all TCP connections have been closed. – Gilles 'SO- stop being evil' – 2010-11-05T20:56:40.503
@Gilles : nope I just make a shell connexion to run a script, nothing is forwarded. – Olivier Pons – 2010-11-09T21:43:24.610
1@Olivier: If you have a
~/.ssh/config
, try without it, and pass the options-a -x
(and no-o
) tossh
to make sure there's no forwarding going on. If it still doesn't work, show the contents of the script. – Gilles 'SO- stop being evil' – 2010-11-09T22:49:29.420@Olivier: does the script start any background job it may be waiting on? Unfortunately jobs does not seem to return anything when in an ssh script. Example:
ssh <yourusername>@localhost '(ls; sleep 10 &); echo Done; jobs'
will list files, display done and wait 10 seconds before returning. – asoundmove – 2010-12-07T12:38:00.777I've modified my question: I've added the whole script. Maybe this may help. – Olivier Pons – 2011-01-20T08:38:25.667