.bat Script Terminating Before AWS Auto Scaling Commands Executed - batch-file

I am fairly new to Amazon Cloud Auto Scaling (and AWS all together).
I am currently trying to write a .bat script that will automatically create a launch configuration and then an auto scaler. The aim is for an image that was previously set up about a week ago by a coworker.
The problem I encounter is that when I run the script, no commands past the launch configuration command is executed.
The code is here:
echo Beginning Auto Scale Up Process
REM Create a launch config
as-create-launch-config --image-id ami-xxxxxxx --instance-type t1.micro --user-data "Created by Launch Config reportingServerScaleUp-lc" --launch-config reportingServerScaleUp-lc
echo Timer Complete
I am looking for suggestions to help me debug this issue. Or advice on how to solve it. After the "echo Timer Complete" I have a command to create an auto scaler. Though, not even the "echo Timer Complete" is executed. The console does return indicating that the launch configuration is created though :)
Also, when I enter each command sequentially into the command line, each executes perfectly. The launch configuration is created as is the auto scale group.

It turns out that the AWS commands call exit which exits the .bat script prematurely.
Prepending each AWS command with "call" did the trick.
I found suggestions in this question: Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

Related

FileZilla Pro CLI Batch command file not executing

I am currently attempting to use FileZilla Pro CLI on a Windows machine to connect and upload to a site in that is working in the Site Manager.
The issue is, the command below works perfectly when pasting it directly into the cmd line. However when saving it as a batch file, it simply just gets to the fzcli> prompt and then nothing happens.
The two line breaks are on purposes to override the requirement for a password and it works perfectly when pasted in.
Does anyone know if this is a cmd line issue, or if my commands need to be different to work in batch file mode?
fzcli
connect --site 0testsite01
put C:/inetpub/wwwroot/websites/sftp/files/customer/test-01.txt /test-sftp/testuser01/test/test-01-uploaded.txt
PAUSE
Your batch file executes fzcli in an interactive mode. The fzcli then waits for you to interactively enter the commands. Only after you would exit the fzcli, the batch file would continue. And fail, as it will try to execute connect as a batch file command. The fzcli does not know about the batch file. Nor does the batch file interpreter know about the fzcli commands.
It's a common misconception. You will find plenty of similar questions basically about scripting any tool that has its own commands. For example: sftp, ftp, psftp, winscp.
To provide commands to fzcli, it seems that you need to use --script switch. The fzcli documentation gives this example:
fzcli --mode standalone --script C:\Scripts\script-file

Batch File to start application restarts itself again and again

I'm trying to create a batch script to activate a conda environment and start an application within it (which has been previously installed).
But for whatever reason, the application doesn't start but the batch script itself restarts again and again.
I'm using the following script:
#ECHO OFF
ECHO Activate Environment ...
call activate ENV
ECHO Start application ...
ApplicationName
PAUSE
The output if I start the batch script by doubleclicking it is:
Activate Environment ...
Start application ...
Activate Environment ...
Start application ...
Activate Environment ...
Start application ...
I also tried with call ApplicationName and start ApplicationName but this doesn't work either. The application I would like to start is an own application which can be installed via pip (Python application, entrypoint specified in setup.py).
The normal use is to open a cmd or the Anaconda prompt, activate the environment manually and enter the command ApplicationName on the command line. After this the application triggers a browser window to open a login screen. When I use the application like that the command line window stays open during the execution of my application and prints debug messages.
I just don't understand why the commands are repeated again and again instead of that the application is started.
Do you know what causes the behaviour?
Thank you in advance for an answer!
Best Regards
Your batch file has the same name as your undisclosed ApplicationName.
Therefore the batch file will restart ApplicationName.bat instead of ApplicationName.exe

Writing Batch file that monitors a certain web page's status

The issue
I am trying to create a batch file that will execute the following two commands:
cd /some/path
dotnet run
that produces the following output:
It starts my localhost server.
Trying To Accomplish
What I would like to do is, put those two commands in a batch file and automatically open Chrome to the server address, HOWEVER, the dotnet command takes some time to finish. So somehow, I would have to keep monitoring localhost to see if it is available.
Any help would be appreciated. Although opening a CMD window, typing those 2 commands, and waiting a minute isn't all that much of a problem, it sure would be nice to just click on a batch file.
Thank you.
You can create a batch file like this code :
#echo off
Set "ApplicationPath=%UserProfile%\source\repos\PruttPos\PruttPosSystem\"
CD /D "%ApplicationPath%"
dotnet run
Start "Chrome" Chrome.exe "http://localhost:5000"
pause

VSTS, Launching Android emulator from a batch file not working as expected

I am trying to launch an Android emulator from a batch file inside my build definition, with the next command:
start /WAIT "Start Emulator" "C:\Program Files (x86)\Microsoft Emulator Manager\1.0\emulatorcmd.exe" launch /sku:Android /id:97522427-7A5E-4F3B-96A8-B9F9F0C0423A
I tried to add the build step as a command line, and a batch script.
Problem: The script is working right, and opening the emulator and wait for it to fully open, but once script finishes executing and console closes, the emulator is closing as well.
I tried to run the script directly on build server, and it works fine without closing emulator, but when queued as a build step, I am facing the above problem.
Question: How can I force the emulator to stay open after batch file finishes executing?
EDIT:
It looks like the build definition task terminates all processes it created in the defined step, I have tried multiple script, tried cmd /k and tried the /b and tried to create another batch file that actually calls this one or start it, yet no results. I am still waiting for any possible solution.
Alright, I tried a lot of scripts in batch files, and I tried to run it from command line, after a lot of time waste and getting tired, I decided to give PowerShell task a try to fix my problem. I ended up with this:
Start-Process -FilePath "C:\Program Files (x86)\Microsoft Emulator Manager\1.0\emulatorcmd.exe" -ArgumentList "launch /sku:Android /id:97522427-7A5E-4F3B-96A8-B9F9F0C0423A" -Verb runas
Start-Sleep -s 60
This made the emulator start, and stays running even after PowerShell script ends.

Execute windows batch command from Jenkins fails but runs fine in cmd.exe

I am trying to run this command in jenkins after a MSbuild
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Y: is a mapped network drive. This runs fine in cmd.exe but when trying to run it in Jenkins, I am getting the error Invalid drive specification.
Here is the output from jenkins:
Time Elapsed 00:00:04.03
[trunk] $ cmd /c call C:\Windows\TEMP\hudson3389873107474371072.bat
C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Invalid drive specification
0 File(s) copied
C:\Program Files (x86)\Jenkins\workspace\trunk>exit 4
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Any help would be appreciated.
I too had a similar issue once. Try granting the Jenkins service "Logon as This account" right under services.msc and make sure the account you type there is the same as the one you use for running cmd.exe.
These commands based on Java JAR files worked for me:
cmd
net use x: \\
xcopy "dist\" x:\ /Y
And that's it! I spent lot of time figure out this issue and nothing worked until I wrote CMD and NET USE!
Neither I didn't need to change permission on jenkins service nor use runas command.
But I must mention that everyone had read and write access to the network drive.
I had the same issue with my Windows Task running a batch file (I know it is not exactly same) where I tried to copy file to network location i.e. shared drive. I used the UNC path and mapped drive as well but the error was same. For me it was error number 4 - MS DOS error code.
The solution was to use net use command! Hope that it helps.
Easy fix for most things.
Make a batch command with what your trying to run, filename.bat with the command prompt text inside.
Make a normal windows shortcut for the batch command, edit the shortcuts advanced properties and check the "Run as admin" (tricky tricky).
Now run the filename.lnk shortcut from jenkins command line call, this will get you around all the jazz.
:)
The solution of adarshr (i.e., modifying the log on credentials of the service) has worked for me for a part of the problem: in my case, this allowed me to successfully check out a mercurial repository (using ssh protocol), which I could not do when using 'Local System account'.
However, I still have different behavior between running a command-line script or running the same script from a jenkins 'execute shell' script in the build section. In my case, I compile a Python extension. In Jenkins, I cannot import the extension (I don't see any error, but the execution simply stops, so I suspect it crashes).
If I uninstall the service and run the slave agent as a Java Web Start, I do get the same behavoir. It is a temporary fix for me, but it means that when I reboot the windows build machine, I have to manually re-start the Java Web Start application.
So -at least in my case- it is clear that this is a credential problem.
Credentials usage documentation: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
I've solved my issue with the CIFS plugin.
Faced similar issue and found two ways to solve.
Type 1:
Tell Jenkins about mapped drive.
1.Goto -> Manage Jenkins -> Script Console (Groovy Script).
2.Run below command
def mapdrive = "net use Y: \\\\copy_nework_address"
mapdrive.execute();
println "net use".execute().getText()
Type:2
1.Goto -> cmd -> run "net use" to know network address
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Copy_Network_Address\Extraction_Zone\Jenkins\" /E
Conclusion:- I prefer 2nd types as after every restart i should run Groovy Script.

Resources