[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Grep from FTP Command

Posted on 2008-11-12
8
Medium Priority
?
1,924 Views
Last Modified: 2012-06-27
I automated a FTP session and was trying to grep from the ftp command. It worked for a few times and without the change in the script started returning Invalid Command for Grep on FTP. Did some search and figured Grep does not work on FTP. 2 Questions here:
1) Why did Grep work the first time around?
2) Is there a way I can incorporate Grep into FTP session?
>_temp.txt echo %1
>>_temp.txt echo %2
>>_temp.txt echo cd c:/logs
>>_temp.txt echo binary
>>_temp.txt echo prompt
>>_temp.txt echo get %YYMMDD%.log
>>_temp.txt echo cd e:/uname
>>_temp.txt echo put %YYMMDD%.log
>>_temp.txt echo grep <Text> %YYMMDD%.log ^> <Text>.log
>>_temp.txt echo get <Text>.log
 
>>_temp.txt echo bye
 
ftp -s:_temp.txt <Host>

Open in new window

0
Comment
Question by:megh345
  • 3
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
dathho earned 2000 total points
ID: 22941568
No, grep is not an ftp command.  However, if you want to run a shell based grep from within your ftp session, simply place a ! (escape to the shell) in front of it.  I.E.
>>_temp.txt echo !grep <Text> %YYMMDD%.log ^> <Text>.log
 
0
 

Author Comment

by:megh345
ID: 22941759
Thanks Dathho, But I am running a batch from windows. so ! executes grep on cmd and returns a error that grep is not recognized as an internal or external command. Any further help will be greatly appreciated. Thanks in advance
0
 
LVL 6

Expert Comment

by:dathho
ID: 22941958
In that case the find command should work for you.

>>_temp.txt echo !find <Text> %YYMMDD%.log ^> <Text>.log  
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:megh345
ID: 22942026
Hmm Find truncates 1024 characters from every line. I have more characters than that in a line. Thanks for your quick response.
0
 
LVL 6

Expert Comment

by:dathho
ID: 22944163
If you are Windows 2000 or newer you should be able to try the findstr command.  I don't know if it will have different behavior.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22946693
can you show the script with which grep was working?

grep is not a ftp command and when run with ! it runs on the local system and not the remote one.

0
 

Author Comment

by:megh345
ID: 22962517
It was the same script where it worked.... It is when it stopped working that I noticed it was not a ftp command. I guess it was magical for a bit.. I couldn't figure out why either... :( .

Dathho, I don't think FindStr will do any better than find command unfortunately..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question