Visit Our UNIX and Linux User Community

Running a script on remote server kills my login session

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a script on remote server kills my login session
# 1  
Old 10-11-2016
Running a script on remote server kills my login session

Hi there,

I'm trying to run a script remotely on a server in a particular directory named after hostname which already exists, my login session gets killed as soon as I run the below command. Not sure what is wrong, is there a better way to do it ?

Note: I can also use nohup command to run this command in background but prefer to use 'at' job.

ssh -l username@hostname "echo "cd /tmp\`hostname\` && exec ./" | at now"

mkdir -p $LOGS

Also tried enclosing the command with ( ) but it gives syntax error,
ssh -l username@hostname "echo "( cd /tmp\`hostname\` && exec ./ )" | at now"

# 2  
Old 10-11-2016
Why are you using exec?
Or more you tell me what happens at the end of execution...
# 3  
Old 10-11-2016
Check those double quotes, you have to escape the inner ones. As it stands now, it executes parts of the command locally.

# 4  
Old 10-11-2016
Originally Posted by vbe
Why are you using exec?
Or more you tell me what happens at the end of execution...
I'm trying to execute the script and it just kills my session at the end of execution.
# 5  
Old 10-11-2016
Well, I'm afraid that without further detailed info we won't get anywhere. WE CANNOT replicate your setup. YOU NEED to post what happens, and when. The more info you post, the higher the probabilty of a solution.
Which part is running where? Does the at command start? Does it crash? Any error message (and don't say "yes!")? Log entries?
# 6  
Old 10-11-2016
your double quotes are wrong ...

if you look at the red-colored characters below, you will see that you have 2 groupings of "command arguments" with the '&&' operator in between.
ssh -l username@hostname "echo "( cd /tmp\`hostname\` && exec ./ )" | at now"

since the exec command immediately follows &&, your malformed command line is basically saying run the ssh command and then run exec. correct code should be ...
ssh -l username@$hostname "echo '(cd /tmp\`hostname\` && exec ./' | at now"

or something closer. verify on your platform. either way, your error is with your command groupings done by your double quotes.
This User Gave Thanks to Just Ice For This Post:
# 7  
Old 10-11-2016
I had to refrain from using 'exec' command as it abruptly ends my login session as soon as I run the command without giving any errors and also got rid of '&&'.
Btw..this is ksh on AIX OS.

Below is the code that works for me and I'll start using it unless anyone sees an issue with it or comes up with anything better.

ssh -l username@$hostname "echo '(cd /tmp/\`hostname\`;./' | at now"

Thanks to all for your quick responses esp. 'Just Ice' for pointing to the quoting issue.

Last edited by mbak; 10-11-2016 at 08:35 PM.. Reason: typo

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

2. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

3. Shell Programming and Scripting

SFTP script to automate login in to remote server

Greetings, guys. I'm not much of a programmer forgive me for being a noob, because of someone leaving, I was put in an IT spot where I have to figure out a few things. Being new to Linux and programming has been a challenge. My boss has asked me to create an automated script to connect to a 3rd... (7 Replies)
Discussion started by: giovannym
7 Replies

4. Shell Programming and Scripting

Running script on remote server

Hi All, I need to run a ksh script on around 200 servers(consisting of AIX,LInux,HP-UX,Solaris). The script is there in the /tmp directory of all the servers. I want want to execute the script in background on the respective servers and then exit from there. I have written something like below:... (8 Replies)
Discussion started by: proactiveaditya
8 Replies

5. Shell Programming and Scripting

i want to execute shell script on remote server with in sftp session

Hi, I want to execute shell script with in sftp session for remote server. like i have a shell script that is on local server.i want to execute that script on remote server sftp user@ sftp> ---execute for remote server not for local server. sftp... (3 Replies)
Discussion started by: SAUD PASHA
3 Replies

6. Shell Programming and Scripting

Running a Script in a Remote server

I am trying to write a script that would let me run a command in a remote server using ssh. scriptA: (dcm2nii is a command that only works on the other server) dcm2nii a b c scriptB: (I run this one on the current server) ssh -X otherserver /home/abc/Desktop/scriptA But when I do ... (2 Replies)
Discussion started by: ZeroGPX
2 Replies

7. Shell Programming and Scripting

Script to check running processes on remote server.

Hi, I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out. #!/bin/sh echo "select Address from Device where Cust =... (5 Replies)
Discussion started by: amitsayshii
5 Replies

8. Shell Programming and Scripting

Running a remote Server through perl script

Hello people, I am want to run a server on remote machine through perl scripting using telnet api. Now when I try to do so, the server gets started perfectly, but as soon as I close the telnet connection in the script, the server started on the remote machine suddenly goes down. I also... (0 Replies)
Discussion started by: chandrak
0 Replies

9. UNIX for Dummies Questions & Answers

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why?

mac 10.4>terminal>linux remote server>ssh login accepted>session closed-why? AHHHH!! I have been connecting to the server with the line: ssh The remote server accepts my password; logs me in with ssh; posts a lovely welcome message AND closes the session. Is this a "term... (0 Replies)
Discussion started by: xprankard
0 Replies

10. Shell Programming and Scripting

running a script on remote server.

I need to run a script on a remote server from my ksh script. The issue I'm having is that I need to logon to the remote server as a different user. (see the following) logged on to server 1 as adsmgr neet to log on to server 2 as odemgr run passwd_util.ksh Thanks in advance. (1 Reply)
Discussion started by: whited05
1 Replies

Featured Tech Videos