![]() ![]() It is not strictly necessary for the string you are looking for to be in quotes. The most recent should be the error you’re looking for. Grep "127.0.0.1" /usr/local/apache/logs/error_logĪssuming your IP is “127.0.0.1”, that command will show you all the times in the log file that your IP address appears. ![]() The way to do grep the log for your IP on a cPanel server is: If you do not know this IP, you can find it by visiting. A good way to find that in the apache error log is to grep for the IP address of the computer you are working from. You notice a php error on your site, and you want to see if you can get the specific error from the apache log for the specific time that you saw it. Here is a practical situation you may encounter with your server. Grep "input_string" filename.txt Using grep Given that input, it then hands you all the lines in the file that contain that string. Grep takes two pieces of input the string you are looking for in the file, and the file you are looking through. This situation cries out for some faster method of extracting that piece of information.įor this type of task, Linux provides the grep command. It would take far too long to read through the huge file. And buried somewhere in that file, there is one piece of information that you need to find. It is long, and has much information in it. If you insist on using ping and sed, you can do: % ping -c1 | sed -nE 's/^PING+\((+)\).Imagine you have a file. In essence, with my configuration, this will first check /etc/hosts, then mDNS and at last DNS. In /etc/nf, so getent hosts will query in sequence and use gethostbyaddr(3) or gethostbyname(3) based on name and ahosts will use getaddrinfo(3). In my computer, i have: hosts: files mdns4 dns etc/nsswitch, then use the getent command with hosts (or ahosts) database e.g.: getent hosts Here's a dig output: % dig +short Īs a side note, in Linux, if you want to query by the NSSwitch (Name Service Switch) i.e. You should look at dig, host, nslookup - whatever suites you the best. Ping is for checking whether a host is up or down based on ICMP response, it is never the right tool for only resolving IP address, there are dedicated tools for that. Again, thank you to everyone that tried to help. I am now using a timer script that I created to configure iptables at certain times to block certain domain name resolutions. I have since refined my methods and do not use any of the answers here but I thank everyone for their attempts with helping here. I have, since asking this question, learned proper POSIX regex to do what I needed and I need to make it clear that I was originally asking about the regular expressions for sed that would print a single instance of an IP from ping output. This is NOT asking to resolve a domain name and therefore is NOT A DUPLICATE!!! ![]() How to parse the IP ADDRESS "ONLY" from ping OUTPUT when using ping on a domain name. Since some marked this question a duplicate of some other bullshit question that has nothing to do with this one, I will make it clear enough that retards with English comprehension troubles can understand: This question is specifically about managing ping output using sed in order to keep the tool I have created more portable as ping comes default with almost any and all linux distros. I already know/knew how to resolve IP address from a host name or domain. How can I remove the duplicate with sed so that I can store the single IP address into a variable and run the script as a cronjob, or am I on a better track using tr? Which gives me an output of: you can see, there is a duplicate of the same IP address. So if I do a ping for Google: ping -c 1 -s 16 I don't want to do this as I believe a single ping will be much more lightweight and portable. to 3:30 P.M.).Īs of currently, the tool works fine, but I have to input IP addresses to certain websites manually into a text file and have the tool pull the IP address based on the nth line using the "head" and "tail" commands. This tool will block certain IP addresses for a certain time range (i.e. I have crafted a Bash tool that runs on a server. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |