Saturday, 14 November 2020

anvil - Unix, Linux Command

LPI Study Material, LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Guides

NAME

anvil - Postfix session count and request rate control

SYNOPSIS

anvil [generic Postfix daemon options]

DESCRIPTION

The Postfix anvil(8) server maintains statistics about client connection counts or client request rates. This information can be used to defend against clients that hammer a server with either too many simultaneous sessions, or with too many successive requests within a configurable time interval. This server is designed to run under control by the Postfix master(8) server.

In the following text, ident specifies a (service, client) combination. The exact syntax of that information is application-dependent; the anvil(8) server does not care.

CONNECTION COUNT/RATE CONTROL

To register a new connection send the following request to the anvil(8) server:

request=connect

ident=string

The anvil(8) server answers with the number of simultaneous connections and the number of connections per unit time for the (service, client) combination specified with ident:

status=0

count=number

rate=number

To register a disconnect event send the following request to the anvil(8) server:

request=disconnect

ident=string

The anvil(8) server replies with:

   status=0

MESSAGE RATE CONTROL

To register a message delivery request send the following request to the anvil(8) server:

request=message

ident=string

The anvil(8) server answers with the number of message delivery requests per unit time for the (service, client) combination specified with ident:

status=0

rate=number

RECIPIENT RATE CONTROL

To register a recipient request send the following request to the anvil(8) server:

request=recipient

ident=string

The anvil(8) server answers with the number of recipient addresses per unit time for the (service, client) combination specified with ident:

status=0

rate=number

TLS SESSION NEGOTIATION RATE CONTROL

LPI Study Material, LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Guides
The features described in this section are available with Postfix 2.3 and later.

To register a request for a new (i.e. not cached) TLS session send the following request to the anvil(8) server:

request=newtls

ident=string

The anvil(8) server answers with the number of new TLS session requests per unit time for the (service, client) combination specified with ident:

status=0

rate=number

To retrieve new TLS session request rate information without updating the counter information, send:

request=newtls_report

ident=string

The anvil(8) server answers with the number of new TLS session requests per unit time for the (service, client) combination specified with ident:

status=0

rate=number

SECURITY

The anvil(8) server does not talk to the network or to local users, and can run chrooted at fixed low privilege.

The anvil(8) server maintains an in-memory table with information about recent clients requests. No persistent state is kept because standard system library routines are not sufficiently robust for update-intensive applications.

Although the in-memory state is kept only temporarily, this may require a lot of memory on systems that handle connections from many remote clients. To reduce memory usage, reduce the time unit over which state is kept.

Thursday, 12 November 2020

5 UNIX / Linux Anacron Command Example for Background Jobs

LPI Exam Prep, LPI Tutorial and Material, LPI Guides, LPI Certification

The main advantage of anacron is that you don’t need to have the system be up and running always to execute the background jobs.

This is very helpful when you want to run background jobs on laptops, which might not be available 24×7. But, you still can schedule routine jobs on these machines using anacron.

This way whenever the laptop starts again, any pending scheduled jobs will be executed by anacron

1. Test Anacron Syntax

All anacron jobs are located under /etc/anacrontab file as shown below:

# cat /etc/anacrontab

1       5       cron.daily              nice run-parts /etc/cron.daily

7       25      cron.weekly             nice run-parts /etc/cron.weekly

@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

@bimonthly 45   cron.bimonthly          nice run-parts /etc/cron.bimonthly

In the above example, the last line is invalid, as the timeperiod “bimonthly” it not support by anacron.

So, you can check for any syntax error, or other issues with the anacrontab file using the following command.

This output indicates that we have an unknown name period in the file.

# anacron -T

anacron: /etc/anacrontab: Unknown named period on line 17, skipping

If you have your own crontab file, you can test that syntax using -T -t and specifying your custom anacrontab file name as shown below.

# anacron -T -t /etc/myanacron

anacron: Invalid syntax in /etc/myanacron on line 14 - skipping this line

anacron: Invalid syntax in /etc/myanacron on line 15 - skipping this line

2. Custom Spool directory

