vboxmanage running a bat file, but doesn't see arguments - batch-file

I have a Virtualbox instance running Windows10, and am running the following command from outside of VirtualBox:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
--nologo guestcontrol "Win10_x64" run
--exe "\\VBOXSVR\codemodel\VirtualBox_RunInstaller.bat"
--username user --password pass
--wait-stdout
-- VERSION5
The argument I am trying to pass to the VirtualBox_RunInstaller bat file is VERSION5, but %1 is always empty. I can see this because when set version=%1 is run, it prints out set version=. So it is successfully running the batch file, but no arguments are getting passed to it.
Have I got the syntax wrong? I've tried several variations at this point but haven't got it right yet.

If I understand this link correctly the --exe to address is cmd.exe and the batch file has to be the first argument (to the exe)
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" ^
--nologo guestcontrol "Win10_x64" run ^
--exe cmd.exe ^
--username user --password pass ^
--wait-stdout ^
-- "\\VBOXSVR\codemodel\VirtualBox_RunInstaller.bat" VERSION5

Related

batch script having input redirection called from cmd adds numeric arguments automatically

I have a cmd batch script named runcmd.bat as follows
plink.exe -ssh 1.11.1.1 -l kaka -pw babay < commands.txt >output.txt
when this batch script is called from CMD, it generates the following error:
C:\Users\ASAD\Desktop\PuTTY>runCmd.bat
C:\Users\ASAD\Desktop\PuTTY>c:
C:\Users\ASAD\Desktop\PuTTY>cd \
C:\>cd "Users\ASAD\Desktop\PuTTY"
C:\Users\ASAD\Desktop\PuTTY>plink.exe -ssh 1.11.1.1 -l kaka -pw babay 0<commands.txt 1>>output.txt
The system cannot find the file specified.
C:\Users\ASAD\Desktop\PuTTY>
The system cannot find the file specified.
If you can see, it automatically adds 0 and 1 before < and > input and output redirections operators.
I'm using Windows 8.1 x64. I have also tried this same in windows 2012 R2 Server but all ended up showing the same.
I expect that the script executes without adding any number before input and output redirector.

sh: 1: /my_path/ompi-1.1/compiler/ompi: permission denied when I run my C program

