Showing posts with label cmd. Show all posts
Showing posts with label cmd. Show all posts

Thursday, April 16, 2009

Change PROMPT default output

You can add within your Environment Variables the following value for variable PROMPT:

SET PROMPT=$T $P$G$S

If you don't have administrative rights then add this within user variables instead of system variables:



that's how the output looks like:



thanks to ronald for this tip.

Wednesday, August 13, 2008

Windows Command Line FIND instead of GREP

People have maybe heared of grep on linux boxes... today I wanted to do a small count for the appeareance on a windows box where we host a log file with 500k rows.

P:\>find /?Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  • /V Displays all lines NOT containing the specified string.
  • /C Displays only the count of lines containing the string.
  • /N Displays line numbers with the displayed lines.
  • /I Ignores the case of characters when searching for the string.
  • /OFF[LINE] Do not skip files with offline attribute set.
  • "string" Specifies the text string to find.
  • [drive:][path]filename Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the promptor piped from another command.

update: otherwise you can also use qgrep: http://malektips.com/xp_dos_0011.html

Tuesday, July 24, 2007

How To: Shrink Sql Server 2005 Log Files

Shrink Sql Server 2005 Log Files




use YourDbName
backup log YourDbName with truncate_only
dbcc
shrinkfile(YourDbName_log)

if you copy your databases, names are not always the same! based on how do you copy it it still has the same name like the source database.. keep attention when you run it - then it shrinks e.g. 130 GB -> 22 MB .... many information goes away.

Update:

========

today i done some researches and I found the following thread:

http://www.eggheadcafe.com/software/aspnet/30488923/script-which-will-shrink.aspx

after some analyzing and test runs the follwoing solution worked for me:


CREATE TABLE #TDatabases(
DBName nvarchar(128),
DBLogicalName nvarchar(128)
)
INSERT INTO #TDatabases
SELECT db.name DBName, mf.name DBLogicalName
FROM sys.databases db join sys.master_files mf
on db.database_id = mf.database_id
WHERE db.name not in ('master', 'tempdb', 'model', 'msdb',
'distribution') AND type_desc LIKE 'log'

SET NOCOUNT ON
DECLARE @VarDBLogicalName nvarchar(128)
DECLARE @VarDBName nvarchar(128)
DECLARE @VarRowCount int

SELECT top 1 @VarDBName = DBName, @VarDBLogicalName = DBLogicalName
FROM #TDatabases
SET @VarRowCount = @@rowcount
WHILE @VarRowCount <> 0
BEGIN
EXEC(' use ' + @VarDBName + ' backup log '+ @VarDBName + ' with no_log
dbcc shrinkfile(''' + @VarDBLogicalName + ''', TRUNCATEONLY) WITH
NO_INFOMSGS')
DELETE
FROM #TDatabases
WHERE DBName = @VarDBName
SELECT top 1 @VarDBName = DBName, @VarDBLogicalName =
DBLogicalName
FROM #TDatabases
SET @VarRowCount = @@ROWCOUNT
END
DROP TABLE #TDatabases
SET NOCOUNT OFF


(otherwise search at google for: "osql shrink all db" in it doesn't fit your needs)


the above script you put now simply into a *.sql file (e.g.: shrinkalldatabases.sql).

now you need to create a second, which is simply a batch file (e.g.:startshrink.cmd) : *.bat or *.cmd. Into this file you write the following command:

osql -E -i shrinkalldatabases.sql -o result.txt

more info about osql you can find here: http://technet.microsoft.com/en-us/library/aa213088(SQL.80).aspx

all needed parameters are the following:

-E -> authentication
-i -> input file
-o -> output file

once you add it now to run once a week you have no further problems with your sql db sizes :-)

to have a small history and some additional information, here how I have created my *.cmd file:

@echo start: %date% %time% >> result.log
osql -E -i shrinkalldatabases.sql >> result.log
@echo end: %date% %time% >> result.log

enjoy it.



Monday, February 19, 2007

How To: Execute a Batch file within Winform

just some code, I don't think there is to much to explain.

Copy & Paste it:



string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "");
// get some key from the config file.
string serviceIp = COM.Handler.Config.GetStringValueFromConfigByKey("IpAddress");
string vars = " " + serviceIp;

Process proc = new Process();
// attach the file
proc.StartInfo.FileName = @"YourBatchFile.cmd";
// pass arguments
proc.StartInfo.Arguments = vars;
// hidden run
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
// no need in my case for show errors.
proc.StartInfo.ErrorDialog = false;
// set the running path
proc.StartInfo.WorkingDirectory = path;
// start the process
proc.Start();
// wait until its done
proc.WaitForExit();
// any other number then 0 means it is an error.
if (proc.ExitCode != 0)
MessageBox.Show("Error executing in YourBatchFile.cmd", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);


hope this helps.

Friday, August 04, 2006

how-to: make a for loop in dos and call websites with console browser wget

here are some FOR loops…

Count and display from 1 to 10:
for /L %i in (1 1 10) do @echo %i


Sequentially get the Microsoft home page 3 times using wget and dump its contents to the console:

for /L %i in (1 1 3) do @wget http://www.microsoft.com/ -O –

Same as above except done in parallel:

for /L %i in (1 1 3) do @start wget http://www.microsoft.com/ -O -

wget - can be get over here:
wget - console browser




thanks to Atif Aziz

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge