grep cf logs from windows machine - windows

I am using the CloudFoundry CLI tool to tail logs from a remote cloudfoundry server. As per the cloud foundry log docs the command is
cf logs **app_name** --recent | grep RTR.
When i run this i get the error, grep is not recognized as a command. I believe this only works in a Unix based system. How can i use a grep like functionality from Windows CF CLI?

cf logs app_name --recent | findstr RTR
Findstr is capable of finding the exact text you are looking for in
any ASCII file or files. However, sometimes you have only part of the
information that you want to match, or you want to find a wider range
of information. In such cases, findstr has the powerful capability to
search for patterns of text using regular expressions.
Microsoft Technet
other solution would be that you install GNU grep on Windows. There are several ports available.

The Windows command prompt does not natively support bash prior to Windows 10, which is required for commands like grep. To use grep, you either have to use the git-bash shell provided during a git install, or in current releases of Windows, use the bash command in a Windows Command Prompt after installing the Windows Linux Subsystem. Windows Reference Documentation here

Perhaps you can use the git-bash if you have git installed on your machine. The git-bash comes with UNIX tools such as grep, so you would just open the git-bash instead of the Windows console and enter your command there.

Related

Re-directing standard error to console and file [duplicate]

This question already has answers here:
Displaying Windows command prompt output and redirecting it to a file
(32 answers)
Closed 8 years ago.
I am trying to redirect both the standard out and standard error in a Windows batch file to the same file.
However I would like the standard error and user input prompts to be displayed in the console as well.
I tried the following:
Process_SVN_Repos.bat > Process_SVN_Repos.log 2>&1
However this causes the STD ERROR to go to
the file (which I want), but does not show up in console and hence I can not input any user required inputs because I don't see any user prompt.
So basically I am trying to:
Redirect all std out to a file.
Redirect all STD ERROR to the same file.
Also show the same STD ERROR on the console.
See the user prompt the application needs in the console and be able to input the user prompt.
You need a tee command for Windows. Here are few options:
Rob van der woude pure batch solution / ....
Dave Benham's jscript/bat hybrid
Tee by Microsoft - it's part of Unix services for Windows (after installation it's available in the BIN folder and has no exe extension) - For XP/Windows Server 2003 for Windows Vista, Windows 7, Windows 8, Windows Server 2008, and Windows Server 2012.
Command line co uk
UnixUtls
Windows doesn't have a tee command, so you can't. As Windows includes Unix you could use one of those shells. I don't know if it has tee, but it has 350 utilities.
If you are using a Unix environment then you can easily use the tee command. But since you are on Windows, it doesn't support you directly. But there are alternatives that you can use.
I have used Wintee for a similar task like yours. I suggest you use that small utility called wtee.exe. If that can't help your task there are other alternatives as well.

Windows, heroku config | grep MONGOLAB_URI

I'm developing a MEAN stack app in windows and the example code I've been given to connect my mongoDB to heroku says on linux and mac the config | grep command in the title would display the full URI. On windows I get the error grep not recognized as an internal or external command, operable program or batch file. I know nothing about the grep command. What would be an alternate method to do this on windows?
grep is just a way to filter the output to make it easy to see the information you're looking for. The Windows equivalent would be 'findstr' (http://technet.microsoft.com/en-us/library/bb490907.aspx). But I would just try leaving it out altogether and using your eyes to find where "MONGOLAB_URI" appears. Assuming you don't have a ton of config, it should be easy to spot:
> heroku config

Download file to null (Windows CLI)

I would like to download a file to null in windows cli just for testing purposes.
In linux i used
wget http://download.thinkbroadband.com/1GB.zip -O /dev/null
This kept my connection busy for a while.
Is there any way to do this in command prompt or power shell in windows 7?
Also other solutions to generate traffic from internet,ut withous saving it to disk, will be accepted.
Using Windows' (roughly) equivalent NUL device should mimic the Linux behaviour sufficiently:
wget http://download.thinkbroadband.com/1GB.zip -O NUL
Update: Recent builds of wget for Windows are available here.
You can use that exact same command on any Windows with Cygwin. Make sure you select Wget in the package list when installing Cygwin

How can I view a log file from powershell console ? (i.e. powershell equivalent of 'less')

What is the powershell equivalent of 'less'?
I see 'more', but it lacks some of the features I rely on (e.g. searching through the file)
I seek a pager (equivalent of 'less') which allows searching (match or ignore case), multiple files at once, etc.
Some of our servers run windows 2008 and I lack admin privileges to install cygwin
I had heard windows 2008, MSFT got their act together and provided some easy-for-admins tools.
Update:
I should give some context:
I know little about power shell
New servers have 2008 on them
While I affection for many tools of yore, the dos prompt is not one of them
I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
I understood that powershell gave us those tools
I fired off my question quickly.
thanks
It reads like you know you can do this:
gc logfile.log | more
(GC is an alias for Get-Content).
You may be able to do the filtering etc.. with this more information can be found by running these commands:
Get-Help Get-Content Get-Help
Get-Content -Examples
(Get-Help gc would work fine as well).
And the bits you may be interested in are limit\filter etc...
Get-Help gc -Parameter * | more
I just use the GOW version of less, works fine.
I don't know of any direct analogue for less in powershell that you can implement easily. Your best bet is to get a windows implementation of less that is outside of cygwin, that way you can just drop in the binary somewhere accessible to your account.
to get grep/vim/wget and other Linux like commands in powershell I suggest running.
iex (new-object net.webclient).downloadstring(‘https://get.scoop.sh’)
then
scoop install grep
scoop install perl
scoop install vim
and to get a list of all of them
scoop search
In Windows 10 PowerShell + Cygwin I use:
gc .\myfile.log | less
Previously I was trying to use cygwin directly:
less .\myfile.log
but it shows binary file because of invalid charset setting between 32b-bit and 64-bit.
I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
In the case you missed this question (top voted) you might enjoy this answer.

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?
Put another way, say a user ABC is logged in on windows and a remote user logs in with ABC's login/password over ssh, can remote ABC pop up an app on the local ABC user's desktop?
I am asking this on Stackoverflow and not Serverfault because the motivation for doing this is programmatic in nature. The remote call will be coming from a Linux box so while it may be possible(?) to do this using WMI or some other approach, ssh seemed like the simplest.
Happy to hear simpler/better alternatives though.
Thanks!
If your cygwin sshd is running under a privileged account, it can get a handle to the current desktop and put windows on it. See the desktop parameter of STARTUPINFO for CreateProcess.
My own solution. Tested on windows XP (but I think it should run in any windows environment with a little effort).
You need to use the psexec and quser command.
First, put psexec and quser in a directory included in the cygwin's PATH environment variable. Just copy these files into the bin directory under cygwin.
You can find the quser.exe in your %system32%\dllcache dir. But for any reason I can't access to it (or access to the mentioned directory) through cygwin commands (i.e. ls, cp, etc), so I made a copy using the microsoft's copy command to the cygwin\bin folder.
Notes: I think it's helpful to have the suite psutils all in the bin folder of cygwin. The first time you run either of these utilities will have to accept a license agreement from Microsoft warning, so run psexec from Windows explorer the first time.
Then create these alias in your .bash_profile file:
alias winrun='psexec \\\\YOU_USERNAME_HERE -d -i `quser | grep YOU_USERNAME_HERE | grep console | awk "{print \\\$3}"`'
alias explorethis='winrun explorer $(cygpath -w `pwd`)'
Remember that you will need to translate the current directory using cygpath if you need to pass it as argument of a command ("explorethis" is an example of that).

Resources