Apart from specifying your own anacrontab file, you can also specify your own spool directory for anacron. This is helpful when you are testing some anacron jobs, and don’t want to messup the standard anacrontab file and spool directory.

The following uses /root/myspool to store all the timestamp information for the jobs that are defined in the /etc/myanacron file.

# anacron -S /root/myspool -t /etc/myanacron

# ls -altr /root/myspool/

total 8

dr-xr-x---. 9 root root 4096 Jan 31 23:35 ..

-rw-------. 1 root root    0 Jan 31 23:36 myjob

drwxr-xr-x. 2 root root 4096 Jan 31 23:36 .

The default spool directory is /var/spool/anacron as shown below, which stores the timestamp for the jobs from the /etc/anacrontab file.

# ls -l /var/spool/anacron

total 16

-rw-------. 1 root root 9 Jan 31 23:56 cron.daily

-rw-------. 1 root root 9 Jan 31 23:56 cron.monthly

-rw-------. 1 root root 9 Jan 31 23:56 cron.weekly

They typically store the information on when was this particular job last executed:

# cat /var/spool/anacron/cron.daily

20140131

# cat /var/spool/anacron/cron.monthly

20140131

3. Run Anacron in the Foreground

You can also run the anacron in the foreground. Sometime this is easy, as you can see the output on the screen itself. This is good for checking something very quick during testing purpose.

For example, when you don’t give -d option, anacron forks a background jobs, and it will just not display anything on the screen. This example, just updates the timestamp for the jobs, but really doesn’t execute anything. You won’t know what really happened.

# anacron -u

But, when you run the anacron in the foreground, using -d option, you can see what it is doing. Don’t do this when you have jobs that will run for long period of time.

# anacron -d -u

Updated timestamp for job `cron.daily' to 2014-01-31

Updated timestamp for job `cron.weekly' to 2014-01-31

Updated timestamp for job `cron.monthly' to 2014-01-31

4. Force the Job Execution

LPI Exam Prep, LPI Tutorial and Material, LPI Guides, LPI Certification
The -f option will do a force execution of the jobs. But this will still consider the delay specs that you’ve set in the anacrontab file.

# anacron -d -f

Anacron started on 2014-01-31

Will run job `cron.daily' in 24 min.

Will run job `cron.weekly' in 44 min.

Will run job `cron.monthly' in 64 min.

However, -n option will execute the job immediately. This will not consider any delay specs that you’ve set in the anacrontab file. Please note that -n option also implies -s option.

# anacron -d -n

Anacron started on 2014-01-31

Checking against 0 with 31

Normal exit (0 jobs run)

5. Specify a Job Name

If you have defined multiple jobs in the anacrontab file, you can execute only a specific job by specifying its job name.

In the following example, it will execute only the job with the name “myjob” from the custom /etc/myanacron tab file.

# anacron -f -d -t /etc/myanacron myjob

Anacron started on 2014-01-31

Will run job `myjob' in 1 min.

Job `myjob' started

