Monday, 22 June 2020

1--- BATCH SCRIPT PROGRAMMING 2020 - PAGE 01





PAGE01 :- 

WHY WE HAVE TO USE BATFILE IN 2020

๐Ÿ’      ๐Ÿ’      ๐Ÿ’      ๐Ÿ’

A batch file contains a series  sequence of commands that runs when you open it. Is commonly written in notepad.exe. Busing Batch syntex and Dos Comands.

Why we need Batch File programmes in  the year 2020??

Say you need to execute a set of commands over and over again to perform a routine task like
Backing Up files from one directory to another, Moving Files, Renaming Files, Ziping files, Unziping Files, Deleting Old FIles, Deleting Five day old files, To make this Task  automatic  we Need Batch files.

I do not want to keep my learnings to myself, so deside, to creat BLOG of  batch tutorial  and adding few more learnings to IT people, which may benefit many other software student and developers working in this lovely industry. 

I worked for Dos commands Many years starting from 1984 onwards. I wrote more than 500 batch file, script files, in my service.

Who can write bat file - who knows computer knowledge, can write batch programmes in  short time.

UNDERSTANDING THE TOOL FOR WRITING BAT-FILE:-
  1. NOTEPAD.EXE
  2. CMD.EXE - DOS PROMPT 
  3. DOS COMMANDS 
  4. BATCH SYNTEX
1)

notepad.exe
or
notepad++
or
edit.exe

Use always Notepad.exe, 
Notepad is Non Document - ASCII file editor.  
How to get notepad -- Go to "start" in windows  type cmd.exe and noepad.exe
   or goto windows-start, type notepad.exe

2)

CMD.EXE
How to get cmd.exe or Command Promot, or Dos Prompt.
Goto to "start" in window Type cmd.exe

c:\ windows\system32\ - this directory will appear in dos-prompt. or c:\

 
3) 

DOS COMMANDS
How to get DOS COMMANDS goto start-in-window type cmd.exeType :- help
example c:\windows\system32\help You will get around 86 Dos Commands.

4) 

BATCH SYNTEX and Dos commands :-
Batch Script always used with Dos Commands. Some of the Batch Syntax samples are given below.


Batch script syntax and description:-

 @echo off  ............  display off  - do not display command processing
 @echo on ............. display on  - display all command processing
 echo  display text  - one line
 rem
  Do not display - one line 
 ::   Do not display  - one line
 if not exist  performs conditional processing eg- if not
goto  Next level
 if error level 1  any error levelprocessing in the programme
goto Next level
 for and do  Runs a specified command for each file, within
 a set of files.

 cd ............   goto directory                    
 cd..   remove one directory      
 cd\   goto root directory 
 md   make new director
 rd   remove directory
 | pipe sign   Pipe sign syn

 if exist ............  Performs conditional processing in batch program  
 if  Performs conditional processing in batch program
 goto  goto loop,  next processing
  if not exist 
 error  goto Next level
 if error level 1
 error goto Next level
 %1 -%9  passing variable  while running batch file in dos prompt   
 %%  variable used with if condition
      >  This syntax used to store  batchfile sc to file test.txt 
     >>  This syntax used to store batchfile screen
output to a file test.txt  

IMPORTENT  DOS COMMANDS:-

BILL Gates reached out to Paterson and purchased 86-DOS from him, allegedly for $50,000. Microsoft turned it into MS-DOS,
which they introduced on this day in 1981. 

Microsoft came first, in the world, OS with Windows 95 on August 24, 1995,Mac OS 8 on July 26, 1997.

MS DOS COMMANDS  :-

ASSOC          Displays or modifies file extension associations.
ATTRIB          Displays or changes file attributes.
BREAK          Sets or clears extended CTRL+C checking.
BCDEDIT      Sets properties in boot database to control boot loading.
CACLS          Displays or modifies access control lists (ACLs) of files.
CALL              Calls one batch program from another.
CD            Displays the name of or changes the current directory.
CHCP              Displays or sets the active code page number.
CHDIR          Displays the name of or changes the current directory.
CHKDSK        Checks a disk and displays a status report.
CHKNTFS      Displays or modifies the checking of disk at boot time.
CLS            Clears the screen.
CMD            Starts a new instance of the Windows command interpreter.
COLOR        Sets the default console foreground and background colors.
COMP            Compares the contents of two files or sets of files.
COMPACT      Displays or alters the compression of files on NTFS partitions.
CONVERT      Converts FAT volumes to NTFS. You cannot convert the
                current drive.
