Below is the snip of a Batch script scheduled for daily execution via Window's task scheduler. However, the time interval option isn't available in the scheduler.
echo open <hostname> >tmp.txt
echo <username> >>tmp.txt
echo <password> >>tmp.txt
:: Some Work
echo quit>>tmp.txt
ftp -i -s:tmp.txt
Need some guidance on making the script run between 5AM-10PM, every 30mins, using batch commands.
Related
How do i execute these two commands in CMD at a scheduled clock time(as 10:53 PM)?
CD desktop
ffmpeg -i "https://X/index.m3u8" -rw_timeout 50000000 output.mp4
First, put all your commands in a single batch file.
Then, create a scheduled task for running it.
Type SCHTASKS /Create /? in command prompt for details about creating it.
At creation, you will probably want to specify either /SC ONCE for a one-time task, or /SC DAILY if you need it everyday.
I have a script that contains a call to winrs in order to remotely start the execution of a .exe on a user specified target machine.
I want the following functionality:
start script
prompt user for name of target PC
winrs into target PC executing the .exe and tell user who ran the script that this is being done.
stop the execution of winrs and tell the user who ran the script that it has finished.
exit.
I want all the output on the machine that the script was run on and don't want any show of activity on the target machine.
The code I have is as follows:
#echo off
echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect=
echo Attempting to contact Agent.
call winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
echo Agent reconnected. Please allow ~5mins for your management console to update.
The code executes until the winrs call, and it does infact execute the .exe on the target machine, but it seems then that the remote shell just stays open doing nothing after this.
If I push ctrl+c at this point "Terminate the shell? (y/n)" gets placed in my logfile, (but no output in the cmd prompt) and I can then push "y" and enter, upon which the remote shell exits and "Terminate batch job (Y/N)" appears in the cmd prompt, however the last echo statement never executes.
How can I get the remote shell to automatically close after the .exe has been run, and echo some sort of confirmation that the script has completed on the prompt of whoever has executed it?
All help appreciated!
You are using call which executes a new cmd.exe window and running winrs in that new window and exiting.
Remove it and it will work. I added pause at the end, in case you are running batch by double clicking it.
#echo off
echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect=
echo Attempting to contact Agent.
winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
echo Agent reconnected. Please allow ~5mins for your management console to update.
pause
EDIT
After some analysis it seems that the batch is waiting for the program to finish, so it would be possible to just call it with start which should call it and return to the original prompt.
start winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
I have a task scheduled to run daily that executes a .bat file and I have checked the options for ending the task after an hour and forcing it to stop if it does not end when requested to, but it runs indefinitely until I manually kill it. Any ideas? (I do not want to use pskill in my script). Script below:
sqlcmd -S MyServer -U username -P password _Q "BACKUP DATABASE x to y"
net use z: "\\server1\project"
cd C:\trial1
copy * "Z:\backups"
net use z: /delete
exit
Thanks to Hans Passant for the answer! See below:
Taking away 'net use' and just directly copying to the server cleared up some error that the task scheduler was getting stuck on.
I have this batch script:
C:\{Directory}\PsExec.exe -u {UserName} -p {Password} \\{IP_Address} /accepteula "C:\batchfiles\{BatchScript}.bat"
And the {BatchScript}.bat script is:
C:\{Directory}\infacmd.bat wfs startWorkflow -DomainName {Domain_Name} -ServiceName {Service_Name} -UserName {Username} -Password {Password} -Application {Application} -Workflow {Workflow} -wait
This script kicks off an Informatica process to build a data warehouse (not sure if that's important, but thought I would mention it). When I run the first batch script, it kicks off the second batch script. However, it seems like command prompt waits for Informatica to be finished before it exits. My issue is that I have other processes that need to run, and this process takes 5 hours currently. Is there a command I can add on to my second (or first) script that will exit command prompt immediately after it kicks off? I don't believe this will impact the data warehouse build since I don't need Windows to monitor the process.
start "windowtitle" C:\...whatever...\infacmd.bat w....
should do what you want...
I have batch script stated below and I run it on Task scheduler (Windows 2008 R2). When it runs, the status of the task is still running and takes too long. I couldn't see any errors or even in history or any logs. I already set the correct owner and permission of the locations in windows. Any one can shed me some lights? Thanks!
SETLOCAL
SET CWRSYNCHOME=C:\scripts\CWRSYNC
SET CYGWIN=nontsec
SET HOME=%HOMEDRIVE%%HOMEPATH%
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%
rsync -rltDuv --progress -e "ssh -i /cygdrive/c/scripts/id_rsa" /cygdrive/c/backup/ root#123.123.123.123:/path/to/backup/ > c:/scripts/logs.txt 2>&1