Showing posts with label DOS Batch. Show all posts
Showing posts with label DOS Batch. Show all posts

Monday, April 02, 2012

Start multiple Putty sessions using DOS Batch file

 

There is a requirement for me open up multiple sessions of same HP Unix Host server. I just automate this using simple DOS Batch file below;

@echo off
set uname=siva
set pwd=#`F$(*&!-=~

start /max  C:\Windows\System32\putty.exe -load "D1- Session1" -l %uname% -pw %pwd%  
start /max  C:\Windows\System32\putty.exe -load "D1- Session2" -l %uname% -pw %pwd%
start /max  C:\Windows\System32\putty.exe -load "D1- Session3" -l %uname% -pw %pwd%  
start /max  C:\Windows\System32\putty.exe -load "D1- Session4" -l %uname% -pw %pwd%
start /max C:\Windows\System32\putty.exe –load  "D1–Session5" -l %uname% -pw %pwd%

@echo on

Monday, March 19, 2012

Quick way of getting Date and Time appended on filename in DOS Batch

 

echo off

set filename=F:\Sivaprasad\Error%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt

echo  %filename%

DOS Batch file To search string in given file

 

Requirement:

To Search the given files under current directory for given strings. If anything found to be written to a file.

Sample Screen:

image

 

Main Script: CHK_Error.bat

@echo off

set fname=
set filename=
set yyyymmdd=
set hhmm=

IF %1. NEQ . (set fname="C:\Accounts\CalWIN\Build\SQLServer\DOS_Batch\%1*.lst") ELSE ( GOTO _Usage )

for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set yyyymmdd=%%k%%i%%j

for /F "tokens=1-2 delims=: " %%l in ('time /t') do set hhmm=%%l%%m

set filename=Error_%yyyymmdd%%hhmm%.txt

echo "Error Log file name is : " %filename%

echo "files to be searched : " %fname%

findstr /i /n /g:search.txt  %fname% > %filename%

if %errorlevel% == 0 (GOTO :_Error_Found ) else  (
Echo  **  No Errors found    **
Goto :END )

:_Error_Found
notepad %filename%
Goto :END

:_Usage
echo " Usage is chkerrors.bat <filestring>

:END
@echo on

Search.txt

msg
error
severity
warning
fail
fatal

Input Files: file1.lst

dgadagdagad
abacdefghijklmnopqrstuvwxyzagadgda
gagad

st messgae
g

adgadg

agadgadgadadadsflmsvbkobsagad
dgadg
ad
ddad

dgadgadg
error 121

dgad
gdagad

gadagad

gagad

msg 128, 9341353513

Input Files: file2.lst

test messgae
g
sagad
dgadg
ad
ddad

dgadgadg
error 121

dgad
gdagad

gadagad

gagad

msg 128, 9341353513

Monday, March 14, 2011

How to set environment variable permanent in DOS

 

By using the SET the environment value persist till the current session live.
To set the environment value permanent in DOS use the SETX

Download SETX

Thursday, June 10, 2010

Delete files using DOS command FORFILES

 

To delete te

--Delete all .bak files in the named directory and its subfolders where the file modified date is more than 2 days old.

 

EXEC xp_cmdshell 'FORFILES /p "L:\MSSQL$PRODSQL2KWEB\Backup" /s /m *.bak /d -2 /c "CMD /C echo Deleting the file : @file del /Q /F @FILE && del /Q /F @FILE " '

/*

FORFILES Parameters

Parameter Name Description

/p Path

/m Search Mask (default is *.*)

/s Subdirectories will be searched recursively if this parameter is included

/c <command> Command to be executed against each file in the result set, commands must be enclosed in double-quotes, default is "cmd c/ echo @file"

/d Date range for file selection, using Last Modified Date as the criterion for the file. When the /d parameter is in the form of MM/DD/YYYY, file meeting the criteria of +/- the specified date are included. When in the format of a smallint (-32,768 - 32,768) the files +/- the files with a modified date +/- that number of days from the current date are included in the file result set.

Variables

Variable Name Description

@FILE File name

@FNAME File name without extension

@EXT File extension

@PATH Full path of the file

@RELPATH Relative path of the file

@ISDIR Evaluates as TRUE if the file type is a directory

@FSIZE File size in bytes

@FDATE Last modified date stamp on the file

@FTIME Last modified timestamp on the file

*/