COPY      Copies one or more files to another location.
DATE        Displays or sets the date.
DEL          Deletes one or more files.
DIR          Displays a list of files and subdirectories in a directory.
DISKCOMP      Compares the contents of two floppy disks.
DISKCOPY      Copies the contents of one floppy disk to another.
DISKPART        Displays or configures Disk Partition properties.
DOSKEY          Edits command lines, recalls Windows commands, and 
creates macros.
DRIVERQUERY    Displays current device driver status and properties.
ECHO            Displays messages, or turns command echoing on or off.
ENDLOCAL      Ends localization of environment changes in a batch file.
ERASE      Deletes one or more files.
EXIT          Quits the CMD.EXE program (command interpreter).
FC              Compares two files or sets of files, and displays the 
differences between them.
FIND          Searches for a text string in a file or files.
FINDSTR      Searches for strings in files.
FOR            Runs a specified command for each file in a set of files.
FORMAT      Formats a disk for use with Windows.
FSUTIL        Displays or configures the file system properties.
FTYPE          Displays or modifies file types used in file extension 
associations.
GOTO          Directs the Windows command interpreter to a labeled line in 
a batch program.
GPRESULT      Displays Group Policy information for machine or user.
GRAFTABL      Enables Windows to display an extended character set in 
graphics mode.
HELP          Provides Help information for Windows commands.
ICACLS      Display, modify, backup, or restore ACLs for files and 
directories.
IF                    Performs conditional processing in batch programs.
LABEL      Creates, changes, or deletes the volume label of a disk.
MD            Creates a directory.
MKDIR      Creates a directory.
MKLINK    Creates Symbolic Links and Hard Links
MODE      Configures a system device.
MORE      Displays output one screen at a time.
MOVE      Moves one or more files from one directory to another 
directory.
OPENFILES      Displays files opened by remote users for a file share.
PATH            Displays or sets a search path for executable files.
PAUSE        Suspends processing of a batch file and displays a message.
POPD          Restores the previous value of the current directory saved by 
PUSHD.
PRINT           Prints a text file.
PROMPT      Changes the Windows command prompt.
PUSHD          Saves the current directory then changes it.
RD            Removes a directory.
RECOVER    Recovers readable information from a bad or defective disk.
REM      Records comments (remarks) in batch files or CONFIG.SYS.
REN      Renames a file or files.
RENAME        Renames a file or files.
REPLACE      Replaces files.
RMDIR           Removes a directory.
ROBOCOPY      Advanced utility to copy files and directory trees
SET            Displays, sets, or removes Windows environment variables.
SETLOCAL      Begins localization of environment changes in a batch file.
SC              Displays or configures services (background processes).
SCHTASKS      Schedules commands and programs to run on a computer.
SHIFT      Shifts the position of replaceable parameters in batch files.
SHUTDOWN      Allows proper local or remote shutdown of machine.
SORT        Sorts input.
START      Starts a separate window to run a specified program or command.
SUBST      Associates a path with a drive letter.
SYSTEMINFO      Displays machine specific properties and configuration.
TASKLIST      Displays all currently running tasks including services.
TASKKILL      Kill or stop a running process or application.
TIME        Displays or sets the system time.
TITLE      Sets the window title for a CMD.EXE session.
TREE      Graphically displays the directory structure of a drive or 
PATH               Dos commands search directory path, to execute programme
TYPE      Displays the contents of a text file.
VER        Displays the Windows version.
VERIFY      Tells Windows whether to verify that your files are written
        correctly to a disk.
VOL            Displays a disk volume label and serial number.
XCOPY      Copies files and directory trees.
WMIC        Displays WMI information inside interactive command shell.

Note 1:-  TO get above help menu type cmd.exe in search window  
type the following syntax  - help -

 c:\windows\system32\   help  

or

help   >   test.txt. 

Open test.txt in  notepad 


Note 2:- For more parameters detailed description.

c:\windows\system32\xcopy/?


For Detaile Description and example Microsoft 
Dos commands  link given below: 

