I have remote machine and trying execute bash script to redeploy application after travis ci build is completed. I use sshpass to connect. But I cannot execute script.
echo "Starting deployment"
export SSHPASS=$PASSWORD
sshpass -e ssh -o stricthostkeychecking=no deploy-user#deploy-server.com "bash /opt/redeploy.sh"
And after this I got : No such file or directory after travic ci deploy phase.
But when I trying to execute this command :
sshpass -e ssh -o stricthostkeychecking=no deploy-user#deploy-server.com "touch /opt/myfile"
File successfully created. redeploy.sh is located in /opt directory and can be executed via terminal. But it can not be executed via this script.
Can anybody help me?
redeploy.sh has such content
#!/bin/bash
docker-compose -f /opt/docker-compose.yml stop
docker-compose -f /opt/docker-compose.yml pull
docker-compose -f /opt/docker-compose.yml up -d
Related
sshpass -p Password ssh -o StrictHostKeyChecking=no a.user#IP "Command1 ; Command2"
When i try to run multiple commands after ssh it only runs the 1st command and exits after that without executing others.
I am running the above command,
Could I improve on it to run all the commands sequentially?
I'm trying to run a complete script while the ssh session is live instead of single commands.
Here is my current code:
sh "ssh -tt -o StrictHostKeyChecking=no ubuntu#IPV4_DNS uptime"
sh "ssh -v ubuntu#IPV4_DNS docker pull X:${BUILD_NUMBER}"
sh "ssh -v ubuntu#IPV4_DNS docker rm -f test"
sh "ssh -v ubuntu#IPV4_DNS docker run --name=test -d -p 3000:3000X:${BUILD_NUMBER}"
The desired code is something like this, but the following doesn't work:*
sh "ssh -tt -o StrictHostKeyChecking=no ubuntu#IPV4_DNS uptime"
sh ''' ssh -v ubuntu#IPV4_DNS docker pull X:${BUILD_NUMBER}
&& docker rm -f test && docker run --name=test -d -p 3000:3000X:${BUILD_NUMBER}
'''
ssh something here && something else && another one
runs something here in the ssh session, and something else and another one locally. You want to add quotes to pass the entire command line to ssh.
sh "ssh -tt -o StrictHostKeyChecking=no ubuntu#IPV4_DNS uptime"
sh """ssh -v ubuntu#IPV4_DNS 'docker pull X:${BUILD_NUMBER} &&
docker rm -f test &&
docker run --name=test -d -p "3000:3000X:${BUILD_NUMBER}"'
"""
I switched to triple double quotes instead of triple single quotes, assuming you want Jenkins to expand ${BUILD_NUMBER} for you.
The original question asked about Bash, but for the record, you are running sh here, not Bash. If you wanted to use Bash features in a Jenkinsfile, you can add a shebang #!/usr/bin/env bash or similar as the very first line of the command. But that's not necessary here; all these commands are simple and completely POSIX. (Maybe see also Difference between sh and bash)
I'm trying to run a bash script on the remote server that is already on the remote server. I'm using ssh pass to do it but I'm seeing errors
test.sh (resides on the remote server)
#!/usr/bin/env bash
echo "This is test"
adb start-server
sshpass command (I'm running this sshpass command from docker ubuntu image
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "bash -s" < /Users/user/Documents/workspace/test.sh
I also tried
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host 'cd /Users/user/Documents/workspace/; sh test.sh'
I get this error message
bash: /Users/user/Documents/workspace/test.sh: No such file or directory
The examples you're showing are for a local script, and you said it's a remote script.
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "bash /path/to/test.sh"
that ought to do it.
you can try to find your test.sh on the remote computer:
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no user#host "find ~/ -name \"test.sh\""
Try with here-document:
sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -T user#host <<EOF
bash /Users/user/Documents/workspace/test.sh
EOF
Include -T option for ssh command, as mentioned above, to disable pseudo-tty.
[AT REMOTE MATCHINE] Ensure that path of adb executable is included in PATH environment variable. Else, specify it with absolute path in the Shell script.
I'm trying to run a remote sh from Jenkins to change a script to executable, but I take the following error:
[-manager_feature_kubernetes-YYLYXREUAV4NHLBACWJHV5YMQFOGHM4SS7G67ASIGYSZZGVS4VBQ] Running shell script
+ sshpass -p **** ssh'****#10.XX.XX.XXX chmod u + x /home/Script.sh '
sshpass: Failed to run command: No such file or directory
The logic of my script is:
sh "sshpass -p \" $ {passSSH} \ "ssh ${userSSH}#10.XX.XX.XXX \" chmod u + x /home/Script.sh \ ""
Can anyone help?
Have you tried this:
sshpass -p '$rootPassword' ssh -o 'StrictHostKeyChecking=no' $isRoot#$Host "chmod u+x /home/$USER/Script.sh"
Just write it here : my docker container did not have package lftp installed
a simple apt-get install lftp solved this issue.
Hope it will help ;)
In my case I was using docker container of alpine linux in which openssh was missing so sshpass failing. After installing openssh package it solved.
apk add openssh
(so just incase if some one faces same)
$rootPassword,$isRoot, $Host are Jenkins string parameter
sshpass -p ""$rootPassword"" ssh $isRoot#$Host id; echo $HOME;
Hi i want to up a docker jenkins container and add jobs by using jenkins-CLI command, these process done successfully when i did manually and by using shell script also. But the main problem is when i am trying to execute this script from remote machine docker container is starting but when i am trying to execute commands in docker container from remote machine it's showing error
cannot enable tty mode on non tty input
cannot enable tty mode on non tty input
My script on docker machine
b="branch1"
sed -i "s/master/$b/g" /root/docker/config.xml
#Run docker jenkins base image
docker run -d -P localhost:5000/jenkins_base2
#Printing docker container
export c=($(docker ps))
echo "${c[8]}"
export x="${c[8]}"
sleep 5
#Copying Config file
docker exec -it ${c[8]} bash -c 'scp root#192.168.0.86:/root/docker/config.xml /root/'
sleep 25
#creating job using jenkins CLI
docker exec -ti ${c[8]} bash -c 'java -jar /opt/apache-tomcat-7.0.68/webapps/jenkins/WEB-INF/jenkins-cli.jar -s http://localhost:8080/ create-job $b < /root/config.xml '
script on remote machine
ssh 192.168.0.86 sh docker.sh
Try ssh with -tt option.
ssh -tt 192.168.0.86 sh docker.sh