Job `myjob' terminated

Normal exit (1 job run)

Tuesday, 10 November 2020

Difference between Linux and Windows

LPI Exam Prep, LPI Tutorial and Material, LPI Prep, LPI Certification, LPI Guides

Linux:

Linux could be a free and open supply OS supported operating system standards. It provides programming interface still as programme compatible with operating system primarily based systems and provides giant selection applications. A UNIX operating system system additionally contains several severally developed parts, leading to UNIX operating system that is totally compatible and free from proprietary code.

Read More: LPI Certification

LPI Exam Prep, LPI Tutorial and Material, LPI Prep, LPI Certification, LPI Guides


Windows:

Windows may be a commissioned OS within which ASCII text file is inaccessible. it’s designed for the people with the angle of getting no programming information and for business and alternative industrial users. it’s terribly straightforward and simple to use.

The distinction between Linux and Windows package is that Linux is completely freed from price whereas windows is marketable package and is expensive. Associate operating system could be a program meant to regulate the pc or computer hardware Associate behave as an treater between user and hardware.

Linux is a open supply package wherever users will access the ASCII text file and might improve the code victimisation the system. On the opposite hand, in windows, users can’t access ASCII text file, and it’s a authorized OS.

Let’s see that the difference between Linux and windows:

LINUX WINDOWS 
Linux is a open source operating system. While windows are the not the open source operating system.
Linux is free of cost. While it is costly.
It’s file name case-sensitive. While it’s file name is case-insensitive.
In linux, monolithic kernel is used. While in this, micro kernel is used.
Linux is more efficient in comparison of windows.  While windows are less efficient.
There is forward slash is used for Separating the directories. While there is back slash is used for Separating the directories.
Linux provides more security than windows. While it provides less security than linux.
Linux is widely used in hacking purpose based systems. While windows does not provide much efficiency in hacking.

Saturday, 7 November 2020

How to Contribute to an Open Source Project

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

It is great to see that the strategic relevance of open source software for the software industry is rapidly increasing (e.g. shown by IBM and Microsoft investing heavily into open source) and companies as well as individuals increasingly acknowledge the importance and advantages of open source.

One of the special things about an open source project is the amazing open source community. Open source software solutions manage to gather a community of developers and users around them. Ideally, they are actively involved in testing, developing and promoting the product. A diverse global community can generate more ideas, report and fix bugs, develop and troubleshoot faster than an internal team. Also, a free software can easily be adapted to fit exactly your needs. And with every improvement by an individual, a big user community will benefit.

That is why I want to encourage you to contribute to open source software. And it is not only about software developers to contribute new product features or the likes. Everyone can contribute in different ways and the product evolves with every contribution. Even as a less tech savvy person you can bring a lot to the table.

As I am one of the founders of the open source project management software OpenProject, I would like to use it as an example to show you how you can contribute to open source software, even if you don’t have a technical background.

OpenProject is free and open source software. The Community version can be downloaded and installed for free. We recommend the packaged installation of OpenProject with a compatible Linux distribution. The OpenProject Enterprise on-premises offers additional premium features and comes as an upgrade to your on-site Community installation. With the Enterprise Cloud, OpenProject does the hosting for you and the premium features are also included.

All three OpenProject versions are open source and will benefit from your contribution. Let’s take a look at what you can do for the OpenProject community or for any other open source project.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Make a difference with user support

Each open source project will benefit from dedicated user support. This is where you can step in. Our community forum is at the heart of OpenProject. This is where we connect with you and you can connect with other users, ask any question you want and support other OpenProject users. Topics like OpenProject development, support, plugins, general topics are discussed.

You can contribute by sharing your OpenProject experience with other users and help them thrive with their projects. Together we keep the conversation going.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Share your ideas for new features

New ideas about features or improvements are always worth sharing with the open source community to improve the product. You are using OpenProject and discover a feature that we haven’t on our roadmap yet but would be beneficial for your project management? Please let us know and open a ticket for a feature idea. You are also welcome to go through the feature ideas and comment on the ones created by someone else that you would also wish for. We are reviewing all feature requests and evaluate them by relevance and effort and then include them into our product roadmap for the upcoming releases. We want to give you as much transparency as possible, hence you can track the progress of all feature requests. We have also documented our product development process in order to make it as clear as possible how new features are being prioritized.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Create relevant content for the community

The open source community is there to learn from each other, share your thoughts on topics that interest you, the community will appreciate it. We love to exchange topics and views with our users and the open source community to inspire and share knowledge.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Help to improve the product with bug reporting

Open source software can be superior because of an active community that is involved to find and report bugs that will still appear despite extensive testing by the development team. Nobody is perfect. If you are an OpenProject user and encounter a behavior that you had not expected, we welcome you to report this bug. We have easy instructions on how you can report the bug here. Don’t be afraid to report a bug with less technical explanations, we attend to all tickets and are looking forward to improving OpenProject with your help.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Be the first to test new features

In order to identify possible bugs before releasing a new version, the open source community is invited to beta test new releases. You can also support OpenProject with testing. We have a quality assurance environment that is always at the latest stage of development. Just register an account and then you can test the new features that we are working on before they go live for everyone. You can for example take a work package of the next OpenProject release and test it. If you find any bugs while testing, report it as described above.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Support others by contributing to the documentation

Not only the software itself but also the documentation of an open source software can be open for collaboration. We have an extensive OpenProject documentation and are aiming to make it as complete as possible. Nevertheless, you might find some aspects missing or not detailed enough. Please feel free to add to the documentation regarding additional sections, screenshots or whatever can help yourself and our users to improve the usage of OpenProject.

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Translate into your mother tongue

The open source community is global and speaks many languages. English is spoken by most but nevertheless everyone is most comfortable in their mother tongue. Thus, contributions in different languages are always welcome in the open source community. Are you native in any other language than German or English? OpenProject is used worldwide and already available in more than 40 languages but there is still a lot to do. We would be very glad if you contributed with more translations. 

LPI Certification, LPI Exam Prep, LPI Prep, LPI Tutorial and Material, LPI Guides

Enjoy the freedom to add new features with your development

The first thing you think about when you hear contribution to open source software is usually software development. I spoke mostly about non-developmental contribution as it is less talked about but such an integral part of the open source community. Nevertheless, I would like to invite the software developers to contribute as well. Our development guide will give you an overview of what options there are and how to develop for OpenProject. If you are rather new to OpenProject, we have created a feature list for you that contains features that are relatively easy to develop.

Source: lpi.org

Thursday, 5 November 2020

AWK command in Unix/Linux with examples

AWK Command, AWK Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Exam Prep

Awk is a scripting language used for manipulating data and generating reports.The awk command programming language requires no compiling, and allows the user to use variables, numeric functions, string functions, and logical operators.

Awk is a utility that enables a programmer to write tiny but effective programs in the form of statements that define text patterns that are to be searched for in each line of a document and the action that is to be taken when a match is found within a line. Awk is mostly used for pattern scanning and processing. It searches one or more files to see if they contain lines that matches with the specified patterns and then performs the associated actions.

Awk is abbreviated from the names of the developers – Aho, Weinberger, and Kernighan.

WHAT CAN WE DO WITH AWK ?

1. AWK Operations:

(a) Scans a file line by line

(b) Splits each input line into fields

(c) Compares input line/fields to pattern

(d) Performs action(s) on matched lines

2. Useful For:

(a) Transform data files

(b) Produce formatted reports

3. Programming Constructs:

(a) Format output lines

(b) Arithmetic and string operations

(c) Conditionals and loops

Syntax:

awk options 'selection _criteria {action }' input-file > output-file

Options:

-f program-file : Reads the AWK program source from the file 

                  program-file, instead of from the 

                  first command line argument.

-F fs            : Use fs for the input field separator

Sample Commands

Example:

Consider the following text file as the input file for all cases below.

$cat > employee.txt 

ajay manager account 45000

sunil clerk account 25000

varun manager sales 50000

amit manager account 47000

tarun peon sales 15000

deepak clerk sales 23000

sunil peon sales 13000

satvik director purchase 80000 

1. Default behavior of Awk: By default Awk prints every line of data from the specified file.

$ awk '{print}' employee.txt

Output:

ajay manager account 45000

sunil clerk account 25000

varun manager sales 50000

amit manager account 47000

tarun peon sales 15000

deepak clerk sales 23000

sunil peon sales 13000

satvik director purchase 80000 

In the above example, no pattern is given. So the actions are applicable to all the lines. Action print without any argument prints the whole line by default, so it prints all the lines of the file without failure.

2. Print the lines which matches with the given pattern.

$ awk '/manager/ {print}' employee.txt 

Output:

ajay manager account 45000

varun manager sales 50000

amit manager account 47000 

In the above example, the awk command prints all the line which matches with the ‘manager’.

3. Splitting a Line Into Fields : For each record i.e line, the awk command splits the record delimited by whitespace character by default and stores it in the $n variables. If the line has 4 words, it will be stored in $1, $2, $3 and $4 respectively. Also, $0 represents the whole line.

$ awk '{print $1,$4}' employee.txt 

Output:

ajay 45000

sunil 25000

varun 50000

amit 47000

tarun 15000

deepak 23000

sunil 13000

satvik 80000 

In the above example, $1 and $4 represents Name and Salary fields respectively.

Built In Variables In Awk

Awk’s built-in variables include the field variables—$1, $2, $3, and so on ($0 is the entire line) — that break a line of text into individual words or pieces called fields.

NR: NR command keeps a current count of the number of input records. Remember that records are usually lines. Awk command performs the pattern/action statements once for each record in a file.

NF: NF command keeps a count of the number of fields within the current input record.

FS: FS command contains the field separator character which is used to divide fields on the input line. The default is “white space”, meaning space and tab characters. FS can be reassigned to another character (typically in BEGIN) to change the field separator.

RS: RS command stores the current record separator character. Since, by default, an input line is the input record, the default record separator character is a newline.

OFS: OFS command stores the output field separator, which separates the fields when Awk prints them. The default is a blank space. Whenever print has several parameters separated with commas, it will print the value of OFS in between each parameter.

ORS: ORS command stores the output record separator, which separates the output lines when Awk prints them. The default is a newline character. print automatically outputs the contents of ORS at the end of whatever it is given to print.

Examples:

Use of NR built-in variables (Display Line Number)

$ awk '{print NR,$0}' employee.txt 

Output:

1 ajay manager account 45000

2 sunil clerk account 25000

3 varun manager sales 50000

4 amit manager account 47000

5 tarun peon sales 15000

6 deepak clerk sales 23000

7 sunil peon sales 13000

8 satvik director purchase 80000 

In the above example, the awk command with NR prints all the lines along with the line number.

Use of NF built-in variables (Display Last Field)

$ awk '{print $1,$NF}' employee.txt 

Output:

ajay 45000

sunil 25000

varun 50000

amit 47000

tarun 15000

deepak 23000

sunil 13000

satvik 80000 

AWK Command, AWK Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Exam Prep

In the above example $1 represents Name and $NF represents Salary. We can get the Salary using $NF , where $NF represents last field.

Another use of NR built-in variables (Display Line From 3 to 6)

$ awk 'NR==3, NR==6 {print NR,$0}' employee.txt 

Output:

3 varun manager sales 50000

4 amit manager account 47000

5 tarun peon sales 15000

6 deepak clerk sales 23000 

More Examples

For the given text file:

$cat > lpicentral.txt

A    B    C

Tarun    A12    1

Man    B6    2

Mahesh    M42    3

1) To print the first item along with the row number(NR) separated with ” – “ from each line in lpicentral.txt:

$ awk '{print NR "- " $1 }' lpicentral.txt

1 - Tarun

2 – Manav    

3 - Mahesh

2) To return the second row/item from lpicentral.txt:

$ awk '{print $2}' lpicentral.txt

A12

B6

M42

3) To print any non empty line if present

$ awk 'NF > 0' lpicentral.txt

0

4) To find the length of the longest line present in the file:

$ awk '{ if (length($0) > max) max = length($0) } END { print max }' lpicentral.txt

13

5) To count the lines in a file:

$ awk 'END { print NR }' lpicentral.txt

3

6) Printing lines with more than 10 characters:

$ awk 'length($0) > 10' lpicentral.txt

Tarun    A12    1

Mahesh    M42    3

7) To find/check for any string in any column:

$ awk '{ if($3 == "B6") print $0;}' lpicentral.txt

8) To print the squares of first numbers from 1 to n say 6:

$ awk 'BEGIN { for(i=1;i<=6;i++) print "square of", i, "is",i*i; }'

square of 1 is 1

square of 2 is 4

square of 3 is 9

square of 4 is 16

square of 5 is 25

square of 6 is 36

Tuesday, 3 November 2020

Join Command in Unix/Linux Examples

Join Command, Linux Command, Unix Command, Command Line

Join command is one of the text processing utility in Unix/Linux. Join command is used to combine two files based on a matching fields in the files. If you know SQL, the join command is similar to joining two tables in a database.

The syntax of join command is

join [options] file1 file2

The join command options are

-1 field number : Join on the specified field number in the first file
-2 field number : Join on the specified field number in the second file
-j field number : Equivalent to -1 fieldnumber and -2 fieldnumber
-o list : displays only the specified fields from both the files
-t char : input and output field delimiter
-a filenumber : Prints non matched lines in a file
-i : ignore case while joining

Unix Join Command Examples


1. Write a join command to join two files on the first field?

The basic usage of join command is to join two files on the first field. By default the join command matches the files on the first fields when we do not specify the field numbers explicitly. Let's say we have two files emp.txt and dept.txt

> cat emp.txt
10 mark
10 steve
20 scott
30 chris
> cat dept.txt
10 hr
20 finance
30 db

Here we will join on the first field and see the output. By default, the join command treats the field delimiter as space or tab.

> join emp.txt dept.txt
10 mark hr
10 steve hr
20 scott finance
30 chris db

Important Note: Before joining the files, make sure to sort the fields on the joining fields. Otherwise you will get incorrect result.

2. Write a join command to join the two files? Here use the second field from the first file and the first field from the second file to join.

In this example, we will see how to join two files on different fields rather than the first field. For this consider the below two files as an example

> cat emp.txt
mark 10 1
steve 10 1
scott 20 2
chris 30 3
> cat dept.txt
10 hr 1
20 finance 2
30 db 3

From the above, you can see the join fields are the second field from the emp.txt and the first field from the dept.txt. The join command to match these two files is

> join -1 2 -2 1 emp.txt dept.txt
10 mark 1 hr 1
10 steve 1 hr 1
20 scott 2 finance 2
30 chris 3 db 3

You can also see that the two files can also be joined on the third filed. As the both the files have the matching join field, you can use the j option in the join command.

Here -1 2 specifies the second field from the first file (emp.txt) and -2 1 specifies the first field from the second file (dept.txt)

> join -j 3 emp.txt dept.txt
1 mark 10 10 hr
1 steve 10 10 hr
2 scott 20 20 finance
3 chris 30 30 db

3. Write a join command to select the required fields from the input files in the output? Select first filed from first file and second field from second file in the output.

By default, the join command prints all the fields from both the files (except the join field is printed once). We can choose what fields to be printed on the terminal with the -o option. We will use the same files from the above example.

> join -o 1.1 2.2 -1 2 -2 1 emp.txt dept.txt
mark hr
steve hr
scott finance
chris db

Here 1.1 means in the first file select the first field. Similarly, 2.2 means in the second file select the second field

4. Write a command to join two delimited files? Here the delimiter is colon (:)

So far we have joined files with space delimiter. Here we will see how to join files with a colon as delimiter. Consider the below two files.

> cat emp.txt
mark:10
steve:10
scott:20
chris:30
> cat dept.txt
10:hr
20:finance
30:db

The -t option is used to specify the delimiter. The join command for joining the files is

> join -t: -1 2 -2 1 emp.txt dept.txt
10:mark:hr
10:steve:hr
20:scott:finance
30:chris:db

5. Write a command to ignore case when joining the files?

If the join fields are in different cases, then the join will not be performed properly. To ignore the case in join use the -i option.

> cat emp.txt
mark,A
steve,a
scott,b
chris,C
> cat dept.txt
a,hr
B,finance
c,db

> join -t, -i -1 2 -2 1 emp.txt dept.txt
A,mark,hr
a,steve,hr
b,scott,finance
C,chris,db

6. Write a join command to print the lines which do not match the values in joining fields?

Join Command, Linux Command, Unix Command, Command Line

By default the join command prints only the matched lines from both the files which means prints the matched lines that passed the join condition. We can use the -a option to print the non-matched lines.

> cat P.txt
A 1
B 2
C 3
> cat Q.txt
B 2
C 3
D 4

Print non pairable lines from first file.

> join -a 1 P.txt Q.txt
A 1
B 2 2
C 3 3

Print non pairable lines from second file.

> join -a 2 P.txt Q.txt
B 2 2
C 3 3
D 4

Print non pairable lines from both file.

> join -a 1 -a 2 P.txt Q.txt
A 1
B 2 2
C 3 3
D 4