dos command to read a text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dosnoob
Posts: 3
Joined: 28 Jan 2013 23:24

dos command to read a text file

#1 Post by dosnoob » 28 Jan 2013 23:32

Hi DOS gurus, im a DOS noob. I want to create a DOS script that will read a log/text file. Below is the requirement:
The script will basically search for a word/string(let say "ERROR:XXXX") from the log file, if the exact word/string is found, then the script will restart a windows services.

log file name = logs.txt
file to search from the logs = ERROR:XXXX

Thanks in advance.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: dos command to read a text file

#2 Post by foxidrive » 28 Jan 2013 23:42

Code: Select all

@echo off
find "ERROR:XXXX" <logs.txt >nul && (
net stop "servicename"
net start "servicename"
)

dosnoob
Posts: 3
Joined: 28 Jan 2013 23:24

Re: dos command to read a text file

#3 Post by dosnoob » 29 Jan 2013 00:23

Hi foxidrive, thanks for the quick response.
How if it cannot find the "ERROR:XXXX"? Will it still restart the services based on your suggested script?

My requirement is, the services will only be restarted if the string "ERROR:XXXX" is found.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: dos command to read a text file

#4 Post by foxidrive » 29 Jan 2013 01:14

dosnoob wrote:Hi foxidrive, thanks for the quick response.
How if it cannot find the "ERROR:XXXX"? Will it still restart the services based on your suggested script?

My requirement is, the services will only be restarted if the string "ERROR:XXXX" is found.


If the term "ERROR:XXXX" is not found then it will do nothing.

dosnoob
Posts: 3
Joined: 28 Jan 2013 23:24

Re: dos command to read a text file

#5 Post by dosnoob » 29 Jan 2013 01:27

Youre the man foxidrive.. Thanks

Post Reply