To deploy application on linux ubuntu server I have bunch of SSH commands that i currently run using PuTTY. The server has local account serviceaccount1. In PuTTY i connect to server using serviceaccount1 and executes the following commands one by one
cd /home/serviceaccount1/cr-ml
script /dev/null
screen -S data_and_status
cd cr-ml/notebooks
source activate crml
unset XDG_RUNTIME_DIR
jupyter kernelgateway --api='kernel_gateway.notebook_http' --seed_uri='data_and_status_api.ipynb' --port 8894 --ip 0.0.0.0
...
...
and so on
Now i want automate this using Jenkins. I installed SSH plugin, configured credential using SSH Username serviceaccount1 with private key
Then created a new jenkins project and added a build step Execute shell scripts on remote host using ssh and then add all the above commands.
When i build the jenkins project, it get stuck at executing 2nd command script /dev/null
i see the following console output
To me, it seems the culprit is the screen -S data_and_status command. Once you start a screen, I don't think you would be able to execute the subsequent commands over the SSH connection.
Alternatively, you can try using a tool like Ansible to run a bunch of commands against a remote server.
Related
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).
I want to execute some linux commands like docker run nginx on a remote Ubuntu server. Let's say host A using my client interface on another host B developed in symfony4 and then the server (host A) will send some info after executing the command to the client interface on host B to be displayed on it.
How to achieve this?
at first you need to log in:
ssh username#ip_address_of_server_with_symfony4
Then
cd /path/to/symfony4
Then
docker exec symfony_container_php php bin/console command:name --arguments
If you need to run single command from your local computer, you also can use ssh -t
ssh -t user#ip full;command;separated with;-es
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.
I'm trying to run a server automatically when my vagrant box boots.
Similar to start screen detached in a vagrant box with ssh, how?, except I'm trying to do it with a provisioning script set to run: "always".
I'm doing something like this: nohup screen -S server -mL -d bash -c 'start-my-server.sh'.
The server starts fine, and if I would have done this within the shell, I could switch to the server with screen -r server.
When I go in after with vagrant ssh, it doesn't find any screens...I'm assuming this is because its not the same shell session.
Is there anyway to get a hold of that screen session?
Edit
Forgot to mention that I had prefixed the screen command with nohup
The answer is that vagrant provision was running as a privileged user, and therefore I couldn't see the screen logging in as the vagrant user.
I am trying to ssh to my deployment server to run a script using jenkins build server but it is giving error:
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/test/workspace
[workspace] $ /bin/sh -xe /tmp/hudson2847284723784326.sh
+ ssh user#serverIP
Pseudo-terminal will not be allocated because stdin is not a terminal.
Host key verification failed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I am using Execute shell build utility in jenkins. Steps used are:
ssh user#serverIP
cd pathofscript
./script.sh
I can login manually in server without using password. I used this article to setup password less login : http://www.linuxproblem.org/art_9.html
Kindly let me know what am I doing wrong.
Try to use Jenkins ssh plugin.