-----------------------------------------------------------------------------------------------
COPY CON COMMAND:- 

(This command can be used when notepad.exe not available in computer)
A Simple bat-file writing without using Notepad.exe :- 
COPY CON example given below. Do not use this command, just for information.  Use always notepad.exe :- 

TYPE copy con in DOS-PROMPT

copy con test.bat 
cls
pause

CONTROL Z 

will save  filename test.bat in the same directory.

Run programme test.bat   -- 
this will clear the screen
------------------------------------------------------------------------------------

IMPORTENT POINT TO REMEMBER, WRITING BAT FILE.

Creating batch commands keep file name within 8 character, and bat  or .cmd for windows 2000  eg. test.bat or eg. test.cmd

While creating a batch file, keep in mind  that do not use Dos command file name 
eg. xcopy.exe   using same file name xcopy.bat not allowed.

Use always lowercase letter or small letters for writing programmes.

After completing batch file in notepad select goto file select "save as"   select "o not use control "S" for saving.

If any space in directory use quotes writing programmes c:\"windows test directory".

Always use full directory path eg. c:\main\del *.txt  inside  batch files. Otherwise it deletes all files
in unknown directory. Careful while using "del" command.

 
  Important message to run batch files in computer:-

  Applies to: Windows -- Windows Server 2019, Windows   2016, Windows 2012 .



My First Programme 

 Syntax  
  
 cls   ::

Description:-
 
Clear screen

To view all  parameters type      c:\windows\system32\cls/?

Examples:-

c:\main\cls

Sample programme 1 :-

@echo off
:: clear screen - give file name s.bat in notepad.exe

cls

pause
exit

Sample programme 2 :-

@echo off
::  Here Two colan indicates do not execute this line,
::  Open notepad give give file name scls.bat

cls

Echo Welcome to Batch script language programming.
:: clear screen and display above message
pause
exit /b

More Parameters and detail description goto c:\windows\system32\cls/?
Note:- type  backward slash  cls/?

----------------------------- 




 Syntax  
   DIR

Description:-

Displays list of files and subdirectories in a directory.

To view all parameters type c:\windows\system32\dir/?

Examples:-

dir [<drive>:][<path>][<filename>]

dir c:\main\*.* 

example c:\main\dir *.*

or 

dir c:\main\*.*

Sample programme :-

@ECHO OFF
:: give file name dir1.bat 
rem do not give filename more 8 character.
rem do not give filename like copy, move, delete, timeout, etc.,  etc., these are dos-commands.

dir c:\main\*.*

pause

dir c:\workarea\*.bat

pause

:: Put  quotes if space in a directory.

dir c:\"personal files"\world*.*

pause
:end

More Parameters and detail description goto c:\windows\system32\dir/?

-----------------------

 Syntax 
       >   >>
  
How to store all-file-names in a directory???

How to backup multiple directory file names (only file names inside the directory)  everyday?
  

Description:-

Output redirection command. Stores list of file-name of subdirectories and directory. 

>    Create New file name every time and write output text.

>> Append output to Given filename. Write text to filename  one by one.

Examples:-  

Type following command in Dos Prompt without batch file.

dir c:\bat\*.txt        or    c:\bat\dir *.txt

or
  1. c:\main\dir *.* > c:\main\dirlist1.txt   All listing of files stored in dirlist11.txt, instead of displayig in computer screen. 
  2. c:\main\dir *.exe > c:\main\dirlist2.txt  All *.exe file name stored in dirlist2.txt
  3. c:\main\dir *.* >> c:\main\dirlist3.txt Append or stores directory files below  to previous output.
  4. USES:-  backing up all directory file names.
Sample programme 1 :-

@ECHO OFF 
:: create file name and storing output to dirlist1.txt
:: you have to create file name dirlist1.txt by using notepad,  before running this bat file.

c:\main\dir *.* >> c:\main\dirlist1.txt
c:\main\dir *.* >> c:\main\dirlist1.txt
c:\main\dir *.* >> c:\main\dirlist1.txt
c:\main\dir *.* >> c:\main\dirlist1.txt

exit

Sample programme 2:-

This programme will create automaticaly-new file name and stores content of directory,
Every time you run this will create NEW file and store the content of file names to dirlist2.txt.
Old file will be deleted. ( To avoid of deleting use >> to append file names one-by-one )

@ECHO OFF
:: Store directory file listing to dirlist2.txt. dirlist2.txt file name will create automaticaly.

c:\main\dir *.* > c:\main\dirlist.txt

   exit
-----------------------

How to set Timmer in Batch file ?
How to shutdown computer after 3 hours ?? 

 Syntax   
   timeout   goto  :start  \t   /s

Description:-

This timeout command useful for pausing batch file,  number of seconds

Examples:-

timeout /t 100

Pause programme for 100 seconds. /t back slash t

Sample programme 1 :-

How to find statistic of internet data line for one-hour.

@echo off
:: create file name shut.bat 
rem do not give filename more 8 character.
rem do not give filename like copy, move, delete, timeout, etc etc these are dos-commands.

timeout  \t  300
:: pause batfile runing in 300 seconds

shutdown  /s \t300
:: shutdown computer after conting 300 seconds

exit

Sample programme 2 :-

@echo off
:: create file name record.bat 
::record directory listing every 5 minutes
:start

dir c:\bat\*.*    >>   c:\bat\dirlist1.txt

timeout  \t  300
:: 300 equal to 5 minutes 

goto start

exit
-----------------------

How to use Echo-On Echo-Off  in a batch file ??

 Syntax    
 @echo  @echo off   @echo on  

Description :-

echo     -     Displays  message

@echo off   -    do not display messages 

 @echo on   -    Display messages till end of programmes

To view more  parameters type     c:\windows\system32\echo/?

Examples:-

@echo "this is a test message"   -- one time display message
@echo off    dissable screen display text
@echo  on 

Sample programme:-

@ECHO off 
:: give file name viewdir.bat 
dir c:\main\*.*
pause
@ECHO on
dir c:\workarea\*.*
pause
@ECHO "if directory have space put it in quotes"
dir c:\"personal files"\*.*
pause
@ECHO "Programme over"
:end

More Parameters and detail description goto c:\windows\system32\echo/?
-----------------------

How to shutdown computer after 3 hours ?? 

 Syntax 
 shutdown    /t

Description:-

Shutdown the computer

Examples:- 

C:\windows\system32\shutdown     /t   30
Shutdown computer in 30 seconds. put back slash  /t  30

Sample programme:-

@echo off
:: give file name shut1.bat 
:: SHUTDOWN COMPUTER 

shutdown   /t  300

:: shutdown computer in 300 seconds i.e. 5 mnts
:end

More Parameters and detail description goto c:\windows\system32\shutdown/?

-----------------------

 Shortcut
 Shuting down computer in one click   
 
How to make Shortcut for programmes and Batch files.

goto desktop-screen, 
place cursor on screen 
rightclick

select  -new- and 
select - shortcut - 
give  filename and path of the programme and give extension that is *.exe or *.bat is very importent.

eg. c:\windows\system32\shutdown.exe  /t 10

-----------------------

How to add Path to existing Windows Path:-

 Syntax  
 path 

Description:-

NOTE:-  before running Batch-programe, store the original path of your computer
by using following command . 


path >> c:\main\bat\path1.txt   

(storing original path of your computer text file called "path1.txt" )

Note:- Running prg that tells the path  which directories to search for executable files in response to commands issued by a user.

Examples parameter:- 

type path in cmd.exe window. This will display ...

path=c:\windows\system32;

to add any new directory path example this directory = c:\main\bat; adding to existing path to c:\windows\system32; 

type the following command in Dos Prompt.

set path=%path%;c:\main\bat

Now type "path" and check, c:\main\bat added to main path.

path=c:\windows\system32;c:\main\bat;

NOTE:- More Parameters and detail description goto c:\windows\system32\path/?

-----------------------

How to make Multiple directory ?
How to remove Multiple directory ?

 Syntax    
 md    %1       end      goto       if

Description:-

md  -- Create new directory

%1 -- passing command line argument or variable

end  -- used in goto   and :end

Examples:- 

C:\md bat       c:\cd bat          c:\bat

c:\md workarea    c:\cd workarea   c:\workarea

Sample programme:-

Create directory for:- month, date, directory
31 days directory can be created in one shot bye Bat file.
Long

eg. c:\workarea\January\01

Example 1:-

