# Exiting the Remote server after script execution

**URL:** <https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763>\
**Category:** Shell Programming and Scripting\
**Created:** [November 4, 2014, 1:49am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763 "2014-11-04T01:49:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 4, 2014, 1:49am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/1 "2014-11-04T01:49:19Z")

</div>

Hi All ,

I'm running a script abc.sh in server "host1" shown as below :

```nohighlight

#! /bin/bash

sh stop.sh

ssh user@$host2 "/home/user/prod_work/xyz.sh; 

sh start.sh

```

The problem I am facing is , the control is not passed to host1 after executing the script "xyz.sh" in host2 .

How to exit the session in host2 after executing the script xyz.sh ??

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/6_449c533f586939b6e5f246632a46421f.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [November 4, 2014, 3:49am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/2 "2014-11-04T03:49:39Z")

</div>

> [@pradeep\_1990](#):
>
> Hi All ,
> 
> I'm running a script abc.sh in server "host1" shown as below :
> 
> ```plaintext
> 
> #! /bin/bash
> 
> sh stop.sh
> 
> ssh user@$host2 "/home/user/prod_work/xyz.sh;
> 
> sh start.sh
> 
> ```
> 
> The problem I am facing is , the control is not passed to host1 after executing the script "xyz.sh" in host2 .
> 
> How to exit the session in host2 after executing the script xyz.sh ??
> 
> Thanks,  
> Pradeep

is working ?

```plaintext
"/home/user/prod_work/xyz.sh;

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 4, 2014, 4:51am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/3 "2014-11-04T04:51:44Z")

</div>

There's either one double quote too many or one too few... anyhow, the shell should complain.

---

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 4, 2014, 12:01pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/4 "2014-11-04T12:01:17Z")

</div>

Sorry..I actually pasted the code wrong ..It is

```nohighlight
ssh user@$host2 "/home/user/prod_work/xyz.sh"

```

But even then the issue remains .

---

<div class="post-metadata">

**Author:** ![ygemici](https://community.unix.com/letter_avatar/ygemici/32/6_449c533f586939b6e5f246632a46421f.png) [@ygemici](https://community.unix.com/u/ygemici)\
**Post date:** [November 4, 2014, 2:02pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/5 "2014-11-04T14:02:27Z")

</div>

- what about contents of your script ?

```nohighlight
# cat /home/user/prod_work/xyz.sh

```

- your ssh connection passwordless ?

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 4, 2014, 2:53pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/6 "2014-11-04T14:53:05Z")

</div>

What do you mean by 'return control'? What do you expect to happen? What happens?

---

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 4, 2014, 11:04pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/7 "2014-11-04T23:04:23Z")

</div>

Yes , the ssh connection is passwordless . I achieved that using the below :

[SSH login without password](http://www.linuxproblem.org/art_9.html)

When I execute abc.sh in server "host1" , the shell script is executed till

ssh user@$host2 "/home/user/prod\_work/xyz.sh" , but hangs after that . It does not continue to execute the next line (sh start.sh ) in host1 until I press Ctrl+C . That is what I mean by returning control .

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![Aia](https://community.unix.com/user_avatar/community.unix.com/aia/32/917_2.png) [@Aia](https://community.unix.com/u/Aia)\
**Post date:** [November 4, 2014, 11:21pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/8 "2014-11-04T23:21:22Z")

</div>

Is there any reason why you don't want to show the content of `/home/user/prod_work/xyz.sh` as ygemici asked in post # 5?

---

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 4, 2014, 11:40pm UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/9 "2014-11-04T23:40:00Z")

</div>

Yes . Sorry... I'm not in a position to show the script for security reasons but it is a simple script only and it is successfully executed nevertheless .

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![Aia](https://community.unix.com/user_avatar/community.unix.com/aia/32/917_2.png) [@Aia](https://community.unix.com/u/Aia)\
**Post date:** [November 5, 2014, 12:07am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/10 "2014-11-05T00:07:27Z")

</div>

> [@pradeep\_1990](#):
>
> Yes . Sorry... I'm not in a position to show the script for security reasons but it is a simple script only and it is successfully executed nevertheless .
> 
> Thanks,  
> Pradeep

That's fine, I was wondering because that would had helped. No worries.  
It appears that the content of the script is at fault.

---------- Post updated at 10:07 PM ---------- Previous update was at 09:52 PM ----------

Forgive me if this question sounds very simple.  
Have you tried with another script, perhaps with just a ls or echoing something?

---

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 5, 2014, 1:03am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/11 "2014-11-05T01:03:07Z")

</div>

Hi Aia ,

Thanks for the replies . I have got it working by directing the script to /dev/null (solution got from [unix.com](http://unix.com) forum ).

```plaintext

ssh user@$host2 "/home/user/prod_work/xyz.sh > /dev/null"

```

But , not sure about the logic though .

Thanks,  
Pradeep

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 13, 2014, 11:23am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/12 "2014-11-13T11:23:08Z")

</div>

It might be better to redirect /home/user/prod\_work/xyz.sh to /dev/null, to fix it on the remote side, instead of the local side. Less round-trip, and saves you one stream if you ever need it later.

---

<div class="post-metadata">

**Author:** ![Pradeep\_1990](https://community.unix.com/letter_avatar/pradeep_1990/32/6_449c533f586939b6e5f246632a46421f.png) [@Pradeep\_1990](https://community.unix.com/u/Pradeep_1990)\
**Post date:** [November 14, 2014, 2:54am UTC](https://community.unix.com/t/exiting-the-remote-server-after-script-execution/347763/13 "2014-11-14T02:54:59Z")

</div>

Thanks . Will try the same .

Regards,  
Pradeep
