Get your local IP address like pro
In shell scripts if you need to get you local IP address corresponding to your hostname then you can use this command
hostname -i
In shell scripts if you need to get you local IP address corresponding to your hostname then you can use this command
hostname -i
I was trying to setup a simply webservice to reply to POST requests. Earlier this was being done in tomcat which seem a little overkill to me since I already had a webserver up and running. So, a quick c program to respond to request is all that I needed. And here is the result.
/*
* =====================================================================================
*
* Filename: Login.cpp
*
* Description:
*
* Version: 1.0
* Revision: none
* Compiler: gcc
*
* Author: Amit Agarwal (),
* Organization:
*
* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
*/
#include <stdio .h>
#include <stdlib .h>
#include <string .h>
#define MAXLEN 1024
#ifdef DBG
#define DEBUG(a,b) fprintf(stderr, a, b);
#else
#define DEBUG(a,b)
#endif
#define HEAD "n"
#define TAIL ""
int main(void)
{
char input[MAXLEN];
char * data;
char*lenstr;
long len;
printf("%s%c%cnn",
"Content-Type:text/xml;charset=iso-8859-1", 13, 10);
// len = getenv("QUERY_STRING"); // This is for GET
lenstr = getenv("CONTENT_LENGTH");
DEBUG( "Length string is %sn", lenstr);
if(lenstr == NULL || sscanf(lenstr,"%ld",&len)!=1 || len > MAXLEN)
printf("Error in invocation - wrong FORM probably.");
DEBUG( "Length is %ldn", len);
{
int count=0;
while ( count < len )
input[count++] = getchar();
input[count]='?';
DEBUG ( "Read characters = %dn", count)
}
//fprintf(stderr, "VAlue is %sn", input);
///unencode(input + 5 , input + len, data);
data = input;
DEBUG("Data value is %sn", data);
printf(HEAD);
printf("Everything else goes heren");
printf(TAIL);
fprintf(stderr, "Sent resp: tid[%s], eaid[%s], tcode[%s]n", tid, eaid, tcode);
}
</string></stdlib></stdio>
Additionally, the makefile:
Continue readingfirewalld by default does not allow packets that are dropped. In some cases, you need to find out if some packet is being dropped or not. For doing so you may want to enable logging of dropped packets with the following command:
sudo firewall-cmd --set-log-denied=all
This will enable logging all the packets and help you figure out if firewalld is dropping the packet.
Trying to find the total usage for each of the file types by extension, then here is a quick bash function for you :
disk_usage_type ()
{
find . -name '*'$1 -ls | awk '
BEGIN{
a[0]="Bytes";
a[1]="KB";
a[2]="MB";
a[3]="GB";
}
{sum+=$7; files++;}
END{
print "Total sum is ::\t" sum;
print "Total files ::\t" files;
while (sum > 1024) {
sum=sum/1024;
count++;
};
print sum" "a[count];
}'
}
Just define the function in one of your bash startup files. After that to use the function pass in the extension for which you would like to find the total size. Output should be something like below:
Continue readingIf you have tried to get the count of lines in file, the you would know about “nl” or “wc -l”. But as you are aware these give you number of lines with other details as well and you need to post process the number to make sure that you have only number and nothing else. In such cases, it is useful to use the count feature of grep and here is a shorthand to get the count of lines in any shell script:
Continue readingFirst you need to install gettext, which by the way might be already installed, however you can install with
dnf install gettext
Details of the package:
- Name : gettext
- Arch : x86_64
- Epoch : 0
- Version : 0.19.4
- Release : 4.fc22
- Size : 4.6 M
- Repo : @System
- Summary : GNU libraries and utilities for producing multi-lingual messages
- URL : http://www.gnu.org/software/gettext/
- License : GPLv3+ and LGPLv2+
- Description : The GNU gettext package provides a set of tools and documentation for
- producing multi-lingual messages in programs. Tools include a set of
- conventions about how programs should be written to support message
- catalogs, a directory and file naming organization for the message
- catalogs, a runtime library which supports the retrieval of translated
- messages, and stand-alone programs for handling the translatable and
- the already translated strings. Gettext provides an easy to use
- library and tools for creating, using, and modifying natural language
- catalogs and is a powerful and simple method for internationalizing
- programs.
Usage examples:
Continue readingIf you want to monitor your server logs and also like them to be emailed then just Logwatch may not be sufficient. It sends you a mail but does not archive them, so head over to epylog
- Name : epylog
- Arch : noarch
- Epoch : 0
- Version : 1.0.7
- Release : 9.fc22
- Size : 151 k
- Repo : fedora
- Summary : New logs analyzer and parser
- URL : https://fedorahosted.org/epylog/
- License : GPLv2+
- Description : Epylog is a new log notifier and parser which runs periodically out of
- cron, looks at your logs, processes the entries in order to present
- them in a more comprehensive format, and then provides you with the
- output. It is written specifically with large network clusters in mind
- where a lot of machines (around 50 and upwards) log to the same
- loghost using syslog or syslog-ng.
To install :
Continue reading