@ECHO OFF
:: give file name m1.bat in notepad.exe
c:\md Main
c:\cd main
c:\main\md January
c:\main\cd january

c:\main\january\md 01
c:\main\january\md 02
c:\main\january\md 03
c:\main\january\md 04 

 :: like this upto 31 days
:end

or

Examble  2 :- 

creating directory by typing directory name in the dos prompt 

@ECHO OFF 
:: give file name m2.bat in notepad.exe

if "%1" "" goto month   
:: if %1 input not equal go to end
c:\md main
c:\cd main
c:\main\ md %1
c:\main\%1\md 01
c:\main\%1\md 02
c:\main\%1\md 03
c:\main\%1\md 04   

:: repeat  upto 31 days
:month
:: Type month  January or February or March etc
:end

More Parameters and detail description goto c:\windows\system32\md/?

Example:-
How to run  this file: keep all bat file in c:\bat

c:\bat\m2.bat january 
c:\bat\m2.bat february

or

c:\bat\m2.bat "january   01"   :: space between directory put it in quotes.
c:\bat\m2.bat "january   02"
c:\bat\m2.bat "january   03"
-----------------------
How to remove directory

 Syntax       or
 rd
 rmdir  

Description:-

Delete a  directory   or  remove directory, 

Examples:- 

