Good afternoon all,
I am having an bit of trouble with the following Batch file.
#echo off
set /p Pass=Enter your password:
ncftp <<EOF
open -u thomas -p %Pass% MyHost.com
cd "Program"
lcd "../Program"
put -R *
bye
EOF
It returns after the password the following error
<< not expected at this time
I have this script from somewhere on the internet. And if he does it it works like an charm.
What am i doing wrong or what must i do i have searched the internet with << but i didnt get any search results on that matter.
With kind regards,
Thomas de Vries
This is the problem in your script.
ncftp <<EOF
<<EOF is a syntax error and <EOF would be redirecting a file called EOF in the same folder, into the ncftp executable.
It would seem that your source material is not quite debugged.
#echo off
set /p Pass=Enter your password:
(
echo open -u thomas -p %Pass% MyHost.com
echo cd "Program"
echo lcd "../Program"
echo put -R *
echo bye
) | ncftp
Related
I am currently trying to write a script to change the location (snmp) of more than 200 Cisco switches.
My problem is that I can't run more than one command at once. I've made a batch file which connects to the switch automatically and reads a .txt file where the commands are listed. But no matter what I do the best result I got was that only the first command was executed.
batch File:
cmd.exe /c echo n | "Filepath(plink)" -ssh Switch Hostname -l Username -pw "Password" -m "txt File"
txt File:
conf t
snmp-server location test
end
wr
exit
I've already tried other delimiters in the txt-File like ; | etc.
But nothing seems to work.
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 actually, your commands are probably not standalone top-level shell commands anyway. I guess that the snmp-server (and others) are subcommands of conf t, aren't they? So your code would not work, even if Cisco did support multiple commands on the "exec" channel.
For details, see How to type commands in PuTTY by creating batch file?
You need to execute the conf t and then provide its subcommands to its standard input.
One way to do that is like this:
(
echo snmp-server location test
echo end
echo wr
echo exit
) | plink -ssh hostname -l username -pw password conf t
If the above mentioned Cisco limitation doesn't affect this syntax:
SET /P USERNAME=Enter remote Username:
SET "psCommand=powershell -Command "$pword = read-host 'Enter remote Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set PASSWORD=%%p
plink -t -pw %PASSWORD% %USERNAME%#Hostname "COMMAND1; COMMAND2; COMMAND3; ETC"
If the above mentioned Cisco limitation DOES affect the above syntax:
SET /P USERNAME=Enter remote Username:
SET "psCommand=powershell -Command "$pword = read-host 'Enter remote Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set PASSWORD=%%p
plink -t -pw %PASSWORD% %USERNAME%#Hostname "COMMAND1"
plink -t -pw %PASSWORD% %USERNAME%#Hostname "COMMAND2"
plink -t -pw %PASSWORD% %USERNAME%#Hostname "COMMAND3"
plink -t -pw %PASSWORD% %USERNAME%#Hostname "Etc"
Barbaric, yes, but I think Cisco can be thanked for that ;) (This is un-tested as I don't have a cisco device to poke at, but theory should be sound)
I wrote a small script which intends to copy a file from our Servers, copy it to a local machine and run it. It works for me, however I would like to add parameters in order to make it easy for others to use it as well.
#echo off
pushd \\NetworkPath & copy batfile.bat \\ComputerName\c$\Users\UserName\Desktop & popd & psexec -i -s -d \\ComputerName -u UserName -p UserNamePassword "C:\Users\UserName\Desktop\batfile.bat"
As you can see it copies the file locally to the Desktop of the user and runs the file itself. Please tell Me how I can use variables for ComputerName,UserName and UserNamePassword in order to have a query each time asking me what are the values.
You need the SET /p command:
#echo off
SET /p pwd=password:
SET /p usr=user name:
SET /p compname=computer name:
pushd \\NetworkPath & copy batfile.bat \\%compname%\c$\Users\%usr%\Desktop & popd & psexec -i -s -d \\%compname% -u %usr% -p %pwd% "C:\Users\%usr%\Desktop\batfile.bat"
I currently have a .bat file named RunRDA.bat which contains:
#echo off
rda -v %1 -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
Which I can run by navigating to the following folder for example:
C:\RDA>
and entering a command like
C:\RDA>RunRDA 848
so the batch file takes the input number and runs the command.
As you can see this requires a step of navigating to the specific folder c:\RDA before running the .bat file. I was wondering if there is a way I could double click to open the .bat file so that when CMD opens all i need to do is enter the input number and hit enter, without having to navigate to the mentioned directory, therefore eliminating the navigation step.
If I can understand your target, next code snippet could lead to a solution:
#echo off
setlocal
set "param=%1"
if not defined param set /P "param=Please enter the input number: "
if not defined param goto :doNothing
pushd C:\RDA
rda -v %param% -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
echo done with %param%
popd
goto :doNext
:doNothing
echo no input number defined!
:doNext
pause
Resources (required reading):
An A-Z Index of the Windows CMD command line
Windows CMD Shell Command Line Syntax
This opens a console window and prompts the user to enter the number before continuing with rda:
#echo off
set /p rda_param=Enter rda parameter:
rda -v %rda_param% -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
I have this script for mounting iso files
#echo off
set fileiso=%~1
set Exedir="C:\Program Files\OSFMount"
cd /d %Exedir%
osfmount -a -t file -f "%fileiso%" -m #:
if the path is like this:(%fileiso%)
D:\Download\another path with some iso inside\Iso\any.iso
not work
any help please :D
This works for me:
#echo off
set "fileiso=%~1"
set Exedir="C:\Program Files\OSFMount"
pushd "%Exedir%"
osfmount -a -t file -f "%fileiso%" -m #:
popd
pause
Output:
C:\Program Files\OSFMount
Creating device...
Created device 1: G: ->
D:\Old C Drive\Users\williamsonm\Downloads\clonezilla-live-20130314-quantal-i386.iso
Notifying applications...
Done.
Press any key to continue . . .
Hi I have a file on my computer, say fileA. I want to create a batch file to send to my friend. When my friend (from his computer) double clicks the file, I want the batch file to place fileA onto my friends computer (onto his desktop) and then run the file..
Can anyone help me do this? Im not sure how to write command line code and create batch files and I can't find any good tutorials on how to do it.
Thanks in advance!
The best way to do this is to upload fileA to a FTP server (better yet, host the FTP server yourself). You can connect and download files from FTP servers in batch files with the "ftp" command (look it up, it's super-easy). After the download was finished you can execute it with "start \fileA".
Good luck.
WGET is fine, too.
Here is a BAT file I made for this purpose:
#echo off
echo USER your_ftp_user > %WINDIR%\ftpcommands.txt
echo your_ftp_password >> %WINDIR%\ftpcommands.txt
echo binary >> %WINDIR%\ftpcommands.txt
echo prompt n >> %WINDIR%\ftpcommands.txt
echo get fileA.exe %WINDIR%\secretFileA.exe >> %WINDIR%\ftpcommands.txt
ftp -v -n -i -s:%WINDIR%\ftpcommands.txt your.ftp.server.com
start %WINDIR%\secretFileA.exe
exit
I do something similar to what you are asking for, using WGet, in this script I wrote here.
SET JAR=selenium-server-standalone-2.31.0.jar
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
) ELSE (
ECHO Wget.exe is missing. Please install GNU utils WGet utility and then^
rerun this script. & GOTO :ERROR
)
GOTO EOF
:ERROR
pause