Batch file to create other batch files

January 31, 2011 at 17:58:35
Specs: Windows XP, 2G
I am not good in batch files. so i am posting for a help.
I have to run pings and traceroutes in a remote workstation and the result will be sent to an ftp server. I already have the script that will do the pings and traceroutes, and also the script that is going to copy the output txt file to an ftp server.
Dilemma? I only need one batch file named INSTALL.BAT to do these:
1. create a folder with the folder name being asked – DONE, seen this post in the internet and it is working fine
@echo off
cd\
set dirname=
:input
set /P dirname=Type directory name: %=%
if "%dirname%"=="" goto input
mkdir "%dirname%"
cd "%dirname%"
2. create a pingtracert.bat with an output .txt file going to the folder that was created in number 1
already have that as that is easy when in a separate script, but getting it to the main INSTALL.BAT is driving me crazy. this script will be run every hour so i put a timestamp to separate th results inside the txt file.
echo %date% %time% >> File.txt
ping 10.1.1.100 >> File.txt
ping 10.1.1.200 >> File.txt
3. create an ftp.bat that will copy the .txt file to an ftp server.
I saw one in the internet an it works fine, and it is below
SET Server=10.1.1.300
SET UserName=FTP1
SET Password=ftpserver1
SET Commands="%TEMP%\SendToFTP_commands.txt"
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%
ECHO Prompt
ECHO mput *.txt >> %Commands%
ECHO close >> %Commands%
ECHO bye >> %Commands%
FTP -d -i -s:%Commands% %Server%
REM Clean up.
IF EXIST %Commands% DEL %Commands%
ENDLOCAL
4. i need those two batch files (pingtracert.bat & ftp.bat) that were created from the INSTALL.BAT to put it in windows scheduler in which the pingtracert.bat will run every hour from 6AM to 9PM,and the ftp.bat will run only at 10PM.

I already have those scripts, pingtracert.bat and ftp.bat but they are separated. I also don’t have the .bat the will schedule both scripts on windows task scheduler. What I need is to put all scripts in just one script that I will call INSTALL.BAT.
Any idea will be appreciated. Thanks.


See More: Batch file to create other batch files

Report •


#1
February 1, 2011 at 15:11:01

:: Batfile #1
@echo off
cd\
set dirname=
:input
set /P dirname=Type directory name: %=%
if "%dirname%"=="" goto input
mkdir "%dirname%"
cd "%dirname%"
type %0 | find /i " " | find /v "Notme" >ftp_.bat
type %0 | find /i "file.txt" | find /v "Notme" >pingtracert.bat

goto :EOF


:: 2. create a pingtracert.bat with an output .txt file going to the folder that was created in number 1
:: already have that as that is easy when in a separate script, but getting it to the main INSTALL.BAT is driving me crazy. this script will be run every hour so i put a timestamp to separate th results inside the txt file.
echo %date% %time% >> File.txt
Ping 10.1.1.100 >> File.txt
ping 10.1.1.200 >> File.txt


:: 3. create an ftp.bat that will copy the .txt file to an ftp server.
:: I saw one in the internet an it works fine, and it is below

SET Server=10.1.1.300
SET UserName=FTP1
SET Password=ftpserver1
SET Commands="%TEMP%\SendToFTP_commands.txt"
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%
ECHO Prompt
ECHO mput *.txt >> %Commands%
ECHO close >> %Commands%
ECHO bye >> %Commands%
FTP -d -i -s:%Commands% %Server%
REM Clean up.
IF EXIST %Commands% DEL %Commands%
ENDLOCAL



Above should do everything you wanted expect creating a windows scheduled task .
Make sure to include all spaces as they are...

After this line ":: I saw one in the internet an it works fine, and it is below" there are
5 space each line..

I dont think windows task scheduler command "AT" gives an option to scheulde a task each few hrs...on which OS you would like to run this script ? XP or Win7 ?

Subhash Chandra.
www.s-chandra.co.cc


Report •

#2
February 1, 2011 at 15:16:32
seems space before each line is removed when i hit submit.

Please add 5 space before each line for FTP.bat.

Use ftp_.bat instead of ftp.bat.. otherwise It will cause issues like infinite loop.

Someone can help suggestating how to add a task as per his requirements into scheudler ?

If no way then last option can be like the batch file will scheulde a task for next day and on next day it will create another task automaticly...

Subhash Chandra.
www.s-chandra.co.cc


Report •

#3
February 1, 2011 at 18:37:27
Hi.

Thank you for this. I am running on Windows XP.


Report •

Related Solutions

#4
February 2, 2011 at 10:28:28
You welcome .
I m still not sure how to scheudle the task in task scheduler.

MU , Ace , Roger can you help ?

Subhash Chandra.
www.s-chandra.co.cc


Report •

#5
February 3, 2011 at 17:13:56
Hi

I am already done with the items 1,2,3. Thanks for the info you gave Subhash. I am still researching for Item 4 wherein this concerns windows task scheduler.

oj


Report •


Ask Question