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
# 8  
Old 10-12-2016
The problem you have now is that there is no error check that the change of directory worked.

Would running ./test.sh in the home directory cause a problem?

I would avoid the exec, there is just no need and perhaps a script called test.sh is not a great idea given that test is a reserved word.

Why do you feel you need to run your code with at anyway? What's wrong with this?:-
Code:
ssh -l username@hostname 'cd /tmp/$(hostname) && nohup ./test.sh &'

Note the single quotes so that $(hostname) is executed on the target. You can choose to capture the output to a file, leave it to default to nohup.out or redirect it to /dev/null as you please.



Robin
This User Gave Thanks to rbatte1 For This Post:
# 9  
Old 10-14-2016
Thanks for suggesting to use && which does the error check and I'd change the script name once it is complete as I need to add some more functionality.

The reason I prefer using at over nohup is sometimes ssh tends to not exit after running the remote job if the script that is running receives some input/output values and I do have these values that are called within a script.
# 10  
Old 10-14-2016
All the standard output and errors from a nohuped job will be written to file nohup.out unless you tell it otherwise and by putting the remote script in the background, your ssh will then end. I'm not sure why running with at is more beneficial except that any unhandled output to 'screen' should end up as an email to the user account running the job.

Can you try it and post any unwanted results? If you think your code may pause for input, then you are no worse off.



Robin
# 11  
Old 10-15-2016
I ran using nohup and it works the same way as at except that nohup sends the output to screen as well and I'd like set it up to receive an email only option to the user running the job rather than outputting to the screen.

One more thing I was wondering is how to validate and notify the user if the remote script has actually started running ?

Thanks!
# 12  
Old 10-17-2016
I'd like to pass 1 argument to the below code from a script called mail.sh that runs this code on remote server, any idea how to do it, I tried double quotes but it runs on the local server and also the back slash doesn't work either ?

Code:
cat mail.sh
#!/bin/ksh
if [ "$SERVER" = "" ]
then
   echo "............................"
   echo "Enter server name: \c"
   read SERVER
   echo "Enter MAILID: \c"
   read MAILID
   ssh -l username@$SERVER 'cd /tmp/$(hostname) && nohup ./test.sh \${MAILID}&'
else
  echo "Check your mail for an update"
fi


Last edited by mbak; 10-17-2016 at 03:50 AM..
# 13  
Old 10-17-2016
Quote:
Originally Posted by mbak
I'd like to pass 1 argument to the below code from a script called mail.sh that runs this code on remote server, any idea how to do it, I tried double quotes but it runs on the local server and also the back slash doesn't work either ?

Code:
cat mail.sh
#!/bin/ksh
if [ "$SERVER" = "" ]
then
   echo "............................"
   echo "Enter server name: \c"
   read SERVER
   echo "Enter MAILID: \c"
   read MAILID
   ssh -l username@$SERVER 'cd /tmp/$(hostname) && nohup ./test.sh \${MAILID}&'
else
  echo "Check your mail for an update"
fi

If you want $hostname to be expanded on $server and $MAILID to be expanded locally, try changing:
Code:
   ssh -l username@$SERVER 'cd /tmp/$(hostname) && nohup ./test.sh \${MAILID}&'

to:
Code:
   ssh -l username@$SERVER 'cd /tmp/$(hostname) && nohup ./test.sh'" ${MAILID}&"

# 14  
Old 10-17-2016
Would this do the same?:-
Code:
ssh -l $username@$SERVER "cd /tmp/\$(hostname) && nohup ./test.sh ${MAILID}&"

I think that this should pass the literal text $(hostname) across to be interpreted by the remote system, but the value of S{MAILID}

Some people may prefer this style but I'm prepared to be corrected it is wrong.

It does strike me though that you will get no output/mail if the change of directory fails. Would this be a problem to you? You may be better to both set the directory and test for it within your script and then alert on failure from within there, if appropriate.



Robin
Login or Register to Ask a Question

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 test.sh that is on local server.i want to execute that script on remote server sftp user@192.168.56.10 sftp> test.sh ---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 userid@website.com 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
Login or Register to Ask a Question