file scan

H

Herb Martin

i need to scan a file, if something is found i.e. 221 then do something.
basically i am trying to script and auto ftp process to upload a file, which
i have already done. however, if it fails i don't know about it... any
advise or help will be appreciated...

use perl;

For arbitrarily complex responses you need a programming language and
while you can use simple batch (for some such), VBScript, JavaScript, etc;
perl was invented PRECISELY for this sort of job.
 
L

LWG

i need to scan a file, if something is found i.e. 221 then do something.
basically i am trying to script and auto ftp process to upload a file, which
i have already done. however, if it fails i don't know about it... any
advise or help will be appreciated...
 
P

Paul R. Sadowski

You want something like this:
for /f %%c in ('findstr /b "221 " ftp.out') do @echo %%c

I'm assuming the 221 is the server return code so the /B switch says look
for it at the beginning of the line.

Again:
for /f %%c in ('findstr /b "221 " ftp.out') do <something>

for /f %%c in ('findstr /b "221 " ftp.out') do @echo Server said goodbye
 
H

Herb Martin

Please provide us with examples. It is kind of you to mention what
programming languages to you but without syntax it doesn't do much
good. Might as well reccomend C++ or Assembler to get the job done.

His question is so imprecise it is impossible to provide him a "ready made
solution" but for a common problem, "CR" and no "CR/LF" in files coming
from Unix the following Perl "program" works just fine (note it will do
all files matched on the command line when called AND make backups
of them):

@for %%a in (%*) do perl -i.bak -n -e "print;" %%a

I call it CRLF.cmd usually --- invoke it like this:

crlf *.txt *. *.pl

(All txt, pl and no extension files will be converted from Unix to Windows
style line endings.)

There are many (complex) examples in the Windows 2000/NT ResKits.

Below is a program that finds and prepares a kill commannd for certain
processes I frequently need to kill:

#################################
open(TLIST, "-|", 'tlist');
while (<TLIST>) {
if (/(ModemDeviceChange)|(CTFMON)|(wcescomm)|(wcescomm)|(realplay)/i) {
($pid, $name, $comment) = split;
printf("kill -f %5d %s\n", $pid, $name);
}
}
close TLIST;
###################################

It would be trivial to change the process names or get them from the command
line, and if you wished to could DO the kill but I just prefer to output the
command so that I can select, copy, and paste it.
 
P

Paul R. Sadowski

Herb Martin said:
Below is a program that finds and prepares a kill commannd for certain
processes I frequently need to kill:

Easy to do with VBS:
set wmi = getobject("winmgmts:")
wql = "select * from Win32_Process where name='outlook.exe' or
name='whatever.exe'" [etc]
set results = wmi.execquery(wql)
for each app in results
app.terminate
next

The problem with Perl is that you have to get and install the Perl
interpreter. In most cases it makes more sense to use the standard
facilities of the OS at hand. I keep a copy of Perl but use it only for
prototyping for the Unix machines I work on.

But this is way off-topic so I'll leave it at that. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top