LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2013, 10:14 AM   #1
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Rep: Reputation: Disabled
executing script even when we close connection via ssh


Hi all,

I need to run a shell script on e remote machine, my connection is now strong, or I want to shut down my machine. But problem is when I close my connection(or lost it), execution of script is terminated. I googled a lot, I saw using of nohup or screen, but none of them worked for me. I really need to do that.

Any help is appreciated a lot.
 
Old 02-18-2013, 10:19 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
What did you try?

nohup:
Code:
nohup ./script > script.out 2>&1 &
screen:
Code:
$ screen -S thisismyscreen bash
$ ./script
Then you can use Ctrl+a d to detach from the screen, and "screen -r thisismyscreen" to reattach.

Last edited by suicidaleggroll; 02-18-2013 at 10:21 AM.
 
Old 02-18-2013, 10:46 AM   #3
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
Thanks a lot for your answer, but is this after I ssh to remote machine?
Could you please explain it more?

and here it is what I am doingwhich does not work at all)
Code:
ssh root@remoteserver screen -d -m ./script
 
Old 02-18-2013, 10:57 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Better use nohup instead of screen cmd. (See manual here)
Code:
~$ nohup ./script.sh > /path/to/output

Last edited by shivaa; 02-18-2013 at 11:01 AM.
 
1 members found this post helpful.
Old 02-18-2013, 11:25 AM   #5
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
Thanks a lot, it simply worked.
 
Old 02-18-2013, 12:44 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Both of my examples are intended to be run after you log in and are sitting at an interactive command prompt on the remote server. Once you run them, you can then log out of SSH and close the terminal without the background process aborting.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Error Executing a script(SSH problem) pinga123 Linux - Newbie 5 07-14-2010 12:54 PM
ssh - how to close connection from bash script babag Linux - Networking 7 05-30-2008 09:14 PM
Perl: Wait for ssh connection to close kenneho Programming 9 10-29-2005 09:19 AM
executing a script when logging via ssh rubby1 Linux - General 8 10-06-2005 03:12 PM
Game server shutting down when I close my SSH connection jader9920 Linux - Software 7 01-05-2004 07:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration