LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 11: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, 11:19 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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 11:21 AM.
 
Old 02-18-2013, 11: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, 11: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 12:01 PM.
 
1 members found this post helpful.
Old 02-18-2013, 12:25 PM   #5
sanaz
Member
 
Registered: Aug 2012
Posts: 76

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

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:54 PM
ssh - how to close connection from bash script babag Linux - Networking 7 05-30-2008 10:14 PM
Perl: Wait for ssh connection to close kenneho Programming 9 10-29-2005 10:19 AM
executing a script when logging via ssh rubby1 Linux - General 8 10-06-2005 04:12 PM
Game server shutting down when I close my SSH connection jader9920 Linux - Software 7 01-05-2004 08:38 PM


All times are GMT -5. The time now is 02:39 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration