I need to run this sh commands. First, the command will be this one
keytool -importcert -file myfile.cer -keystore keystore.jks -alias "Aliasname"
Enter keystore password:
Re-enter new password:
Trust this certificate? [no]:
I need to run this commands automatically, And when the first command is successful. It asks for a password. I need to enter it automatically. and finally yes.
How to do that using .bat file?
If keytool is compliant with standard input, you can use:
(
echo your_password
echo your_password
echo y
)|keytool -importcert -file myfile.cer -keystore keystore.jks -alias "Aliasname"
Related
I'm having trouble trying to get my batch file to also give me super user access in PuTTY/Plink. I can auto-input the ip and password but I want to also automate it to where it will also give me su access when I run this batch file. So far it runs up to the point where I need to manually enter su but I'm trying to automate that so I tried -m commands.txt and now it just crashes.. Looking for any help here thanks.
this is what I have so far
#echo off
color b
cls
echo What is the IP for the unit?:
set /p IP= :
echo What is the SSH Password for this unit?:
set /p Passw0rd= :
echo What is the Root Password for this unit?:
set /p ro0t= :
start plink.exe -ssh user#%IP% -pw %Passw0rd% -m commands.txt
exit/b
what in the commands.txt:
su
The su gives you a hint what's wrong, for sure. But you cannot see it because you start plink using start in a new console window that immediately disappears. Remove the start, at least when debugging the problem.
Anyway, you most likely get "standard in must be a tty" or a similar message. The su by default needs terminal for the password prompt. The Plink is meant an for an automation, not an interactive use. So it by default does not allocate a pseudo terminal for the session. To force use of the terminal, add -t switch:
plink.exe -t -ssh user#%IP% -pw %Passw0rd% -m commands.txt
A similar question: "Sudo" fails with "sudo requires a tty" when executed from PuTTY command line
As a next step, you will probably want to execute further commands within su. For that see Executing (sudo) subcommands using Plink.
Though note that in general automating su, particularly su with a password, is usually a bad idea: Allowing automatic command execution as root on Linux using SSH.
I need to execute a shell script remotely inside the Linux box from Windows
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
exit
fi
echo "$1"
Here is the command I ran from Windows command prompt
cmd> plink.exe -ssh username#host -pw gbG32s4D/ -m C:\myscript.sh 5
I am getting output as
"Illegal number of parameters"
Is there any way I can pass command line parameter to shell script which will execute on remote server?
You misunderstand how the -m switch works.
It is just a way to make plink load the commands to send to the server from a local file.
The file is NOT uploaded and executed on the remote server (with arguments).
It's contents is read locally and sent to the server and executed there as if you typed it on a (remote) command line. You cannot give it arguments.
A workaround is to generate the file on the fly locally before running plink from a batch file (say run.bat):
echo echo %1 > script.tmp
plink.exe -ssh username#host -pw gbG32s4D/ -m script.tmp
Then run the batch file with the argument:
run.bat 5
The above will make the script execute echo 5 on the server.
If the script is complex, instead of assembling it locally, have it ready on the server (as #MarcelKuiper suggested) and execute just the script via Plink.
plink.exe -ssh username#host -pw gbG32s4D/ "./myscript.sh %1"
In this case, as we execute just one command, you can pass it on Plink command line, including the arguments. You do not have to use the -m switch with a (temporary) file.
I triggered the Shell script in "commands.txt" from Plink which worked for me like a charm with below method I tried:
You can define your script as an one liner using && in a file (I defined in one liner)
You need to run your command in <
Note: Use first EOF in quote like <<'EOF' but not the last one. Else you will see you code will behave weirdly.
Please see below.
Example:
sudo -i <<'EOF'
<your script here>
EOF
Then, finally run it using Plink:
plink -ssh username#hostname -pw password -m commands.txt
Have you tried putting the command and argument in quotes:
i.e. -m "C:\myscript.sh 5"
i need a help on how to give input to a command prompt using a batch file..
for example-
if i run the command mysql -u root -p to open my mysql server and it asks for password.. how i m gonna give that password to it using a batch file...
pls help me i am little new to it
Just specify the password besides -p in batch file. Eg: if username is Ankit and password is Devil, specify the following in the batch file:
mysql -uAnkit -pDevil
Ask for the input using Set /P, e.g.
Set /P "pwd=Please enter your password: "
You can then use the variable %pwd% in your command string, e.g.
mysql -u root -p %pwd% …
You could also use the same method to request the user name too:
Set /P "usr=Please enter your user name: "
Set /P "pwd=Please enter your password: "
mysql -u %usr% -p %pwd% …
Type Set /? at the Command Prompt for the command's usage information.
I need to login to the putty and run the below commands to complete the task.
putty.exe -ssh user#host -pw password -m c:\user\batchcommands.txt
1st Command :
cd/u01/app/oracle/user_projects/domains/COLLECT/EOD/bin_arm
2nd Command :
./FileUpload.sh
3rd Command :
cd/u01/app/oracle/user_projects/domains/COLLECT/EOD/bin_arm
4th Command :
./execute_eodarx.sh
How can I run these commands serially (completion of previous command)?
Write all commands in file with extension *.bat for e.g. auto_script.bat
Bat file is like shell scripts in windows and runs command in synchronous way.
then
putty.exe -ssh user#host -pw password -m "c: && cd path_to_file && auto_script "
Note : just use filename (of the bat file) as command in the directory. how to run bat file for cmd
I need to run a setup.exe from the local network with credentials.
I was able to do this with a bat file, but the problem is, but i don't want the cmd window showing up when this is executing.
So from what i've read, a good option is to use a vbs script like this, except i can't find a way to use it with credentials.
Set shell = WScript.CreateObject("Wscript.Shell")
shell.Run("\\192.168.0.100\Setup\setup.exe"), 0 , True
Basically what i need is the equivalent of this batch script in vbs:
net use Z: \\192.168.0.100\sh /user:user password /persistent:yes
start /d "Z:\Setup" setup.exe
you may do this:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "Z:", "\\192.168.0.100\sh", True, user, password
Set shell = WScript.CreateObject("Wscript.Shell")
shell.CurrentDirectory = "Z:\Setup"
shell.Run("setup.exe"), 0 , True
Note: MapNetworkDrive will fail if Z: is already mapped. You will need to handle that.
PSExec is what you want:
https://technet.microsoft.com/en-us/sysinternals/pstools.aspx
Like this:
Set shell = WScript.CreateObject("Wscript.Shell")
shell.Run("psexec.exe -u User -p Password -accepteula \\192.168.0.100\Setup\setup.exe"), 0 , True
Documentation:
https://technet.microsoft.com/en-us/sysinternals/pxexec
Using PsExec
Usage: psexec [\computer[,computer2[,...] | #file]][-u user [-p
psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c
[-f|-v]][-w directory][-d][-][-a n,n,...] cmd [arguments]
-u Specifies optional user name for login to remote computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-accepteula This flag suppresses the display of the license dialog.