I'm have some bash script (myscript.sh), one of logical steps is to run ssh command against Windows machine running open-ssh.
When I'm running the script (myscript.sh) from the shell everything works fine.
But when I am running same script from Jenkins (CentOS 7.3) it fails to retrieve content via ssh command: ssh root#windows-server hostname.
Please need your help.
The user running the jenkins process do probably not have the correct executable rights or group membership to do so.
Try
sudo -u "jenkinsuser" myscript.sh
If that fails you confirmed the issue.
Change the execute rights on your script or put the server process owner in the right group if this is the case.
Related
I am facing an issue in jmeter that I want to know if I can solve.
I need to run a script in distance computer.
when I run the script via command line in my computer it is working.
plink -ssh jenkins#178.27.288.288 -pw passtest sudo /opt/test/test.sh
I want to run it in Jmeter from my computer (the same as the script run).
I tried the ssh sampler that did not work
I want to useage the OS sampler, Is it can be done? Can I run script on distance computer?
The only explanation I found was from blazemeter site, and mentioned:
"Again, since running the “plink” program via the OS Process Sampler is quite easy,"
remote machine: jenkins#178.27.288.288,
password for remote machine: passtest,
command: sudo /opt/test/test.sh
So can someone please advise
I added the OS sampler
and get this message:
Exception occurred whilst executing system call: java.io.IOException: Cannot run program "sudo /opt/test/test.sh" (in directory "plink -ssh jenkins#178.27.288.288 -pw passtest "): CreateProcess error=267, The directory name is invalid
Can someone please advise how to run the command in the remote computer?
once again if I take the full line into command command line it is working, but after I cut it for Jmeter it is not working? what am I missing
Command arguments need to go in the "Command parameters" section, not in the "Working Directory"
I would suggest running your script via cmd.exe interpreter, so the actual command would be cmd, not the Linux command
It is more safe to provide -hostkey parameter as if the remote Linux machine is not in known_hosts your script will get stuck
Assuming all above your OS Process Sampler configuration should look like:
It might be easier to use JSR223 Sampler where you can invoke a program and get the output as easy as:
"c:\somefolder\plink.exe -pw passtest sudo /opt/test/test.sh".execute().text
More information on the approach: Apache Groovy - Why and How You Should Use It
I have the PowerShell scripts (.ps1) on my Centos server. I can successfully execute them locally, but don’t know how I can execute these scripts remotely from another Centos server.
I’ve tried to execute scripts after connecting over SSH and I’m getting errors
-command not found and -syntax error.
How to run PowerShell scripts on Linux remotely from another Linux box?
You can simply ssh to the PowerShell server and run your .ps1 scripts from the console like this: pwsh your_script.ps1
Here is the solution that I'm using:
ssh to the server: ssh user#server_name
navigate to the scripts directory
run pwsh script_name.ps1
I don't need to connect with PowerShell session and didn't do any configuration on PowerShell server. Hope it helps.
I'm trying to add a build step in jenkins to copy files from my build server to my web application server. I've got the following command working in the command prompt
sudo scp -r /var/lib/jenkins/workspace/demoproj/publish root#0.0.0.0:/usr/temp
but when I run this command, it prompts me for a password every time. I found out about sshpass, but when I run this command...
sudo sshpass -p "passwordhere" scp -r /var/lib/jenkins/workspace/demoproj/pub root#0.0.0.0:/usr/temp
the terminal gets stuck. And never makes it through.
My main problem is if I add the first command to a build step in jenkins, it won't be able to pass the password over. How can I either supply the password in jenkins, or modify the command to pass over my credentials?
Helpful information: I'm using Putty on Windows 10 to connect to my
Ubuntu 16.04.3 LTS x64 servers from another Ubuntu 16.04.3 server.
First, sshpass needs to be installed on both the systems that is, the one running your jenkins instance as well as the one you are trying to access that is: root#0.0.0.0. You can verify it by doing 'which sshpass' or 'whereis sshpass'. If its not installed even in one of them then you need to install it first.
Also, Have you ever tried doing a ssh to the said machine: root#0.0.0.0 from the system where you have your jenkins instance? If not then there might not be an entry in the 'known-hosts' of either system. for that you can do ssh with '-o StrictHostKeyChecking=no' option to make an automatic entry in known-hosts.
Alternatively, if you dont want to enter password again and again you should work with 'keys'. Generate a unique key for both the systems and do an scp or ssh with -i option.
You should use jenkins credentials instead of using sensitive passwords directly into the scripts. Put the whole scp or ssh part inside a block which looks like: withCredentials(){}.
What's the point of having CI if you are required to be nearby to enter password every time? Install "publish over ssh" plugin, it has a step to send stuff over ssh.
https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin
Look at "Use SSH during a build" section, you can use "send files or execute commands over SSH" build step. This shall become available after plugin installation.
I trying to execute a service and pass a specific user without run sudo command.
If I use the sudo command, the application will create a temp files with root permission and when the service was been restarted with correct user (Application User) the application user will not able to access this temp files.
Independent of the user who starts this service, the process need start with application user.
Have any way to fix it?
My OS it is Ubuntu 16 and CentOS 6/7.
Thanks
put the start command in sudo and use the su - c applicationuser /full/path/to/app and args
su -c NAME will run the following command as if called by NAME
you can clean that up a bit by putting the command in a shell script and then putting the shell script in sudo.
I want to upload a file which can auto run and reboot on a linux system.
Or atleast do some changes on the system.
Please provide some help.
Use scp to copy the script to the device.
scp myscript user#server:/tmp/myscript
Then run with ssh.
ssh user#server 'sh /tmp/myscript'
Or if you don't want to enter the password, you can use certificate based authentication.
If you want it to periodically run automatically, configure the Linux system to run it as a cron job