Monday, January 11, 2010

SQL Server 2005 /2008 Express Edition Backup automation

SQL Database Backup Script

declare @IDENT INT, @sql varchar(1000), @DBNAME VARCHAR(200)


 

select @IDENT=min(DBID)
from
SYSDATABASES
WHERE [DBID] > 0 AND NAME NOT
IN
('PUBS',
'NORTHWIND',
'TEMPDB','AdventureWorks')

while @IDENT is
not
null

begin

    SELECT @DBNAME = NAME FROM
SYSDATABASES
WHERE
DBID
= @IDENT

/*Change disk location here as required*/

    SELECT @SQL =
'BACKUP DATABASE '+@DBNAME+' TO DISK = ''C:\SQLBACKUP\Backup\'+@DBNAME+'.BAK''WITH INIT'

PRINT @SQL

    EXEC (@SQL)

    select @IDENT=min(DBID)
from
SYSDATABASES
WHERE [DBID] > 0 and
DBID>@IDENT AND NAME NOT
IN
('PUBS',
'NORTHWIND',
'TEMPDB','AdventureWorks')

end


 

DOS Batch files to backup the databases

@echo off

c:

if not exist c:\SQLBackup\Logs MD C:\SQLbackup\Logs

if not exist c:\SQLBackup\Backup MD C:\SQLbackup\Backup

cd c:\SQLBackup

Echo Backup Started >> c:\SQLBackup\Logs\SQLBAckup.log

Date /T > c:\SQLBackup\Logs\SQLBAckup.log

Time /T >> c:\SQLBackup\Logs\SQLBAckup.log

Echo.

echo *************************************************************************** >> c:\SQLBackup\Logs\SQLBAckup.log

isql -S (local)\Express -E -i c:\sqlbackup\backup.sql >> c:\SQLBackup\Logs\SQLBAckup.log

echo *************************************************************************** >> c:\SQLBackup\Logs\SQLBAckup.log

echo.

Date /T >> c:\SQLBackup\Logs\SQLBAckup.log

Time /T >> c:\SQLBackup\Logs\SQLBAckup.log

echo Backup Finished >> c:\SQLBackup\Logs\SQLBAckup.log

echo.

echo *************************************************************************** >> c:\SQLBackup\Logs\SQLBAckup.log


 

Folders will look like,

image 
Schedule it on Windows Task Scheduler

image

That's it the SQL Server 2005 / 2008 Express Edition database backup is automated now!

Tuesday, December 02, 2008

DOS Batch file to create a file name in data stamp

:: 2. Set logfile name based on today's date

for /F "tokens=1,2,3,4 delims=/ " %%I in ('date /T') do set Logfile=%%J%%K%%L.log

:: 4. Delete all but 7 most recent log files

:: Get a sorted list of the log files oldest at the bottom of the list

Dir /b /o-d %Logfolder%\*.log > %Workfolder%\%LogList%

:: The find command counts how many log files there are and for sets TempVar with this value

For /f %%A in ('Dir /b /o %Logfolder%\*.log^| Find /c /i "log"') do set TempVar=%%A

:: If there are more logs than needed skip the number to keep and delete the oldsest one(s)

If %TempVar% GTR %LogsToKeep% For /f "skip=%LogsToKeep%" %%B in (%Workfolder%\%LogList%) do Del /q %Logfolder%\%%B
Del /q %Workfolder%\%LogList%

Tuesday, April 08, 2008

Trap custom SQL 2005 Installation Success state

C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG\Files>find /I "comp
leted successfully" SQLSetup0007*.log > Result.txt

Thursday, March 20, 2008

How to find domain name using batch

@echo off
echo.
echo If no Domain is listed below, then you are not part of an NT Domain.
echo.
echo If so, please use your account from one of the supported NT domains,
echo.
echo.
echo.
echo Your current NT Logon is:
echo.

net config workstation | find "User"
net config workstation | find "Logon"

echo.
echo.
echo.
echo.
pause