I've been stuck on this issue for the past 3 or 4 days. I am trying to run the attached command in a Windows batch file in Jenkins. This causes it to hang and it doesn't accept any further inputs:
knife winrm ec2-xx-xx-xx-xx.compute-1.amazonaws.com interactive -m -x Administrator -P xxxxxxxx
This works fine if run manually on a Windows machine, but I think the ruby.exe that is being opened is starting to cause Jenkins some problems.
Has anyone ever used knife winRM's interactive mode in such a way before? I'm at my wits end here and I really need this to work. Thank you for any help you could provide.
Have you tried running it as "call knife" instead of just "knife"? If, inside a batch file, you run another batch file (knife.bat, for example) without "call", the initial batch file run is terminated. There's a good explanation here: http://www.robvanderwoude.com/call.php
Related
Edit: As of 01/31/2023 the scripts that I am using below ARE working. Any patterns of inconsistencies that I find I will report here. Would like to leave this open in case others have findings/advice they are interested in sharing in relation to bash scripting/LastPass CLI/WSL
I am looking to use the LastPass CLI to make some changes to Shared Sites within our LastPass enterprise. I was able to write the scripts (fortunately with some help from others on here), however I am unable to get the commands to work properly within a script.
One of the commands that I WAS having troubles with was lpass share create. This command worked directly from the command line, but I was unable to run this command within a script successfully. I have a very simple script, similar to the one below:
#!/bin/bash
folderpath=$1
lpassCreateStoreFolder(){
lpass share create "$folderpath"
}
lpassLogin(){
echo 'testPWD' | LPASS_DISABLE_PINENTRY=1 lpass login --trust --force tester#test.com
}
lpassLogin
lpassCreateStoreFolder
I've been invoking my script through the PowerShell command line like so:
wsl "path/to/script" "Shared-00 Test LastPass CLI"
Sometimes this command works within the script and other times it does not. When I tried running this script around mid December, I had no success at all. The script would run through all the way, the CLI would even give me a response
Folder Shared-00 Test LastPass CLI created.
and the LastPass Admin Console logs show me a report of "Create Shared Folder". The problem is when I go to my LastPass Vault, the Shared Folder was rarely/if ever created. Running the command without a script, directly from the command line worked almost 100% of the time. I initially chalked this up to inconsistencies on their end, but now I am experiencing these same problems with a different command.
Similarly I have been using the lpass edit command to make edits to sites within our LastPass vault. Once again, I have a relatively simple script to make the edit to the site:
#!/bin/bash
lpassId=$1
lpassSetNotes(){
printf "Notes:\n What are your notes?\nThese are my notes" | lpass edit --non-interactive --sync=now "$lpassId"
}
lpassLogin(){
echo 'testPWD' | LPASS_DISABLE_PINENTRY=1 lpass login --trust --force test#test.com
}
lpassLogin
lpassSetNotes
and have been invoking this script through Powershell like so:
wsl "path/to/script" "000LastPassID000"
like the lpass share create command, running the script does not produce the desired output. The script runs all the way through and my changes are reflected in the logs, but when I go to the vault the site itself is never changed. The command DOES however work when I run it from the command line directly within WSL.
I am relatively new to writing Bash scripts/the Linux operating system, so I'm not entirely sure if this something wrong on my end or just the vendor's tool that I am utilizing producing inconsistencies. Any help would be appreciated, I know this issue might be hard to replicate without a LastPass account
Example LastPass CLI calls that work directly from command line in WSL
lpass share create "Shared-00 Testing LastPass CLI"
printf "Notes:\n What are your notes?\nThese are my notes" | lpass edit --non-interactive --sync=now "$lpassId"
References
LastPass CLI
CLI Manual
CLI GitHub
I have a deploy script in which I want to clear the cache of my CDN. When I am on the server and run my script everything is fine, however when I SSH in and run only that file (i.e. not actually getting into the server, cding into the directory and running it) it fails and states the my doctl command cannot be found. This seems to only be an issue with this program over ssh, running systemctl --help works fine.
Please note that I have installed Digital Ocean's doctl using sudo snap install doctl and it is there.
Here is the .sh file (minus comments):
#!/bin/sh
doctl compute cdn flush [MYID] --files [*] # static cache
So I am not sure what the issue is. Anybody have an idea?
Again, if I get into the server and run the file all works, but here is the SSH command I use that returns the error:
ssh root#123.45.678.999 "/deploy/clear_digital_ocean_cache.sh"
And here is the error.
/deploy/clear_digital_ocean_cache.sh: 10: doctl: not found
Well one solution was to change the command to be an absolute path inside my .sh file like so:
#!/bin/sh
/snap/bin/doctl compute cdn flush [MYID] --files [*] # static cache
I realized that I could run my user commands with ssh (like systemctl) so it was either change where doctl was located (i.e. in the user bin) or ensure that the command was called with an absolute path adding the /snap/bin/ in front of the command.
I'm working on restarting Tomcat from remote server. I can able to connect to server and view the output of few basic commands. When i'm performing tomcat/apache restart its not happening since some configurations defined in bashrc. How to include bash from my jenkins? These are my lines
#!/bin/bash
ssh -tt uname#ip
cd tomcat/bindirectory
catalina.sh stop
sleep 4
catalina.sh start
Jenkins by default uses non-interactive logins.
.bahsrc is executed.
/etc/profile , /etc/default/* are not.
I'm not entirely sure on what you're trying to accomplish? Maybe add some output as well.
Im trying to execute script on remote machine (script resides REMOTELY, and NOT in agent folder or whatever) through Command Line Runner:
#echo off
%env.ALLUSERSPROFILE%\JetBrains\TeamCity\plugins\.tools\psexec.exe \\12.34.56.78 -h -u admin -p 12345 T:\Folder\Script\update.cmd T:\Folder\Server
But I always get:
The system cannot find the path specified.
Process exited with code 1
And NOTHING else. TeamCity and psexec just scrambling output and not giving it out on what actually not found, what is the problem or whatever. It just freaks me out to even use psexec to run something.
What am I doing wrong? What else do I need to specify to JUST run it remotely (Im not asking about giving me output of script, because as I searched I understand what such simple functionality is not supported by psexec at all)?
I need to log in to a Windows server via SSH through a local Python (2.7) script, start a script on the server and then disconnect the SSH connection, so that the local script can continue to run.
As of now, I am using fabric, and the local script will not continue before the remote script is done and the SSH connection is closed.
I have read on a range of forums, but it seems to my (admittedly inexperienced) eyes that most replys use unix commands. I need to be able to log onto a windows machine however.
What can I do?
Thank you very much in advance!
Does this help you? You can write a batch script that'll start in the background:
Running Windows batch file commands asynchronously