Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-25-2008, 03:52 AM   #1
LQ Newbie
Registered: Feb 2008
Posts: 4

Rep: Reputation: 0
HELP!! running program to ssh


Im running a simple script to login to a remote server thru SSH and run a command.

#! /bin/sh +x
ssh user@server -2Y -C "(cd /RMA/prod/files/g3/area11/logs; ls -ltr)"

The script works fine but the script returns to the original host after executing the command, I want the script to execute the command without exiting on the remote server so i can run another command.

This may sound easy but it got's me a headache and I'm feeling the answer is right under my nose!

Can somebody help me, I really appreciate it!


Old 02-25-2008, 06:43 AM   #2
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Rep: Reputation: 30
Have you tried using pipe
command1 | command2
Old 02-25-2008, 01:10 PM   #3
Senior Member
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
Here is another interesting possibility. Have your script do three things:

1) Make the ssh connection
2) Copy a file (another script) to the remote server
3) Execute the copied script

That way, you could make the script do whatever sequence of instructions you wanted. If you don't know what you want to do until you see some output, and still stay logged in, that is a little tougher.

It logs you out at script completion because staying logged in remotely with execution privileges is a security risk.
Old 02-25-2008, 06:24 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,395

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
There are basically 3 options:

1. if you really don't know what the next cmd will be, then you have to do it (login) manually
2. if you can make an intelligent script that can determine which cmds to run (eg Perl), then either
2a. copy script over and run it (as suggested) each time OR
2b. copy script over once only and auto run it each time you login (like your current version).
Old 02-25-2008, 07:23 PM   #5
LQ Newbie
Registered: Feb 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Appreciate the help, but this doesn't solve the problem.
I needed the script to not exit the remote server after executing the commands. I needed to run a program at the background and I needed the command prompt available.

Any other bright ideas?


commands, help, ssh

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
how to keep program running after closing ssh session fakie_flip Linux - Software 10 11-03-2011 08:33 AM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
Running Program Through SSH windisch Linux - General 6 10-04-2005 06:10 AM
Keeping a program running between SSH sessions ark86 Linux - Newbie 2 10-01-2005 03:31 PM
Running a program in the background - SSH ziggo0 Linux - Newbie 4 03-05-2005 01:30 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:14 AM.

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