How to make command run after exit the window in linux - linux

I am establishing a connection between the linux machine and the another machine to run my scripts.but once i close the window the connection got disconnected.What should i do to make this connection contiue after closing the window.since multiple users execute the scripts in the other machine so its difficult to establish the connection each time..Any suggestions welcome.
the command i wrote in command line to establish connection is
java -jar /home/**/workspace/cli.jar -s https://******
-i /home/**/.ssh/id_rsa -description TESTS
-fsroot /home/**/Jenkins -labels test -name TESTS

Use "&" after the command to run it in background without need of open windows

If I've understood correctly screen will do. Try 'man screen' in google.

Related

Connect to Linux Server from Powershell of windows server

I am trying to connect to a Linux server with sftp type in power shell but it's not getting connected. Tried many ways but couldn't figure out anyway as the power shell I have is restricted for using ssh, posh-ssh, and OpenSSH. But it gets connect via cmd prompt. one way to connect to it. Which is: Start-Process cmd - ArgumentList "/K sftp username#servername"
This opens cmd and runs the command but as it connects to Linux server it won't allow me to append another command to execute it. Like Start-Process cmd - ArgumentList "/K sftp username#servername & bye". The "bye" is command we use to come out Linux server but this is not letting to use it.
If anyone has any idea how we do it or any other way to connect please let me know.

How to use tmux inside release pipeline

I have an azure release pipeline to run my backend application on a DigitalOcean server.
I would like to use a tmux window so I can still see the terminal in case I need to debug the production backend.
tmux new-session -A -s tmuxWindowName
pkill java
mv backend/demo-0.0.1-SNAPSHOT.jar backend/backend.jar
java -Xmx800M -jar backend/backend.jar
tmux detach
but this doesn't work because the azure ssh connection is not attached to a terminal. I get the following error:
##[error]open terminal failed: not a terminal
I tried setting the term with "TERM=xterm" and googling this issue comes up with lots of people that are able to manipulate the SSH connection command but I can't since I use an SSH service connection.
What to do?
You can create a detached tmux session by adding -d to new-session which will not require a terminal (until you attach it which will be presumably from somewhere else).

In Linux, how to make a jar file a daemon and how to add websocket

actually I have 2 jars and 1 ini file. In terminal I can run this java application like that :
"/usr/java/jre1.8.0_121/bin/java" -cp "./eSign.jar:sqlite-jdbc-3.7.2.jar" ./esign.tubitak.applet.SignApplet /home/ugurcan/Desktop/Linux_sign_test/test.ini
And my gui based program works like this. Now; I need to make this program run without any terminal commands like an exe as a session(which runs in backgraound always). Additionally , I need to add a websocket for the server to program makes a connection between the server and the computer which runs the program.
Thank you for your thoughts !!!
To run a command in background you can use:
nohup COMMAND &. nohup - makes your program immune to terminal hangup, and & runs it in background.
Can't figure out what do you mean 'to add a websocket for the server to program makes a connection between the server and the computer which runs the program'. Websocket support should be added in your application. But without any further detail we can't help you.

Call Powershell Script from Unix Shell Script

I have a powershell script on my Windows server which does some active directory operations. I wish to call that script from another Linux machine using a shell script.
I have installed powershell server on my Windows server and can communicate with my linux machine using key based ssh authentication.
Since Windows does not support SSH connections on its own, I have installed a software called Powershell server (http://www.powershellserver.com/) on my Windows server.
The issue is that my script just stops once the command for ssh to Windows server is executed.
My shell script below:
#!/bin/bash
echo "script run"
GROUP=$1
ACCOUNT=$2
ssh Administrator#<Windowshostname>
sleep 10
echo "<pathtoscript>\scriptname.ps1 -group $GROUP -account $ACCOUNT"
sleep 5
echo "exit"
exit
I have tried without the echo command as well and it still hangs. Any idea what I must be doing wrong here? How can I make it work please?
You cannot ssh into a Windows box unless you install a SSH daemon.
You have two options:
1- You need to connect via Remote PowerShell (WINRM).
2- Install SSH daemon and connect via SSH (Check here)
3- You can also use PowerShell Web Access (Windows Servers.)
UPDATE: If you are using PowerShellServer.com then there are some things you can do to try to understand more.
Test scriptname.ps1 locally in Windows Server
Edit your scriptname.ps1 in the first line to create a file somewhere and after execution check if that file exists. This way you will know if script is being executed or not.
Execute Get-ExecutionPolicy and check you can run scripts. Remove constraints by temporary Set-ExecutionPolicy unrestricted
Tried the operation using an "expect" script and it all works well now.

Quitting ssh -X session with a running GUI program but leaving the program to run on the remote host

I have ssh-ed to a remote machine. I have enabled X11 forwarding (ssh -X) and I have started a GUI program.
The program takes 5 minutes to set up to do some processing but the actual processing takes 1-2 hours. I don't want to stream data while the program is working. I don't even want to see the program again as it produces files as output when it finishes and I can just scp them.
So how can I quit the ssh session but leave the program running on the machine? CRTL+C in the terminal?
EDIT: For the answer please see my comment just below.
Long story short - you can't do this without making some modifications to the way you run things. A GUI application requires for an X server target to be accepting it's GUI updates - if you're using your local X server to do this, then it'll require (1) the connection to be open (2) that you actually handle the updates.
A way around this is to use something like Xvfb - which is a headless way of hosting a virtual X-server. Above and beyond the examples provided on the wikipedia page, folks who seem to make frequent use of this mechanism are Selenium users.
Awesome, I've been looking for an acceptable answer to my problem for hours, and finally one pops up. ssh -X -f login#machine yourprogram worked perfectly for me. Though I used ssh -Y -f login#machine yourprogram. This has been driving me nuts.
Like some people said, SSH -X is using your local X server, so it needs the connection. I had the same problem, wanted to quit ssh but leaving GUI applications running. To do this I installed X server and VNC server on the remote host. With a VNC client on your local computer, you can easily connect to the VNC server and disconnect leaving GUI applications running.
By the way, you will have better performances with VNC or X2Go. In my case, Firefox was very slow and some sites didn't load at all with SSH -X, even with -Y or -C optimizations.
Running ssh -X -f login#machine yourprogram should do the trick.
Starting your program with nohup program & will make it safe to just close your terminal - program will still be running.
You won't be able to see the UI after you end ssh session, but since you don't need it anyway - it's going to do the job.

Resources