background preloader

Linux

Facebook Twitter

Server

Virtual. Analyzer. Home. Tutorial. Admin. Linux KVM Virtualization Performance. Bash Arrays. If you're used to a "standard" *NIX shell you may not be familiar with bash's array feature. Although not as powerful as similar constructs in the P languages (Perl, Python, and PHP) and others, they are often quite useful. Bash arrays have numbered indexes only, but they are sparse, ie you don't have to define all the indexes. An entire array can be assigned by enclosing the array items in parenthesis: arr=(Hello World) Individual items can be assigned with the familiar array syntax (unless you're used to Basic or Fortran): arr[0]=Hello arr[1]=World But it gets a bit ugly when you want to refer to an array item: echo ${arr[0]} ${arr[1]} To quote from the man page: The braces are required to avoid conflicts with pathname expansion.

In addition the following funky constructs are available: ${arr[*]} # All of the items in the array ${! The ${! The following example shows some simple array usage (note the "[index]=value" assignment to assign a specific index): Running it produces the following output: LOGINFAILURE.PL - Block IPs where failed login attempts originate. Download this program loginfailure.pl -summary # Show failing IPs loginfailure.pl -denyip 192.168.1.4 # Block this IP loginfailure.pl -allowip 192.168.1.4 # Stop blocking this IP loginfailure.pl /var/log/messages # Check file for offending IPs loginfailure.pl -daemon 60 /var/log/secure loginfailure.pl -failures 4 -daemon 60 /var/log/secure* Many times production Unix machines cannot restrict login access by IP address.

This program was written to help identify those cracking attempts and block the intruder. This program typically runs as a daemon, frequently reading the log files, updating its tables and when necessary, rewriting the hosts.deny file. Alternatively, the program may be run as a cron entry. The idea behind this program is that once an IP address is found to have enough login failures, you want to block it for a relatively short period (-denytime) and then later unblock the IP address (-purgetime).

-allowip ip -daemon S -db file -denyip ip -denytime TIME -detail -etcdeny file -failures N. Mpiling "C" And "C++" Programs On Unix Systems - gcc/g++ [ LUPG Home ] [ Tutorials ] [ Related Material ] [ Essays ] [ Project Ideas ] [ Send Comments ] v1.0.2 Table Of Contents: Preface - How To Read This Document This document tries to give the reader basic knowledge in compiling C and C++ programs on a Unix system. If you've no knowledge as to how to compile C programs under Unix (for instance, you did that until now on other operating systems), you'd better read this tutorial first, and then write a few programs before you try to get to gdb, makefiles or C libraries.

If you're already familiar with that, it's recommended to learn about makefiles, and then go and learn other C programming topics and practice the usage of makefiles, before going on to read about C libraries. This last issue is only relevant to larger projects, while makefiles make sense even for a small program composed of but a few source files. In this lovely tutorial, we'll deal with compilation of a C program, using the compiler directly from the command line. Single_main . RootPrompt -- Nothing but Unix. SENTINIX GNU/Linux distribution.