Search linux log files using mac terminal or script - linux

I want to search my access logs for traffic going to a directory on a Linux. I have a mac which I know I can do this with my terminal but I can't find an example how to do this.

Do you have the log locally on your Mac? Or are you asking how you would use a Mac to administer a Linux OS?
Open terminal, either change directory to the dir that contains the log or adjust the command to suit. Depending on what you want to search for, you'd use grep.
grep -i "dir name" logfile.log
It's a bit of a wide empty question so I don't know what you want to search for.
If it's remote, you'd open terminal and ssh to the server which has the log and do something similar to the above. Or, if you're asking how you would do it in one command, you could use ssh too.
ssh user#linux "grep something /var/log/apache/access.log"

Related

searching text in a file remotely

I have log files, based on Linux servers, and I'm working on Windows OS.
I'm using Filezilla to log in the Linux server and searching specific text or strings by open the log file.
I want to automate this process using batch in Windows, I tried using below;
#echo off
cls
set /p string="Enter the string: "
echo open xx.xx.xx.xx 21> ftpc.dat
echo xxxxxxxx>> ftpc.dat
echo xxxxxxxx>> ftpc.dat
echo bin >> ftpc.dat
echo grep '%string%' /PATH IS HERE/log.log >> ftpc.dat
ftp -s:ftpc.dat
I'm just new to that, I want ideas on that, how I automate this search process? where I can make a search tool for any text, that this tool goes and find specific file in linux server and shows the results in lines (before/after 15 lines) of thatsearch results.
Do I need to write bash scripts, or I can do this basic script in batch file as above to show or output the results?
If you have a number of Linux servers to watch, it might be worth installing something like rsyslog or logstash. It's a big topic, but those might be good starting points in your research.
Other things to google: elasticsearch, kibana ... and their alternatives.
You cannot run grep using FTP.
So either:
Use FTP to download whole file and grep/search it locally.
Or (as you seem to have an SSH access too) use a command-line SSH client to execute grep on the server. On Windows, you can use Plink (which comes with PuTTY):
plink -pw password user#example.com grep '%string%' /remote/path/log.log >

how to enable statistics using awk in linux

when I type the command stats.awk size.cvs, it says command not found on my virtual machine linux. Can someone help me get through sice Im new to linux and linux coding
It looks like you are not trying to run any standard Linux tool, but a script written by someone else called "stats.awk"... and the file you want to operate on is called "size.cvs" (it is more likely called size.csv -- as this is likely a "Comma Separated Value" file). Most Linux implementations do not allow you to just run a script unless the script is in your PATH and has the right permissions.
You could try "fully qualifying" the path of your awk script, but probably easiest is to just feed it into awk. Try:
awk -f stats.awk size.cvs
To find out more information about your shell run:
man $SHELL
Or just Google for a tutorial on your shell (which is likely bash). To find more about awk, again, try Googling for a tutorial on awk.

"ls" command works sometimes and sometimes doesn't on Node.js

Please help me out, i am new. "ls" command for list doesn't work on my Node.js most times. It is not working now. However, it works sometimes though. How can i find list of current directory or file in Node.js?
As per to my tutorial for Node.js, i have to use command "ls" to see the list of my current directory or file.
When i press enter on ""ls" it replied "ls" is not found as internal or external command."
However, "ls" command shows the contents of file sometimes. I am using "ls" command for Desktop listing and another file in their. I do go to Desktop by cd Desktop. and then i only write "ls" then enter.
Please reply with simple explanation since i am new and learning Node.js.
i am taking Essential Node.js training from Lynda.com. "ls" did worked earlier though. "ls" does work on Window Shell and Bash all the time. Please reply. Thank You.
If not, what command i shall use for listing current directory or file contents?
Windows operational system provides the command dir instead of ls which should work similarly in your case:
Just use:
dir

Netgem n5200 (or other) - How to get into linux operating system layer?

After logging by PuTTY to Netgem n5200 device I have open in terminal kind of shell with about 40 commends, but no information about way how to close it and work directly on Linux.
Device has for 99% installed HardHat Linux distribution (MontaVista Linux).
From level of mentioned shell I can use some simple linux command like "! pwd", "! ls -l", "! ps".
Maybe it would be useful that I'm in tmp dir and I can not leave it at this moment.
I've already study Netgem SDK looking for information and I found nothing, the same result after searching in google, so that's why I came looking for help here.
Probably you can try to start the shell using
!sh
or
!bash
command.
If not, could you please provide the list of available commands (such as pwd, ls), may be some of them could be used to get a shell (e.g. vi).

Using Linux commands on files across multiple servers

I am new to Linux as a whole and so far I have not found a solution to this that isnt clumsy at best. I have a Windows background and so I am accustomed to running commands on one server that access text files on multiple systems in the same domain.
Example of what is processed in Windows:
find "Some text" \\ServerName01\c$\inetpub\*.log
find "Some text" \\ServerName02\c$\inetpub\*.log
find "Some text" \\ServerName03\c$\inetpub\*.log
Example of what I would LIKE to do in Linux:
sed 's/SomeText/OtherText/p //ServerName01/var/opt/somefolder/*.log
sed 's/SomeText/OtherText/p //ServerName02/var/opt/somefolder/*.log
sed 's/SomeText/OtherText/p //ServerName03/var/opt/somefolder/*.log
What is the best way to do the above in Linux, or is it even possible?
Thanks!
See the pssh and pscp suite, you can run commands on a bunch of remote servers : http://www.theether.org/pssh/
pssh or cssh would work
pssh provides a number of commands for executing against a group of
computers, using SSH. It’s most useful for operating on clusters of
homogenously-configured hosts.
http://www.ubuntugeek.com/execute-commands-simultaneously-on-multiple-servers-using-psshcluster-sshmultixterm.html
there is a lot of way for doing it :
Via NFS/Fuse Mount, mount the logs directory on one system and you could do the same thing as windows (which automatically mount remote filesystem with the "\\")
use ssh,(that would be my prefered solution)
cat serverlist | xargs -i ssh {} " grep \"some text\" yourfilepaths"
which helps if you use ssh keys pairs

Resources