rd [<Drive>:]<Path> [/s [/q]

rmdir [<Drive>:]<Path> [/s [/q]]

or 

rd c:\main\january\01
remove date 01
or

c:\main\january\rd 01

Sample programme:-

We have created 12 month directory and 31 date directory
how to delete these diretory in one shot.

Long method of deleting directory 
eg. c:\main\January\01

First remove date -directory and then month directory

Example 1:- 

@ECHO OFF :: give file name m1.bat in notepad.exe
c:\cd main\january   
:: go to january directory

c:\main\january

c:\main\january\rd 01
c:\main\january\rd 02
c:\main\january\rd 03
c:\main\january\rd 04  
 
:: like this upto 31 days
:end

or

Example 2:- 

creating bat file by
 passing argument in Dos-prompt   

@ECHO OFF 
:: give file name m3.bat in notepad.exe It removes directory after January month

if "%1"=="" goto   month

c:\cd main\%1   :: go to january directory
c:\main\%1
pause  ::Check %1 replaced by month correct or not
c:\main\%1\rd 01
c:\main\%1\rd 02
c:\main\%1\rd 03
c:\main\%1\rd 04   :: like this upto 31 days
:month
:: Type month  January or February or March etc
:end


Example 3 :-

Example 2:- Easy way of writing above bat-file passing argument in Dos-prompt 

@ECHO OFF :: give file name m4.bat in notepad.exe
if "%1" ==  "" goto  month1  :: month1 should be with in 8 character
if "%2" ==  "" goto  date1
c:\cd main                  :: go to january directory

c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2
c:\main\%1\rd %2   :: like this upto 31 days

:mon
:: Type month  January or February or March etc
goto end  
:: this command to avoid message displaying date message
:date1
::Type date 1, 2, 3, 4, 5,6,etc
:end


Example:

c:\bat\m4.bat january 01    or   c:\bat\m4.bat january 02

-----------------------
How to exit programme

 Syntax 
 exit     /b

Description:-

close cmd.exe, close dos window

Examples:- 

exit from batch programme and close dosprompt

Sample programme:-

@echo off
;; exit from running of programming or close dos prompt
echo welcome message will appear
exit
echo This wecome 2 message will not appear. 
echo This wecome 2 message will not appear.

More Parameters and detail description goto c:\windows\system32\shutdown/?
-----------------------

How backup all your files, using Xcopy command?

 Syntax   
  
xcopy copy 

Description:-

Copies files and directories Including Subdirectory

To view all  parameters type      c:\windows\system32\xcopy/?

Examples:-

xcopy c:\main\*.* c:\bat

Sample programme 1:-

@ECHO OFF
:: copy all files from different directory to c:\backup

xcopy /s c:\main1\*.* c:\bat
xcopy /s c:\main2\*.txt c:\backup
xcopy /s c:\main3\*.jpg c:\backup
xcopy /s c:\main4\*.exe c:\backup
xcopy /s c:\main5\*.txt c:\backup

cls

:end

Sample programme 2:-

Note:


@echo off

if "%1" ==  "" goto msg
if "%1" ==  "" goto  msg

xcopy %1 %2 /s /e

if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit
:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit

:msg
Type    from directory c:\main1\*.* to backup c:\backup

pause



Sample programme 3:-


echo y| xcopy c\main\*.doc     c:\backup\doc
echo y| xcopy c\main\*.jpg     c:\backup\image
echo y| xcopy c\main\*.txt      c:\backup\text

Note:- 
copy all DOC , JPG, Text file to c:\main\doc directory without prompting Yes or no .

NOTE:- after Y and PIPE sign in keyboard shift backslash.

-----------------------
How to run multiple bat file or exe file inside the batch file.

 Syntax  
 
 call

Description:-

Running another Batch file inside the programme 
No effect on Command Prompt. Use it inside Batch file.

Examples:-

call c:\main\test1.bat

Sample programme 1:-

@echo off
call f:\workarea\clrscreen.bat
call c:\main\test1.bat
call c:\main\test2.bat
call c:\main\test3.bat
call c:\main\test4.bat
:: calling another batfile to perform function.
:end

-----------------------

How to open Multiple App 

 Syntax  
 
 start

Description:-

To run specified Programme inside the batch file 
eg. Notepad.exe or word.exe or photoshop.exe 
or all executable files.

Examples:-

notepad.exe
google.com
gmail.com
chrome.exe open all windows in one shot

Sample programme 1:-

@echo off

start c:\main\notepad.exe
start c:\main\google.com
start c:\main\gmail.com
start c:\main\chrome.exe
start c:\main\ieexplore.exe

:: Opening all programmes in one shot

:end
-----------------------


 Syntax
 
 doskey  

Description:-

Recall windows command, in dos prompt, 
use up arrow and down arrow.

All commands in dosprompt are stored in memory.

Display more help at dos prompt   doskey/?

----------------------- 



How to transfer files to remote computer:- 

ftp Batch Script Programmes
With Examples:-

NO SOFTWARE INSTALLATION REQUIRED TO TRANSFER FILE FROM YOUR COMPUTER TO REMOTE COMPUTER

 Syntax  
 
 ftp

Description:-

Transfering file To remote computer 

More Parameters and detail description goto c:\windows\system32\ftp/?

Note:- 

Type FTP in dosprompt, it will go to FTP-mode,There you can use ftp commands. You can return to the command prompt by typing the quit command. 
Instead c:\ promt it will show  ftp > command prompt. 

Examples:-

ftp Applies to window server 2012, 2015, 2019

Sample programme:-

Basic Syntax

ftp
open 10.130.100.100.100
userid
password

mget
or
mput


Note :- mget down file, mput - upload file. to get help type ftp and then help:
ls, dir, disconnect, delete, mdelete, mdir, open, quit, rmdir, send trace type etc etc.

HOW TO -- GET -- ALL FILES FROM OTHER COMPUTYER.

1 - FIRST BATCH FILE

@ECHO OFF
:: fILE  file name ftpone.bat  

::  This is combination two set of batch file 

C:\bat

ftp -s:c:\main\bat\mega\ftptwo.txt

quit


2 - SECOND  ONE IS TEXT FILE -

FTPTWO.TXT  INSIDE FILE PUT  IP address, USER ID AND PASSWORD


C:\
cd\main

open 10.130.7.37 
userid
password

cd /
cd MAIN

dir * 

mget *.*

bye

NOTE:-   bye  command is quiting the prg.   cd / bacward slash


---------------------------

Download FTP software:-

Some more examples using External software for FTP:

1   Two useful external FTP software to download or upload in Dosprompt without any installation of software:    EXE file name

      1 - ncftpget.exe

      and

      2 - ncftpput.exe 

No software instalation required for these two Exe file. Easy to use In Dos Prompt.

2   FAMOUS FTP software for windows, file uploading and downloading to remote PC. 
External Link given below.



How to use ncftpput.exe or ncftpget.exe  without writing batch file.
Single line command for FTP.

ncftpget -u test -p link 10.130.7.37 c:\ \remoteserverdirectory\*.*

- u is User ID, -p is password, 10.130.7.37 is IP address,  c:\ \remoteserverdirectory\*.* is remote directory with all files to download.

ncftpput -u anonymous -p anonymous -t35 -DD 10.110.81.2 \ e:\250mb_ril_bsnl*.*

ncftpget -u opi -p link -t35  -DD 10.110.81.2   \\tdatasrv\tdata\NEWS\main\reg\    \USA\recd\*.*

\\tdatasrv\tdata\NEWS\main\reg\ -- Local directory,   \USA\recd\*.*  remove directory
no username and no password is Anonymous

Sample Batch file for FTP Programe inside Batch file
ncftpput.exe or ncftpget.exe  no software installation is necessary for FTP ( not dos command) :

1)    ncftpget -u test -p link 10.130.7.37 c:\ \remoteserverdirectory\*.*
:: remote IP address and -u- for userid -p- for password

