batch script stopped after ssh and did not continue [duplicate] - batch-file

This question already has answers here:
Pass commands as input to another command (su, ssh, sh, etc)
(3 answers)
Closed 1 year ago.
This is my batch script. I wanted to automate restart of the mysql
cd G:\My Drive\TCL
G:
ssh -i themedcreations.pem ec2-user#ec2-3-16-127-158.us-east-2.compute.amazonaws.com
sudo su
service mysqld restart
Pause
The script is okay if I manually input the lines in cmd.
I was hoping the batch file could run itself till the end, but it stops after running the ssh -i line, afterwards it requires manual input.
What went wrong? I am completely new to batch scripting. I tried timeout or wait. They all didn't work.

Use the -n flag and see if it solves your problem.
example
ssh -n -i themedcreations.pem ec2-user#ec2-3-16-127-158.us-east-2.compute.amazonaws.com

Related

Reading %0 as %0 in CMD

I think this is a pretty basic doubt but I could not find the solution myself. What I am trying to do is to create a .bat file in order to automate a data upload process. But the command to be passed in .bat file has to have database password which unfortunately has '%0' in it. So, when I run it, cmd reads it as the file name instead, causing it to run into an error. So, can we write this in a way cmd reads '%0' as it is and doesn't change it to filename?
Without seeing your code, it's guessing ...
Probably you are using something like
mysql -u root -p secret%0
Then you can fix it by doubling the percent sign
mysql -u root -p secret%%0

Is It Possible Start and Stop MariaDB service using NET command without Administration? [duplicate]

This question already has answers here:
Stop and Start a service via batch or cmd file?
(18 answers)
Closed 3 years ago.
I have installed MariaDB 10.4 Series in Window 7. But there's no option for start/stop and restart in installation folder. So i had to stopped through services.msc tool. Hence I have created batch script but when I run the script then I am getting "Access is denied" error message because i run the script direct from desktop. I don't want to run cmd as administrator. I want to run the script direct by clicking.
Following the batch script:
#eacho off
net stop mariadb
if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem to stop the service
pause
Please help me that How can I start and stop the service of MariaDB using batch script without run cmd under administration ?
Stopping and starting Windows services via command line:
net stop YOURSERVICENAME
net start YOURSERVICENAME

Running a HTA file remotely using PSTools

Its almost certain that HTA files are obsolete, but i've found that they are much better than net send / msg.
I'm trying to run a HTA file on a remote machine using PSTools, but instead of it running, it brings back a broken window:
Running the HTA file using CMD (locally) works perfectly though.
My PsExec line:
PsExec.exe -accepteula -i -d \\itwall cmd 'mstha \\intranet\Downloads\VisitorSystemNewMessage.hta asd'
I even tried to run the HTA from a Batch file, but the exact same thing happens.
Any ideas?
It's because the account running the command cannot interact with the session of the remote user.
Use the -s switch to run the HTA using the system account of the remote computer.
Also, you shouldn't need to run cmd. You should be able to just specify mshta.exe then your arguments.
PsExec.exe -accepteula -s -i -d \\itwall mshta.exe \\intranet\Downloads\VisitorSystemNewMessage.hta asd
Edit: To illustrate that this is not an HTA issue. Run the following command:
PsExec.exe -accepteula -i -d \\itwall notepad.exe
Notice you'll have the same black window showing.

FTP script failing [duplicate]

This question already has answers here:
How to ftp with a batch file?
(10 answers)
Closed 4 years ago.
I am trying to create a script which copies the contents of one directory to an FTP location but every example I have tried to work with has failed. I need this to target a folder within the FTP site can anyone point me in the right direction.
Thank you
Batch file is below.
#ftp -i -s:"%~f0"&GOTO:EOF
open 0.0.0.0
name#address.com
Pa55word
!:--- FTP commands below here ---
lcd c:\program files\system\location
cd storage
binary
mput "*.*"
disconnect
bye
Once FTP is open you are no longer at a command prompt. You are inside FTP. You need to use your batch file to write the ftp script,FTPInstructions.ftp in the following example. Then open ftp, telling it to run the script.
When you invoke the ftp.exe program to run the ftp script from the batch file you can redirect the ftp.exe console output to a log file and examine that log file for errors. You'll need to redirect both stdout and stderr. Something like this:
echo open 0.0.0.0>FTPInstructions.ftp
echo user UserName>>FTPInstructions.ftp
echo Password>>FTPInstructions.ftp
echo something>>FTPInstructions.ftp
echo something else>>FTPInstructions.ftp
.
.
echo bye>>FTPInstructions.ftp
ftp.exe -n -s:FTPInstructions.ftp>FTPSession.log 2>&1
You can then use FIND or FINDSTR in the batch file to locate any error messages output by ftp.exe in the FTPSession.log file.

How to delete synchronized files from FTP server using Batch file [duplicate]

This question already has answers here:
psftp.exe get files from the server and delete
(3 answers)
Closed 4 years ago.
I was wondering if someone knows how to do what I'm looking to do.
For my server, I download files from an FTP server daily at 5AM. My batch script is pretty simple, it connects to the FTP server, downloads the files, processes them locally, and then deletes the processed files from the local directory, but I am unable to figure out how to get the batch file to purge only the downloaded files from the server.
Here is the code I'm currently using (edited for privacy)
C:
cd "C:\targetfolder"
rem psftp -b download.cmd -i priv(second).ppk -P 2223 xxx#yyy.ca
psftp -b download(second).cmd -i priv(second).ppk -P 2223 xxx#yyy.ca
rem psftp -b download.cmd -i priv.ppk xxx#yyy.ca
psftp -b download.cmd -i priv.ppk -P 2223 xxx#yyy.ca
rename *.xxx *.xxx
del done*.*
So the script as it is successfully is run every morning and downloads my new files. Are there some line(s) of code I'm missing that will simply delete the downloaded files only?
I also want to mention that I cannot install any new software on my FTP server to manage the files, so it has to be processed in my batch code here.
Thank you in advance for any help you all may be able to provide!
EDIT1: Here is the script in the doanload.cmd
ls
cd target
ls
mget *
Solved, thanks to #MartinPrikryl.
I added "rm *" to the end of my cmd file and it's working nicely, even though it doesn't differentiate from downloaded and non-downloaded files, it does what I need.
Thanks #MartinPrikryl!

Resources