我正在通过SSH这样启动远程脚本:
ssh user@ipaddress '~/my_script.sh'
一切都很好,但是一旦脚本完成,连接就不会关闭。我必须按CTRL-C断开当前连接。
我已经尝试过“〜/ my_script.sh”中的“退出”命令,它没有用。我已经尝试在“〜/ my_script.sh”中使用“注销”命令,并且收到一条消息:
logout: not login shell: use exit
...
知道脚本完成后如何自动正确关闭SSH吗?
(为澄清起见,进行了修改:)这是我的脚本里面的内容:
#!/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
当我通过SSH启动它时,它会运行,最后,我读到“全部完成”。所以这意味着到达了最后两行。
任何想法我该怎么做才能自动关闭并公关
~/.ssh/config
,请尝试不使用它,然后将选项-a -x
(和no -o
)传递ssh
给,以确保没有转发正在进行。如果仍然不起作用,请显示脚本的内容。
ssh <yourusername>@localhost '(ls; sleep 10 &); echo Done; jobs'
将列出文件,显示完成并等待10秒钟后返回。