2)   ncftpput -u opi -p link 10.130.7.37 \thanthi\2006\jul c:\*.pdf
::-u is userid   -p   is password

---------------------------


 
Important message to run batch files in computer:-
 Applies to: Windows Server 2019, Windows Server      2016, Windows Server 2012 



How to get IP-ADDDRESS of Computer:- 

 Syntax 
  
 ipconfig   

Description:-

Network troubleshooting makes much easiere IPCONFIG.
Displays all current TCP/IP network configuration values

current network adapter connection including:
Current IP Address
Subnet Mask
Default Gateway IP
Current domain

Examples:-

ipconfig /all                

Sample programme:-

ipconfig /all  

More Parameters and detail description goto c:\windows\system32\ipconfig/?

---------------------------

HOW TO FIND MULTIPLE DATA LINE
 DOWN OR NOT, USING BATCH FILE:-

 Syntax    
 loop if
 ping find

To view all  parameters type      c:\windows\system32\ping/?

Useful Batch file for windows user 2020. to find INTERNET down or NOT

HOW TO FIND 50 or MORE Data lines Up or Down using this Batch File.
Bank Office
IT industries
Factories can use this batch file Instead of spending more money on software.

I used this PING command Many years in our office to find 50 Data lines dead or alive.
if data line dead automaticaly batch file open notepad.exe to indicating Line is down.
open notepad and check which line is down.

Description:-

PING command continue sending echo Request messages to the destination until interrupted.
To interrupt and display statistics, press CTRL+break. To interrupt and quit ping, press CTRL+

Examples:-

ping google.com /t

OR

PING  8.8.8.8   /t
(Google dns IP addresses 8.8.8.8)

Sample programme 1 :- tested ok

Down data msg uploaded to status-d.txt file .
UP message msg uploaded to  status-u.txt.

@echo off
:: creat four  File name in c:\main
::status.bat  -- batch file name
::status1.txt 
::status2.txt

set dated=%date:~-4%_%date:~3,2%_%date:~0,2%
set timet=%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %dated%
echo %timet%

:start
timeout.exe 300
::pause the batch file upto 5 mnts

c:
cd\main  

del  c:\main\status1.txt
::delete status1.txt evertime automatic
ping google.com > c:\main\status1.txt
find /I "ttl" c:\main\status1.txt 
if errorlevel 1 goto down1 
@echo  **-- Data line 1 is  UP **--  >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ---------------------- >> c:\MAIN\status2.txt
goto  line2
:down1
@echo  **-- Data line 1 is  down **  >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ---------------------------------------DOWN >> c:\MAIN\status2.txt
:line2 

goto start

::When you copy the file change directory according to you c:\main

HOW THE BATFILE WORKS:

When you ping "ttl" string will be displayed  in screen. Put these 
ping output-message   to text file eg. status1.txt. by using  >> (TWO greater than sign) .

Fined string "ttl" in "line0.txt" by using "find" doscommand. If "ttl" does not exist in status1.txt
put message to down.

NOTE:-

What is the difference between Ping and ipconfig:

Although ipconfig displays information, it can also be used to make basic configuration changes and reset certain facets of DHCP and DNS.
Ping is used to test connectivity to other hosts

Sample programme 2:- tested ok

TO find MULTIPLE Data line checkup down-status:-
Use full for IT companies, Bank offfices:-
@echo off
:: creat four  File name in c:\main
::status.bat  -- batch file name
::status1.txt 
::status2.txt

set dated=%date:~-4%_%date:~3,2%_%date:~0,2%
set timet=%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %dated%
echo %timet%