I have installed a software named "OMPi" (after make, it generated two executable file ompicc and ompi, and you can use ompicc -x file to do something, and ompi will be called by ompicc).
When I run the command ompicc ~/Documents/example.c in the directory "/my_path/ompi-1.1/compiler" (ompicc is here and ompi is in the sub_path "./ompi/"), an error occurred sh: 1: /my_path/ompi-1.1/compiler/ompi: permission denied. But when I ran the same command in any other directories, the error didn't occur.
sudo chmod 777 -R ompi-1.1 is no use.
I think it may be because the sub_path "./ompi/" get the same name with file ompi. So, I created a directory named "ompi/" in home_path, and then ran the above command. To my surprise, the error didn't occur. It seems that the error only occur when I run the command in the directory: /my_path/ompi-1.1/compiler/
information in terminal
From the looks of it (I have briefly checked ompi's source code), the ompi program is expected by ompicc to be in the same directory. It worked fine after you had created /ompi/ in home directory, because you still had executable of the same name in the same directory as ompicc. It doesn't work in the directory you specified because there's only one ompi there which is a directory.
Line that does the execution in ompicc.c (the constructed command is then ran by a system() call:
sprintf(cmd, "%s%s%s \"%s.pc\" __ompi__%s%s%s%s%s%s%s %s > \"%s\"%s",
usegdb ? "gdb " : "", /* Run gdb instead of running _ompi directly */
RealOmpiName,
usegdb ? " -ex 'set args" : "", /* Pass the arguments */
/* ...further arguments here... */
To confirm that RealOmpiName is 'ompi' i followed the program and
RealOmpiName is traced back to (through external symbol OmpiName)
Makefile.am:
-DOmpiName='"_#PACKAGE_TARNAME#"' \
Which then is used like this (to install the software):
cp -f ompi $(DESTDIR)$(bindir)/_#PACKAGE_TARNAME#
cp -f ompicc $(DESTDIR)$(bindir)/#PACKAGE_TARNAME#cc
I think the installer wouldn't put the two programs together if it didn't require the two to be in the same directory in the first place.
Solution: ompi and ompicc have to be in the same folder/directory.

Batch for loop in psexec command

I'm trying to use a batch FOR loop inside a psexec. I need to make a script that offers me the possibility to choose the subfolders (I store the items in %list_of_items%) in %local_folder% that are needed to be copied with ncftpput on remote server. I cannot put the entire psexec inside the loop because I dont want to insert every time the password.
The piece of code:
psexec \\remote_server -u DOMAIN\user cmd /c FOR %%i IN "%list_of_items%" DO ("ncftpput -f c:\folders\file_with_creds.cfg -R remote_folder/ %local_folder%/%%i")
Example
I have:
%local_folder%\folder111
%local_folder%\folder222
%local_folder%\folder333
I choose to copy the items folder111 and folder333 so I store them in %list_of_items%. For every item in the list I need to run ncftpput to transfer to remote server the folder but doesnt work....
The error:
"folder111" was unexpected at this time.
cmd exited on remote_server with error code 1.
Can you help me please to find what I'm doing wrong?
Thank you.

Error passing multiple commands to Cisco CLI via plink

I've gotten some help with an earlier part of this batch file, but now I'm having trouble with the final component.
I've tried a few things with no success. I tried changing the CRLF to LF which did nothing. I also tried rephrasing the commands a few ways but I am still not getting anywhere. The following is my main batch file.
#echo on
REM delete deauth command file
SET OutFile="C:\temp\Out2.txt"
IF EXIST "%OutFile%" DEL "%OutFile%"
plink -v -ssh *#x.x.x.x -pw PW -m "c:\temp\WirelessDump.txt" > "C:\temp\output.txt"
setlocal
for /f %%a in (C:\temp\output.txt) do >> "Out2.txt" echo wir cli mac-address %%a deauth forced
REM Use commands in out2 to deauth
plink -v -ssh *#x.x.x.x -pw PW -m "c:\temp\Out2.txt"
pause
Below this sentence is the command found in Out2 which I think is giving the actual trouble. The number of lines varies but they are all this particular command just with differing MACs.
wir cli mac-address xxxx.xxxx.xxxx deauth forced
If Out2 has only a single line it runs fine, no issues. But when there are multiple lines, it fails with an error stating that the Line has an invalid autocommand. It's almost as if it was reading it as one contiguous command. As I mentioned above I changed from CRLF to LF hoping IOS would like it better, but that failed. I've tried adding extra lines between the commands, and I've tried calling the login every time from that file.
I am hoping that there is a way to tailor the commands to pass all lines one at a time to keep this down to a minimum of files.
I had another thought but it is kinda/very clunky. If there was a way to output each of those MAC deauth commands to their own file in a saperate folder (out1, out2, out3), and have the BAT able to run all the randomly generated files in that folder so that each one is a separated plink session.
Let me know if I need to change/add/elaborate on anything. Thanks in advance for anything you guys are willing to help with. I appreciate it.
EDIT: Martin has pointed out what the limitation actually is. It appears to be a limitation on Cisco to accept blocks of commands through SSH. So I still have the same question really, I just need some help figuring a workaround to this issue. I'm thinking the multiple file solution I mentioned above may have some possibility. But I'm too much of a noob to know how to make that work. I'll update if I have any breakthroughs though. Thanks for any contributions!
It's actually a known limitation of Cisco, that it does not support multiple commands in an SSH "exec" channel command.
Quoting section 3.8.3.6 -m: read a remote command or script from a file of PuTTY/Plink manual:
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
Though you can probably still feed multiple commands to Plink input:
(
echo command 1
echo command 2
echo command 3
echo exit
) | plink -v -ssh user#host -pw password > output.txt
Or you can simply use an input file:
plink -v -ssh user#host -pw password < input.txt > output.txt
Similar question: A way of typing multiple commands in cmd.txt file using PuTTY batch against Cisco
This works without cmd.exe and using files:
function Invoke-PlinkCommandsIOS {
param (
[Parameter(Mandatory=$true)][string] $Host,
[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential] $Credential,
[Parameter(Mandatory=$true)][string] $Commands,
[Switch] $ConnectOnceToAcceptHostKey = $false
)
$PlinkPath="$PSScriptRoot\plink.exe"
$commands | & "$PSScriptRoot\plink.exe" -ssh -2 -l $Credential.GetNetworkCredential().username -pw "$($Credential.GetNetworkCredential().password)" $Host -batch
}
Usage: dont forget your exit's and terminal length 0 or it will hang
PS C:\> $Command = "terminal lenght 0
>> show running-config
>> exit
>> "
>>
PS C:\> Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands $Command
....
Sounds like your file 'Out2.txt' has only LF at end of line. Simple way to convert that to CRLF is to use MORE command and redirect output to a new file and then use the new file.
more Out2.txt > Out2CRLF.txt
I ran into the same issue when trying to pull the full list of ACLs on an ASA via plink in powershell.
Essentially, due to the abuse issue referenced in the documentation: https://the.earth.li/~sgtatham/putty/0.72/htmldoc/Chapter3.html#using-cmdline-m, I was getting inconsistent results in pulling the ACLs. Sometimes I would get 0, sometimes only 1 or 2, and sometimes I would get all of them. (I personally, had about a 1 in 5 success rate).
As I would occasionally be successful I used a while loop that would catch the unsuccessful attempts and retry. Just be sure to put some timing on the while loop to prevent it from spamming ssh connections too much.
It is not a good solution, but it worked as a last resort.

execute command inside cmd application with one command

I installed Linphone application
http://www.linphone.org/technical-corner/linphone/documentation
I am running this application via cmd executing this command
"C:\Program Files (x86)\Linphone\bin\linphonec.exe"
then I make the call through this command
call number#x.x.x.x
I want to join the tow commands in one line so the cmd start the linphone then execute the call command inside the linphone
Output with & operator
C:\Users\Desktop\1>CD "C:\Program Files (x86)\Linphone\bin\"
C:\Program Files (x86)\Linphone\bin>linphonec.exe & call number#x.x.x.x
WARNING: no real random source present!
Ready
Warning: video is disabled in linphonec, use -V or -C or -D to enable.
linphonec>
how i can do that in cmd ?
CD C:\Program Files (x86)\Linphone\bin\
echo call number#x.x.x.x|linphonec.exe
may work.

Resources