:start
timeout.exe 5
::pause the batch file upto 5 mnts

c:
cd\main  

del  c:\main\status1.txt
::delete status1.txt evertime automatic
ping google.com > c:\main\status1.txt
find /I "ttl" c:\main\status1.txt 
if errorlevel 1 goto down1 
@echo  **-- Data * google.com * is UP -- >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ---------------------- >> c:\MAIN\status2.txt
goto  line2
:down1
@echo  **-- Data * google.com * is  down --  >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ---------------------------------------DOWN >> c:\MAIN\status2.txt
:line2 

del  c:\main\status1.txt
::delete status1.txt evertime automatic

ping google.com > c:\main\status1.txt

find /I "ttl" c:\main\status1.txt 
if errorlevel 1 goto down2 
@echo  **-- Data * google.com * is  down -- **   >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ---------------------- >> c:\MAIN\status2.txt
goto  line3
:down2
@echo  --------**-- Data * google.com * is  down -- **------  >> c:\MAIN\status2.txt
echo %dated%  >> c:\MAIN\status2.txt
echo %timet%  >> c:\MAIN\status2.txt
echo ------------------------------------------- >> c:\MAIN\status2.txt
:line3
 ::change line 1 to line 2,  change down1 to down2
 ::change IP ping addres to second data line
goto start

NOTE :- More Parameters and detail description goto c:\windows\system32\ping/?

---------------------------


 Syntax 
  
    date

Description:-

Display current date

Examples:-

c:\date /t displays date prompting you for any change

Sample programme:-

SAMPLE BATFILE TO COPY TOMORROW DATED FILES, 
In this programme we can learn How to get Tomorrow Date.

@Echo off 
setlocal enableextensions disabledelayedexpansion

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" 
set "td.YY=%dt:~2,2%" 
set "td.YYYY=%dt:~0,4%"
set "td.MM=%dt:~4,2%"
set "td.DD=%dt:~6,2%"

rem Remove padding from date elements and increase day
set /a "y=%td.YYYY%", "m=100%td.MM% %% 100", "d=(100%td.DD% %% 100)+1" 
rem Calculate month length
set /a "ml=30+((m+m/8) %% 2)" & if %m% equ 2 set /a "ml=ml-2+(3-y %% 4)/3-(99-y %% 100)/99+(399-y %% 400)/399"
rem Adjust day / month / year for tomorrow date
if %d% gtr %ml% set /a "d=1", "m=(m %% 12)+1", "y+=(%m%/12)"

rem Pad date elements and set tomorrow variables
set /a "m+=100", "d+=100"

set "tm.YYYY=%y%"
set "tm.YY=%y:~-2%"
set "tm.MM=%m:~-2%"
set "tm.DD=%d:~-2%"

echo Today : %td.YYYY%/%td.MM%/%td.DD%
echo Tomorrow: %tm.DD%-%tm.MM%-%tm.YYYY%
set @pathVar = "c:/temp/%tm.DD%-%tm.MM%-%tm.YYYY%.cfg"
@Echo on
echo %@pathVar%

:: PUT YOUR SOURCE DIRECTORY
:: xcopy c:\temp\%tm.DD%-%tm.MM%-%tm.YYYY%*.* c:\temp\temp
:end

More Parameters and detail description goto c:\windows\system32\date/?

---------------------------

 Syntax    
  
    time

Description:-

Without any parameters it displays current time.

c:\time   

Display current time or to change time.
----------------------------------------------------------

How to compare two files

 Syntax   
  
 fc 

Description:-

Compares the contents of two files or sets of files byte-by-byte. 
These files can be stored on the same drive or on different drives, 
 If used without parameters, comp prompts you to enter the files to compare

To view all  parameters type      c:\windows\system32\cls/?
Examples:-
comp c:\bat\file1.txt f:\main\file2.bat

Compares two files or sets of files and displays the differences between them.
or
fc c:\bat\file1.txt f:\main\file2.bat

---------------------------
Continued to Page 02




No comments:

Post a Comment

HOW TO BACKUP YOUR ALL DIRECTORY IN YOUR COMPUTER AND FILE NAMES:-

HOW TO BACKUP YOUR ALL DIRECTORY IN YOUR COMPUTER AND FILE NAMES:-   Syntax         tree   /f Description:- Displays names of files in a dir...