[lf icon]

Short Articles and Tips


1 C/C++ and Bitmap Files 2 Finding given String in files in a directory 3 Asynchronous I/O implementation for Red Hat Linux 9 .Relinking Oracle9iR2 to utilize AIO
4 A tour of the KDE Linux desktop. 5 Oracle9iR2 post installation procedure on a shrink-wrapped Red Hat 9 and the freely downloadable version. 6 cd writing in linux
7 Multithreaded HTTP Server for Linux 8 Implementation of a multithreaded RPC Server for Linux 9 using rpm2cpio to extract files from rpm package without install it
10 what to do when not able to login to Linux (forgottten the password) ? 11 Unzip and untar using redirection and pipe 12 Apache Redirect
13 Help for ADSL USB Modems ( in spanish) 14 Newbie guide for the net install of SuSe 8.2 15 colorize your coder's life
16 SMS alert when email arrive. 17 Samba 3, XFS, LVM and ACL's 18 Protect your email from Spambots
19 Searching for some string in all files of directory 20 alias parameters 21 Pasting text in vi looks horrible, solution?
22 Resetting Terminal/Shell 23 Linux Networking Guide 24 Resetting your terminal/shell window
25 EZ Email Security With Stunnel 26 Mounting ISO images (no CD-R required) 27 klick any key to continue
28 Swapping CTRL key with CAPS_LOCK key (X11 and console mode) 29 Having fun with BIND Version number. 30 Howto log in to your server passwordless via ssh ( rsa version )
31 http://www.portico.org/ 32 Removing ^M from file 33 Hide your Bind version
34 How to delete and recreate /tmp 35 Mojolin, The Linux Job Site, goes international 36 Blocking anyone to su to root
37 Disable rreboot,halt ,shutdown for users 38 Create /dev/null 39 How to create many subdirectories in one time
40 Translating articles from/to English, French, German and Spanish from within Netscape. 41 How to ispell a german text file? 42 How to easily shutdown your Linuxbox without beeing root?
43 How to delete all files from /tmp? 44 How to make Linux ignore a ping? 45 Resetting your terminal/shell window
46 Finding out what libraries a program requires 47 Mtools 48 Colors in the command prompt
49 2 vi tricks 50 Finding Netscape bookmarks  

Short articles can now be submitted directly online by everybody. Just click here and follow the instructions.


 
1)   category: UNIX Basics Language:English,  article number: 2006-02-13:1

C/C++ and Bitmap Files
by OULD MOHAMEDEN BABA Moctar , homepage: http://babasoft.4t.com

article image

BASIC C&BITMAP KNOWLEDGES 1


I-General Presentation :

This tutorial is for �Novice� C(or Unix Systems) users. It shows you how can you create and manipulate your own images with c programs. There is no special astuteness, it's easy to learn, to apprehend.


    1. BITMAP Images : the bitMap images or Raster Images are pixelled images, that means a collection of points(pixels) contained in a

      table, every point among them has one or many values describing its color. It's a MaP of bITs (x bits represent one pixel).

  1. Pixel : PIcture eLement. The pixel represents the tiniest element that constitute a numeric image. The collection of these pixels is contained in a 2d table (map) thats constitutes the image.

    Let's see a first example :

1.this is a bitmap image that contains the letter �a�


So, the image has a quality defined by it's definition, it's color ...

So, below you can have different images quality and the correspondent Memory Size of the file :

Image definition black and White(1 bit) 256 colors(8 bits) 65000 colors(16 bits) True color(24 bits)

320x200 7.8 KO 62.5 KO 125 KO 187.5 KO

640x480 37.5 KO 300 KO 600 KO 900 KO

800x600 58.6 KO 468.7 KO 937.5 KO 1.4 MO

1024x768 96 KO 768 KO 1.5 MO 2.3 MO

This shows the quantity of the video memory that needs your graphic card that is function of the screen definition (The number of showed Points) and of the colors number. The example shows that you must have at minimum a 4 MO video card memory to be able to show a 1024x768 resolution with true-color...





II-Let's attack the main subject :

So, in this second part, i will present the main subject, i.e how can you write your own images with a very simple c/c++ code??

do you know how i discovered all this? Very easy!! One night, at roughly 10:00pm, i was working on my favourite O.S Linux Mandrake 10.1 and i was testing some line commands. Suddenly, i found a program named bitmap i think, and i launched it, and i saved an image that i created without any extension. Later, i tried to open it and Kwrite launched it and i discovered that it was a c code : it was a bit map!!!

So, i taked many hours(no, i remember, it was 2 hours roughly) to understand such encoding : it wasn't difficult, but when you try in your first time, i can warrant you that it isn't easy.

In this first part of the TUTORIaL, we will ONLY talk about black and White images.

Let's take a first example. So, in first time we will work with a 16x16 bitMap image.

PIXeL 1 PIXeL 2



PIXeL 31 PIXeL 32

1.this is a 16x16 bitmap image that contains the letter �M�


In this example, we have a 16x16 bitmap image. That means that we have 16x16=2^8 = 256 points. So this image is composite of 32 pixels(each pixel is on 8bits). These pixels are situated, in growing order, from the top on left to the bottom on right.

each pixel constitutes 8 points(bits) in bIG-INdIaN order:

0 1 2 3 4 5 6 7









each case represents one bit value (0 or 1). each value holds different color(black or White).

1-If the bit holds 1, that means that the color is bLacK.

2-If the bit holds 0, that means that the color is WHITe.


So, we can say(look at the image) that aLL the IMaGe is simply a 32 characters vector that holds the pixels' values.

N.b : unsigned char <=> 8 bits.


So, now we can try to ReSUMe all THIS with a very very easy c/c++ code.

Let's see the previous example representing the Letter M :

#define fileName_height 16

#define fileName_width 16


static unsigned char fileName_bits[ ] = {

0x11,0x00,0x1b,0x00,0x15,0x00,0x11,0x00,0x11,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

}

1.this is a 16x16 bitmap image code in c/c++ that contains the letter �M�


Now, we will explain how we have this values. To write M (as an image : look at the schema), he will have:

    pixel 1 = �1000.1000� =(Inverse to have bIG-INdIaN) 00010001 = 0x11

    pixel 3 = �1101.1000� =(Inverse to have bIG-INdIaN) 00011011 = 0x1b

    pixel 5 = �1010.1000� =(Inverse to have bIG-INdIaN) 00010101 = 0x15

    pixel 7 = �1000.1000� =(Inverse to have bIG-INdIaN) 00010001 = 0x11

    pixel 9 = �1000.1000� =(Inverse to have bIG-INdIaN) 00010001 = 0x11

    aNd for each i != 1, 3, 5, 7, 9 pixel i = 0x00

Now, I'm trying to develop in JaVa, KYLIX or c++ a application that generate bitmap files that uses this method!!!

So, don't hesitate to help me by sending me mails [email protected]) or by signing my Guest book on my web site : www.babasoft.4t.com. Thank for you and the all Linuxfocus Team!!!


You can also find this tutorial on my web site : www.babasoft.4t.com/Tutorials/graphics/bitmap_c1.html


bY OULd MOHaMedeN baba Moctar....


 
2)   category: UNIX Basics Language:English,  article number: 2004-10-26:1

Finding given String in files in a directory
by saikrishna

If you are looking for a simple solution to search through the files in a given directory for a string .


This is done using find & grep.
find [directory : ex: / . /home/user] "*.fileex" -exec grep "string or pattern" {} \;

Example :
find . -name "*" -exec grep "PageFaultException" {} \;

The above command will search All files in the given directory for the string PageFaultException in it.

but this wont print the file name in which the pattern/string is found.
Now just add /dev/null before the \; & now filenames are displayed.

Example :
find . -name "*" -exec grep "PageFaultException" {} /dev/null \;

HTH
sai


 
3)   category: System Administration Language:English,  article number: 2004-09-08:1

Asynchronous I/O implementation for Red Hat Linux 9 .Relinking Oracle9iR2 to utilize AIO
by Boris Derzhavets [derzhavets[at]hotmail.com]

Installation of new kernel with AIO support and patched version of libaio library

1. rpm -i kernel-2.4.20-35.9.i686.rpm from http://atrpms.com
2. rpm -i libaio-0.3.93-4.src.rpm
3. cd /usr/src/redhat/SOURCES
4. gunzip libaio-0.3.93.tar.gz
5. tar xf libaio-0.3.93.tar -C /tmp
6. cd /tmp/libaio-0.3.93/src
7. Modify files:

 compat-0_1.c
 io_queue_init.c
 io_submit.c

as advised in [1],[2]
8.  cd /tmp
9.  tar cvf libaio-0.3.93.tar libaio-0.3.93
10. gzip libaio-0.3.93.tar
11. cp libaio-0.3.93.tar.gz /usr/src/redhat/SOURCES
12. rpmbuild -ba  /usr/src/redhat/SPECS/libaio.spec
13. cd /usr/src/redhat/RPMS/i386
14. rpm -i libaio-0.3.93-4.i386.rpm
15. Check for file /usr/lib/libaio.so.1 to appear
16. cd /lib
17. ln -s /usr/lib/libaio.so.1 libaio.so

Relinking Oracle to utilize AIO for filesystems

Shutdown Oracle:-

1. cd $ORACLE_HOME/rdbms/lib
2. make -f ins_rdbms.mk async_on
3. make -f ins_rdbms.mk ioracle
4. cd $ORACLE_HOME/dbs

Add to init.ora files of instances currently installed on box:-

disk_asynch_io=true
filesystem_io=asynch

Startup Oracle

References
1.http://www.hyperic.net/support/tech-notes/oracle-setup.htm
2.http://developer.osdl.org/daniel/libaio/patch.libaio-0.3-93.fix



 
4)   category: UNIX Basics Language:English,  article number: 2004-08-22:1

A tour of the KDE Linux desktop.
by Barney Matthews , homepage: http://www.tuxs.org

This guided tour of the Linux KDE desktop can be used to help orientate a new Linux user or given to a person expressing interest in Linux as an idea of what a Linux desktop looks like. This tour is written for the KDE 3.2 desktop on Knoppix 3.4 but can be used with any Linux distribution that includes the KDE desktop. By the end of this tour you should have an idea of where things are in KDE and be able to start a few everyday tasks. A printable PDF version is also available. Read more at tuxs.org


 
5)   category: UNIX Basics Language:English,  article number: 2004-07-24:1

Oracle9iR2 post installation procedure on a shrink-wrapped Red Hat 9 and the freely downloadable version.
by Boris Derzhavets [derzhavets[at]hotmail.com]

Start with rpmbuild of glibc-2.3.2-11.9.rpm following [1]:

  

1.Download from redhat.com required version of  src.rpm for glibc,
  supposedly   glibc-2.3.2-11.9.src.rpm
2. rpm   -i   glibc-2.3.2-11.9.src.rpm
3. cd /usr/src/redhat/SOURCES
4 bzip2  -dc glibc-2.3.2-200313.tar.bz2 | tar xf  -  -C  /tmp
5.cd /tmp/glibc-2.3.2-200313/locale
6. Comment out all compat_symbols lines from lc-ctype.c
7. cd ../ctype
8. Comment out all compat_symbols lines from ctype-info.c
9. cd ..;cd ..;pwd
   /tmp
10. tar cvf glibc-2.3.2-200313.tar glibc-2.3.2-200313
11. bzip2 glibc-2.3.2-200313.tar
12. cp glibc-2.3.2-200313.tar.bz2 /usr/src/redhat/SOURCES
13. cd /usr/src/redhat/SPECS
14. vi glbc-9.spec
15. Add to the end of glibcrelease line (line 1) ".oracle".
    Now  11.9 now looks as 11.9.oracle. Then save file.
16. rpmbuild �ba  /usr/src/redhat/SPECS/glbc-9.spec
In my case, at the end rpms were written to /usr/src/redhat/RPMS/i386 folder
17.Download from [1]:
Updated i386 RPMS
glibc-2.3.2-27.9.7.oracle.i386.rpm
glibc-common-2.3.2-27.9.7.oracle.i386.rpm
glibc-debug-2.3.2-27.9.7.oracle.i386.rpm
glibc-debuginfo-2.3.2-27.9.7.oracle.i386.rpm
glibc-debuginfo-common-2.3.2-27.9.7.oracle.i386.rpm
glibc-devel-2.3.2-27.9.7.oracle.i386.rpm
glibc-profile-2.3.2-27.9.7.oracle.i386.rpm
glibc-utils-2.3.2-27.9.7.oracle.i386.rpm
nscd-2.3.2-27.9.7.oracle.i386.rpm
AND
Updated i686 RPMS
glibc-2.3.2-27.9.7.oracle.i686.rpm
Start rmps upgrade based on predefined dependencies.
There are no any warnings in [1] regarding i386.rpms and
i686rpms dependencies:
   
[root@ServerDBS inst_patch]# rpm -Uvh glibc-2.3.2-27.9.7.oracle.i686.rpm \
  glibc-common-2.3.2-27.9.7.oracle.i386.rpm \
  glibc-utils-2.3.2-27.9.7.oracle.i386.rpm \
  glibc-debug-2.3.2-27.9.7.oracle.i386.rpm \
  glibc-devel-2.3.2-27.9.7.oracle.i386.rpm
Preparing...            ####################### [100%]
 1:glibc-common         ####################### [ 20%]
 2:glibc                ####################### [ 40%]
Stopping sshd:[  OK  ]
Starting sshd:[  OK  ]
 3:glibc-devel          ####################### [ 60%]
 4:glibc-utils          ####################### [ 80%]
 5:glibc-debug          ####################### [100%]
[root@ServerDBS inst_patch]# rpm -Uvh glibc-debuginfo-2.3.2-27.9.7.oracle.i386.rpm \
  glibc-debuginfo-common-2.3.2-27.9.7.oracle.i386.rpm
Preparing...            ########################## [100%]
   1:glibc-debuginfo-common ###################### [ 50%]
   2:glibc-debuginfo        ###################### [100%]
[root@ServerDBS inst_patch]# rpm -Uvh glibc-profile-2.3.2-27.9.7.oracle.i386.rpm \
    nscd-2.3.2-27.9.7.oracle.i386.rpm
Preparing...     ########################### [100%]
   1:nscd        ########################### [ 50%]
   2:glibc-profile   ####################### [100%]

At this point run as oracle (no information about this step in [1] ):
$make �f $ORACLE_HOME/network/lib/ins_oemagent.mk install
This time you will be succeed due to patched rpms have been installed.
Now dbsnmp is properly linked and will bring back to life "Intelligent Agent"
Then grab from $ORACLE_HOME/root.sh all commands required
to install right permissions for dbsnmp and dependent directories and
run them as root.
Next steps:
$agentctl start
$oemctl start oms
You are ready to run OEM console.
References:
1.http://mlug.missouri.edu/~jmcintosh/computers/oracle/redhat/9/rpms/
2.http://www.linuxdevcenter.com/pub/a/linux/2003/09/04/oracle_install.html


 
6)   category: UNIX Basics Language:English,  article number: 2004-07-10:4

cd writing in linux
by Avinash Tiwari , homepage: http://www.geocities.com/avitiw

Steps to burn multi-session CD in LINUX as root :

Step 1: Make ISO images
             $mkisofs -r  -o cdimage.raw files

Step 2: Burn Cd with cdrecord              
              $cdrecord -v -multi speed=4 dev=0,0,0 -data cdimage.raw

Step 3: Make ISO images to further add data to multi-session CD

             $ mkisofs -r  -o cdimage.raw -C a,b -M /dev/cdrom files
                  where a,b is the number the following command
                  gives
             $ cdrecord -msinfo dev=0,0,0

Step 4: Further Burning(Multi session) the CD
             $cdrecord -v -multi speed=4 dev=0,0,0 -data cdimage.raw

                  Note: The value 0,0,0 can be different for you. This
                  identifies your cd-writer. To get the number execute
                  following command as root
             
             $cdrecord -scanbus

             Also the value a,b in Step 3 will be different for 
             different sessions. The value for speed will depend upon 
             your CD-writer


 
7)   category: Software Development Language:English,  article number: 2004-06-16:1

Multithreaded HTTP Server for Linux
by Boris Derzhavets [derzhavets[at]hotmail.com]

Multithreaded HTTP Server for Linux built up by the pool of threads
utilizing select() system call.

Developing code bellow we follow general guidelines from [1] chapter 11.
The only one source file has been modified is server.c.
Instead of fork new process to handle each incoming client's connection,
as procedure server_run ( ) does in [1], we start pool of 1024 threads
accepting as parameter descriptor of passive socket.
The procedure run by each thread is asynchronous BSD socket's server utilizing
select() system call (see for example [2],chapter 13(5)) to switch between handling
incoming client's requests by accept() system call and receiving "http" requests
from clients already connected to server utilizing procedures
handle_request() and handle_get() from [1],chapter 11.
References
1.Mark Mitchel,Jeffrey Oldham,Alex Samuel. Advanced Linux Programming.
New Riders Publishing , 2001. www.advancedlinuxprogramming.com
2.Douglas E. Comer,David L. Stevens Internet Working with TCP/IP ,vol 3
Client-Server Programming and application Linux/Posix Socket Version,
Prentice Hall,Inc. 2001

/*
 *   server.c  module :- multithreaded version, starting pool of threads,
 *   multiplexing select( ) call, to serve new connections  
 *   utilizing accept() system call and "http" responds for clients 
 *   already connected to server simultaneously.
 */

#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include "server.h"
#define NUM_THREADS 1024 

pthread_mutex_t get_mutex=PTHREAD_MUTEX_INITIALIZER;

static char* not_found_response_template =
  "HTTP/1.0 404 Not Found\n"
  "Content-type: text/html\n"
  "\n"
  "<html>\n"
  " <body>\n"
  "  <h1>Not Found</h1>\n"
  "  <p>The requested URL %s was not found on this server.</p>\n"
  " </body>\n"
  "</html>\n";
                                                                                
                                                                                
static char* bad_method_response_template =
  "HTTP/1.0 501 Method Not Implemented\n"
  "Content-type: text/html\n"
  "\n"
  "<html>\n"
  " <body>\n"
  "  <h1>Method Not Implemented</h1>\n"
  "  <p>The method %s is not implemented by this server.</p>\n"
  " </body>\n"
  "</html>\n";
static char* ok_response =
  "HTTP/1.0 200 OK\n"
  "Content-type: text/html\n"
  "\n";
                                                                                
static char* bad_request_response =
  "HTTP/1.0 400 Bad Request\n"
  "Content-type: text/html\n"
  "\n"
  "<html>\n"
  " <body>\n"
  "  <h1>Bad Request</h1>\n"
  "  <p>This server did not understand your request.</p>\n"
  " </body>\n"
  "</html>\n";

void
die(const char *func, int err)
{
        fprintf(stderr,"%s: %s\n",func,strerror(err));
        abort();
}

static void handle_get (int connection_fd, const char* page)
{
  struct server_module* module = NULL;
  if (*page == '/' && strchr (page + 1, '/') == NULL) {
    char module_file_name[64];
    snprintf (module_file_name, sizeof (module_file_name),
              "%s.so", page + 1);
    module = module_open (module_file_name);
  }
                                                                                
  if (module == NULL) {
    char response[1024];
    snprintf (response, sizeof (response), not_found_response_template, page);
    write (connection_fd, response, strlen (response));
  }
  else {
    write (connection_fd, ok_response, strlen (ok_response));
    (*module->generate_function) (connection_fd);
    module_close (module);
  }
}
static void *
handle_connection (int fdSock)
{
int connection_fd = fdSock;
  char buffer[256];
  ssize_t bytes_read;
  bytes_read = read (connection_fd, buffer, sizeof (buffer) - 1);
  if (bytes_read > 0) {
    char method[sizeof (buffer)];
    char url[sizeof (buffer)];
    char protocol[sizeof (buffer)];
                                                                                
    buffer[bytes_read] = '\0';
    sscanf (buffer, "%s %s %s", method, url, protocol);
    while (strstr (buffer, "\r\n\r\n") == NULL)
      bytes_read = read (connection_fd, buffer, sizeof (buffer));
    if (bytes_read == -1) {
      close (connection_fd);
      return;
    }
    if (strcmp (protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) {
      write (connection_fd, bad_request_response,
             sizeof (bad_request_response));
    }
    else if (strcmp (method, "GET")) {
      char response[1024];
      snprintf (response, sizeof (response),
                bad_method_response_template, method);
      write (connection_fd, response, strlen (response));
    }
    else
       handle_get (connection_fd, url);
  }
  else if (bytes_read == 0)
      ;
  else {
    system_error ("read");
   }
close(connection_fd);
}

void *
serv_request(void *insock)
{
int msock = (int)insock;
struct sockaddr_in fsin;
fd_set rfds;
fd_set afds;
unsigned int alen;
int fd,nfds;
int rval;
socklen_t address_length;
struct sockaddr_in socket_address;

nfds=getdtablesize();

FD_ZERO(&afds);
FD_SET(msock,&afds);

while(1) {
 memcpy(&rfds,&afds,sizeof(rfds));
 if (select(nfds,&rfds,(fd_set *)0,(fd_set *)0,(struct timeval *)0) < 0)
          die("select()",errno);
 if (FD_ISSET(msock,&rfds)) {
  int ssock;
  alen=sizeof(fsin);
  /*
   Serving new incoming client's connection
  */
  pthread_mutex_lock(&get_mutex);
    ssock=accept(msock,(struct sockaddr *)&fsin,&alen);
  pthread_mutex_unlock(&get_mutex);
  if (ssock < 0)
    die ("accept()",errno);
  if (verbose) {
      socklen_t address_length;
                                                                                
      address_length = sizeof (socket_address);
      rval = getpeername (ssock, &socket_address, &address_length);
      assert (rval == 0);
      printf ("Thread '%d' accepted connection from %s\n",
              pthread_self(),inet_ntoa (socket_address.sin_addr));
    }
  FD_SET(ssock,&afds);
}
for (fd=0;fd < nfds; ++fd)
 if (fd != msock && FD_ISSET(fd,&rfds)) {
  printf("Thread '%d' responding request...\n",pthread_self());
  /*
   Serving client had been already connected to server
  */
  handle_connection(fd);
  FD_CLR(fd,&afds);
  }
 }
}


void
server_run(struct in_addr local_address,uint16_t port)
{
struct sockaddr_in socket_address;
int rval;
int server_socket;
int k;
/*
Getting socket's descriptor to be passed to 
each thread in the pool
*/
  server_socket = socket (PF_INET, SOCK_STREAM, 0);
  if (server_socket == -1)
    system_error ("socket");
  memset (&socket_address, 0, sizeof (socket_address));
  socket_address.sin_family = AF_INET;
  socket_address.sin_port = port;
  socket_address.sin_addr = local_address;
  rval = bind (server_socket, &socket_address, sizeof (socket_address));
  if (rval != 0)
    system_error ("bind");
  rval = listen (server_socket, 10);
  if (rval != 0)
    system_error ("listen");
 if (verbose) {
    socklen_t address_length;
    address_length = sizeof (socket_address);
    rval = getsockname (server_socket, &socket_address, &address_length);
    assert (rval == 0);
    printf ("server listening on %s:%d\n",
            inet_ntoa (socket_address.sin_addr),
            (int) ntohs (socket_address.sin_port));
  }

/*
Starting pool of threads building up HTTP server
*/

size_t stacksize;
pthread_t p_thread[NUM_THREADS];
pthread_attr_t attr;
   pthread_attr_init(&attr);
   stacksize = 500000;
   pthread_attr_setstacksize (&attr, stacksize);
   pthread_attr_getstacksize (&attr, &stacksize);

for(k=0; k<NUM_THREADS; k++) {
      pthread_create(&p_thread[k],&attr,serv_request,(void*)server_socket);
}
                                                                                        
pthread_attr_destroy(&attr);

for(k=0;k<NUM_THREADS;k++) {
        pthread_join(p_thread[k], NULL);
        printf("Completed join with thread %d\n",k);
      }
}



 
8)   category: Software Development Language:English,  article number: 2004-05-16:5

Implementation of a multithreaded RPC Server for Linux
by Boris A. Derzhavets [derzhavets[at]hotmail.com]


   Consider as an example (see. [1] chapter "Sun RPC")  
square_svc.c  for file square.x  to build multithreaded 
RPC Server for Linux. 

File square.x as in [1] Chapter "Sun RPC" follows bellow :

struct square_in {
 long arg1;
};
struct square_out {
 long res1;
};
program SQUARE_PROG {
  version SQUARE_VERS {
  square_out SQUAREPROC(square_in) = 1;
  } = 2 ;
} = 0x31230000;


Call rpcgen to generate server's , client's stubs,header file square.h
and square_xdr.c (remind key -A is not supported under Linux):

$ rpcgen -a -M square.x

Server's side procedures code:

/*
 *                                           ServerSideProc.c
*/
#include "square.h"
#include "stdio.h"
#include "stdlib.h"
#include "rpc/pmap_clnt.h"
#include "string.h"
#include "memory.h"
#include "sys/socket.h"
#include "netinet/in.h"

int request=0;

bool_t

squareproc_2_svc(square_in *inp,square_out *outp,struct svc_req *rqstp)
{
printf("Thread id = '%ld' started, arg = %d\n",pthread_self(),inp->arg1);
sleep(5);
outp->res1=inp->arg1*inp->arg1;
printf("Thread id = '%ld' is done %d \n",pthread_self(),outp->res1);
return(TRUE);
}
int 
square_prog_2_freeresult(SVCXPRT *transp,xdrproc_t xdr_result,
 caddr_t result)
{
xdr_free(xdr_result,result);
return(1);
}


Modified code square_svc.c:

/*                                                          square_svc.c
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#include "square.h"
#include "stdio.h"
#include "stdlib.h"
#include "rpc/pmap_clnt.h"
#include "string.h"
#include "memory.h"
#include "sys/socket.h"
#include "netinet/in.h"

#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif

pthread_t p_thread;
pthread_attr_t attr;

                                
/* Procedure to be run by thread */

void *
serv_request(void *data)
{
struct thr_data
{
struct svc_req *rqstp;
SVCXPRT *transp;
} *ptr_data;

{

   union {
                square_in squareproc_2_arg;
   } argument;
   union {
                square_out squareproc_2_res;
   } result;
   bool_t retval;
   xdrproc_t _xdr_argument, _xdr_result;
   bool_t (*local)(char *, void *, struct svc_req *);

/*
Unpack data from structure
*/

ptr_data = (struct thr_data  *)data;
struct svc_req *rqstp = ptr_data->rqstp;
register SVCXPRT *transp = ptr_data->transp;

                                                                                                   
        switch (rqstp-"rq_proc) {
        case NULLPROC:
                (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
                return;
                                                                                                   
        case SQUAREPROC:
                _xdr_argument = (xdrproc_t) xdr_square_in;
                _xdr_result = (xdrproc_t) xdr_square_out;
                local = (bool_t (*) (char *, void *,  struct svc_req *))squareproc_2_svc;
                break;
                                                                                                   
        default:
                svcerr_noproc (transp);
                return;
        }
        memset ((char *)&argument, 0, sizeof (argument));
        if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
                svcerr_decode (transp);
                return;
        }
      
/*
 Data are already prepared.
*/
        retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);

 if (retval " 0 && !svc_sendreply(transp, (xdrproc_t) _xdr_result, (char *)&result))      
   {
                svcerr_systemerr (transp);
       }
        if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
                fprintf (stderr, "%s", "unable to free arguments");
                exit (1);
        }
        if (!square_prog_2_freeresult (transp, _xdr_result, (caddr_t) &result))
                fprintf (stderr, "%s", "unable to free results");
        return;
}
}
                                
/* 

New code for square_prog_2

*/

static void
square_prog_2(struct svc_req *rqstp, register SVCXPRT *transp)
{
struct data_str 
{
struct svc_req *rqstp;
SVCXPRT *transp;
} *data_ptr=(struct data_str*)malloc(sizeof(struct data_str));

{

/*
Paking data into structure in order to pass pointer to structure
to pthread_create( ). Starting  thread as detached
*/

data_ptr->rqstp = rqstp;
data_ptr->transp = transp;
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); 
pthread_create(&p_thread,&attr,serv_request,(void *)data_ptr);
 }
}

int
main (int argc, char **argv)
{
	register SVCXPRT *transp;

	pmap_unset (SQUARE_PROG, SQUARE_VERS);

	transp = svcudp_create(RPC_ANYSOCK);
	if (transp == NULL) {
		fprintf (stderr, "%s", "cannot create udp service.");
		exit(1);
	}
	if (!svc_register(transp, SQUARE_PROG, SQUARE_VERS, square_prog_2, IPPROTO_UDP)) {
		fprintf (stderr, "%s", "unable to register (SQUARE_PROG, SQUARE_VERS, udp).");
		exit(1);
	}

	transp = svctcp_create(RPC_ANYSOCK, 0, 0);
	if (transp == NULL) {
		fprintf (stderr, "%s", "cannot create tcp service.");
		exit(1);
	}
	if (!svc_register(transp, SQUARE_PROG, SQUARE_VERS, square_prog_2, IPPROTO_TCP)) {
		fprintf (stderr, "%s", "unable to register (SQUARE_PROG, SQUARE_VERS, tcp).");
		exit(1);
	}

	svc_run ();
	fprintf (stderr, "%s", "svc_run returned");
	exit (1);
	/* NOTREACHED */
}

Compile  ServerSQUARE:

$ gcc -o ServerSQUARE  ServerSideProc.c  square_svc.c square_xdr.c \
-lprthread    -lnsl






Client's side code:

/*          
*                                  ClientSideProc.c
*/

#include "memory.h" /* for memset */
#include "square.h"
#include "stdio.h"
#include "stdlib.h"
#include "rpc/pmap_clnt.h"
#include "string.h"
#include "memory.h"
#include "sys/socket.h"
#include "netinet/in.h"

int 
main (int argc,char **argv)
{
CLIENT *cl;
square_in in;
square_out out;
if (argc != 3 )
{ printf ("Usage : client "hostname" "integer_valus=e"\n");
  exit(1);
}
cl = clnt_create(argv[1],SQUARE_PROG,SQUARE_VERS,"tcp");
 if (cl == NULL) {
                clnt_perror (cl, "call failed");
                exit (1);
        }
in.arg1 = atol(argv[2]);
if (squareproc_2(&in,&out,cl) != RPC_SUCCESS)
{
   printf ("%s\n" , clnt_perror (cl,argv[1] ));
   exit(1);
}
printf("result: %ld\n",out.res1);
exit(0);
}





Compile  ClientSQUARE:

$ gcc -o  ClientSQUARE  ClientSideProc.c  square_clnt.c  square_xdr.c \
   -lprthread     -lnsl

Testing  (see [1]  ,chapter "SUN RPC"):

[root@dell4500 SQWMT]# cat square.bsh

./ClientSQUARE dell4500.redhat 10 & ./ClientSQUARE dell4500.redhat 11 & \
./ClientSQUARE dell4500.redhat 12 & ./ClientSQUARE dell4500.redhat 21 & \
./ClientSQUARE dell4500.redhat 13 & ./ClientSQUARE dell4500.redhat 14 & \
./ClientSQUARE dell4500.redhat 15 & ./ClientSQUARE dell4500.redhat 16 & \
./ClientSQUARE dell4500.redhat 17 & ./ClientSQUARE dell4500.redhat 18 & \
./ClientSQUARE dell4500.redhat 19 & ./ClientSQUARE dell4500.redhat 20 &


Output on client's side:

[root@dell4500 SQWMT]# ./square.bsh
[root@dell4500 SQWMT]# result: 196
result: 225
result: 256
result: 289
result: 121
result: 144
result: 441
result: 169
result: 100
result: 324
result: 361
result: 400

Output on Server's side:

[root@dell4501 SQWMT]# ./ServerSQUARE

Thread id = '1082453184' started, arg = 14
Thread id = '1090841664' started, arg = 15
Thread id = '1099230144' started, arg = 16
Thread id = '1116941120' started, arg = 17
Thread id = '1125329600' started, arg = 11
Thread id = '1133718080' started, arg = 12
Thread id = '1142106560' started, arg = 21
Thread id = '1150495040' started, arg = 13
Thread id = '1158883520' started, arg = 10
Thread id = '1167272000' started, arg = 18
Thread id = '1175660480' started, arg = 19
Thread id = '1184048960' started, arg = 20
Thread id = '1082453184' is done 196
Thread id = '1090841664' is done 225
Thread id = '1099230144' is done 256
Thread id = '1116941120' is done 289
Thread id = '1125329600' is done 121
Thread id = '1133718080' is done 144
Thread id = '1142106560' is done 441
Thread id = '1150495040' is done 169
Thread id = '1158883520' is done 100
Thread id = '1167272000' is done 324
Thread id = '1175660480' is done 361
Thread id = '1184048960' is done 400

                             References:
 
1.W.Richard Stevens.UNIX: Network Programming v 2.Interprocess communications. 
  Prentice Hall,1999


 
9)   category: UNIX Basics Language:English,  article number: 2004-02-25:2

using rpm2cpio to extract files from rpm package without install it
by slimzhao

rpm use cpio's archive format internally.

rpm itself can't extract single or bundle of files from a package.

rpm-XXXX.rpm provide a tool called rpm2cpio

that's it:

rpm2cpio your_package.rpm | cpio -di '*.doc'

this command extract all files match the pattern '*.doc', it's necessary to use single-quote to protect *. from globbing by shell

  • the pattern to use is for the full path string, not only the real file name, given a file
    './usr/share/pfaedit/pfaedit-es.ui'
    '*share/pfa*' will match it
  • never just use 'rpm2cpio your_package.rpm' to see what happen, rpm2cpio write the result to stdin, not a file with the same file name and .cpio as suffix, which probably most of you would expect.
  • always using -d parameter, or it's equivalent: --make-directories


 
10)   category: UNIX Basics Language:English,  article number: 2004-02-23:3

what to do when not able to login to Linux (forgottten the password) ?
by Abhinav Srivastava

Sometime it happens that user forgets its password (also the root password) and not able to login into the linux.

To login into the system, boot the linux and at the boot prompt type the following command:

linux -s

This will boot the linux in the single user mode and gives the root prompt to enter the new root password without asking the old one. Type following command at the prompt:


#passwd {give new password}

#exit

By typing the exit, normal boot process will continue and prompts the user for login/passsword.


 
11)   category: UNIX Basics Language:English,  article number: 2004-02-23:2

Unzip and untar using redirection and pipe
by Abhinav Srivastava

To restore the original file from *.tar.gz format, users normally run the following commands on UNIX:


1) gunzip *.tar.gz

2) tar -xvf *.tar

It can be done in one step and that is:

gunzip < test.tar.gz | tar xvf -

The above workes with any version of tar. If you have gnutar (the tar that comes with linux is gnu tar) then you can also use the -z option and tar will do it all for you:
tar -zxvf test.tar.gz



 
12)   category: UNIX Basics Language:English,  article number: 2004-01-29:1

Apache Redirect
by Edward Choi , homepage: http://www.cybersoul.org

Why redirect?
1) You're working for a web-hosting company and your client has all the top domains and wants to point his .net/.org domain to .com. You need to redirect .net/.org to his .com page.

2) You're working for a web-hosting company which provides "DNS Parking" with redirection service. Client wants to get a domain and redirect to his existing geocities homepage, you need to redirect to his geocities homepage.

Hardway:
You as an system administrator create his account as usual (with the hard way or by using some script). You created 3 accounts:

  • example.com
  • example.net
  • example.org
Redirect .net/org to .com with Javascript/PHP on the index page.

Easyway:
In your httpd.conf file or vhost.conf if you use Include, add in the Redirect directive:


<VirtualHost *>
        ServerAdmin [email protected]
        DocumentRoot /usr/vhost/example.org/httpdocs/
        RedirectPermanent / "http://www.example.com"
        ServerName www.example.org
        ServerAlias www.example.org example.org
</VirtualHost>


(You need mod_alias module loaded before you can use the Redirect directive)


 
13)   category: Hardware Language:English,  article number: 2004-01-16:1

Help for ADSL USB Modems ( in spanish)
by Alex

http://accessrunner.sourceforge.net/es/base.html


 
14)   category: UNIX Basics Language:English,  article number: 2003-11-15:2

Newbie guide for the net install of SuSe 8.2
by Crouse , homepage: http://www.usalug.org

This is my newbie guide for the net install of SuSe 8.2 Read through this entirely so you can familiarize yourself with the steps, and get the data you need to finish your install.

Since SuSe doesn't offer free iso download versions of SuSe, I decided to write this guide on how to do an ftp install (net install) of SuSe 8.2 since that is something that they do offer for free, but don't offer support. They do offer a "guide" to installing SuSe from the net, but it lacks detail and seems intentionally cryptic to me. I wanted to write a step by step guide to make things simpler so others don't have to search and search for hints on how it's done.

The first thing you need to do is select a place to download the boot.iso from. You can do that by searching here : http://www.suse.com/us/private/download/ftp/int_mirrors.html and selecting the closest location to you. I choose the ftp://ftp.rpmfind.net/linux/SuSE-Linux (Massachusetts, Boston).

Once I had that page up, I browsed to the ftp://ftp.rpmfind.net/linux/SuSE-Linux/i386/8.2/boot/ directory and downloaded the boot.iso file. Exact url to the boot iso : ftp://ftp.rpmfind.net/linux/SuSE-Linux/i386/8.2/boot/boot.iso (File Size 19.7 MB so that shouldn't take too long.)

After I had the boot iso downloaded, I burned that as an image. (I won't go into detail here, but there are many helpful tutorials on the net if you need help with that.)

Next, simply insert the disk into your computer, and reboot. You should be rewarded with a screen that displays some welcome message and then be forwarded on to the boot options screen. At this screen you should be able to choose from Installation

Choose Installation --- then hit the enter key. You should get a {Loading Linux Kernel...............} and then proceed to the next screen.

You should get to a MAIN MENU screen. Several options there. Starting with Settings. System Information. Kernel Modules. Start Installation. Exit/Reboot. Power Off.

Choose Settings first. Make sure your Language selection is correct. Then choose KERNEL MODULES and then select Load network card modules. Choose your network cards modules and load it.

If you need to load other modules do so here before proceeding. When that's done go back to the main menu and choose START INSTALLATION. Then Start Installation again....... hmmmmmmm Then choose the source medium (NETWORK). Then choose FTP. Then to enable your card to access the internet you need to choose AUTO CONFIG VIA DHCP or do it manually. I choose auto, since I'm on a dsl router that does DHCP.

Next is the hard part. You have to enter the IP ADDRESS of the FTP server. It took me several trys to figure this out. But after a little research, I found that the IP address can be had via the DIG command on Linux.

You must use the dig command in a terminal to find the IP address of whatever FTP server your using. I was using the ftp.rpmfind.net FTP server. Using the dig command : dig ftp.rpmfind.net returns two IP addresses. 216.254.0.38 and 194.199.20.114 Enter one of these numbers into the box asking for the IP address. After hitting enter it asks you if you want to specify a username and password, just say no. Then it asks if you want to use a Http proxy. Say NO again.

If things have went right so far it should say "trying to connect to ftp server". Once connected it says "Please enter the directory on the server"

For the rpmfind.net ftp server the correct entry would be: linux/6/SuSE-Linux/i386/8.2/

You should then see a small screen that says "Loading data into ramdisk (45800 kB) WOOT..... the hard part of the install, getting connected, is over!!

After that data is downloaded into the RAM disk, you will be greeted with the YaST Installation and System administration program.

The first thing you get to do is choose your language again. Then Yast detects hardware and checks to see if you want to load those drivers/modules. Choosing yes to detected hardware seems like a no brainer to me... so choose yes. The rest of the installation seems fairly straightforward and should be easy. The YaST installer has a very NICE partitioning tool.

At a minimum, you should probably have these partitions.

/boot small 50 mb
swap 500 mb unless you have alot of ram
/root 2+ gigs at least
/home the rest of the hard drive...or dedicate more to other partitions and root.

The net install once it begins does take some time, even with fast connections. The servers are all running and alot of time are running at full capacity. My connection, installing KDE and the rest of the default install, takes about 4 hours or a little more. I set it up to start downloading the packages right before I go to bed

Wake up and finish the install, setting root password, users, graphic card settings, and that's about it. Reboot and you get rewarded with a SuSe 8.2 Linux Desktop workstation !! I'm very impressed with the ease of use of the SuSe enviroment. I look forward to using it more and more.

I hope this short tutorial was useful to you. If so, let me know

Main Download Page
http://www.suse.com/us/private/download/suse_linux/index.html

SuSe Mirrors Page
http://www.suse.com/us/private/download/ftp/int_mirrors.html

The installation guideline
ftp://ftp.suse.com/pub/suse/i386/current/README.FTP

By Crouse
http://www.usalug.org
USA Linux Users Group
Original article posted :
http://www.usalug.org/phpBB2/viewtopic.php?t=524


 
15)   category: Applications Language:English,  article number: 2003-11-07:1

colorize your coder's life
by Nicolas Bouliane , homepage: http://www.skullbox.ca

Every body know vim ? visual iMproved !

if you are coding with vim, you can format your code to html

if you want to colorize your code

:syntax on

if you want to numerize your line

:set nu

to format your code to html

:so $VIMRUNTIME/syntax/2html.vim

now make a bash script and bash on your source code ;-)



 
16)   category: Applications Language:English,  article number: 2003-11-04:1

SMS alert when email arrive.
by Edward Choi , homepage: http://www.cybersoul.org

A short tutorial to get sms send to your mobile when you receive an email.

After you have compiled, the command to execute is: smssend [provider] [mobile no.] "[message]"
I will use qmail and my provider starhub as an example, you can use your favourite MTA and integrate with the script for your provider. I will edit ~vpopmail/domains/cybersoul.org/.qmail-edward and put the following in it:
/home/vpopmail/domains/cybersoul.org/edward/Maildir/ 
|smssend starhub 1234567 "You have new mail."
|preline procmail -t ./edward/Maildir/procmailrc
Done! Now when someone send me an email, i will receive a sms with the text: "You have new mail". You can do many other things that you want to send to your mobile with smssend.


 
17)   category: System Administration Language:English,  article number: 2003-10-20:1

Samba 3, XFS, LVM and ACL's
by Clark Mills [c.mills[at]auckland.ac.nz]

article image
Hi all.

What started out as a foray into experimenting with the newly released Samba 3, XFS, LVM and ACL's has panned out to be potentially of use beyond it's original requirements.

We, like everyone else, have daily backups. We also have people who delete work in progress, even though they might be saving every 5 minutes. What I describe at this web page is an experimental setup where there are snapshots taken every 30 minutes. Users can blow away folders and haul them back themselves. They can recover work they clobbered or deleted, assuming that they saved the file within the last 30 minutes. They can go back and grab a version 2 hours ago.

This may be of use to someone else, I can see it being useful to us. If nothing else the XFS/ACL/Samba should be of use. The snapshotting also has use with Unix/Linux users as well as the snapshotting could be applied to any filesystem. Indeed it's somewhat easier in the Unix/Linux world as the Samba layer just disappears.

It's also absolutely free ;) and transparent to the Windows users.

Enjoy & experiment.

        http://c.mills.ctru.auckland.ac.nz/Samba/XfsAclWinAuth.html
Cheers... Clark


 
18)   category: UNIX Basics Language:English,  article number: 2003-06-05:1

Protect your email from Spambots
by XPR , homepage: http://donot.net

What's so good about the �Do Not Disturb� anti-spam program ?

Donot.net (Do Not Disturb) web site provide an easy way to protect your email address from the Spam-Bots. These programs only purpose is to constantly comb the web in search of email addresses to add to their lists. In short, Donot.net takes your email address and encrypts it html code. So, when a spam-bot crawls your site, it just sees an html string that it doesn't understand. Your message isn't decrypted unless the user clicks on the link. Since it doesn�t use any javascript, every one can contact you.

But couldn't spammer design a spambot that decrypt it?

For sure they can do it. Thankfully Spam-Crawlers are in such a rush to keep up with the massive amount of web content that they ignore everything but the plain text of each site. Decrypt HTML code would be a waste of processor cycles to be worth it, but that efficiency will help to protect your email address. Anyway Donot.net doesn�t pretend to win the war against spammers alone but it makes their job harder.

http://donot.net


 
19)   category: UNIX Basics Language:English,  article number: 2003-05-03:1

Searching for some string in all files of directory
by Pawel Slabiak , homepage: http://www.linux-services.org

article image
If you are looking for some string(s), and you really don't know the name of file in which it could be, you can use a very simple grep command with some parameters: grep -rsniH your_string * r - recursive s - no messages n -line number i - case insensitve H -with filename for example: grep -rsniH pcmcia *



 
20)   category: UNIX Basics Language:English,  article number: 2002-05-21:1

alias parameters
by goeb

in bash, to use alias with one parameter, use !*
example:
> alias c 'cd /home/\!*'
> c elsa
> pwd
/home/elsa


 
21)   category: UNIX Basics Language:English,  article number: 2002-04-02:2

Pasting text in vi looks horrible, solution?
by Rene van Leeuwen

In some configurations, when you paste text in a vi-screen, it looks all horrible with increasing amounts of spaces and tabs in front of every line. What is wrong?
If you do :set, you probably see the property 'autoindent'. You can shut that off with :set noautoindent for the current vi-session and paste your text again.
A more permanent solution is to open the file ~/.vimrc and comment the line with 'set autoindent' (or set ai) out. Start vi again and the property 'autoindent' should be gone.

For people who use vim as a vi editor there is as well the possibility to use
:set paste
In case of vim this is better because vim has not just autoindent mode but as well smartindent and other indenting modes. :set paste resets all of those modes. When you are ready with pasting you can use :set nopaste


 
22)   category: UNIX Basics Language:English,  article number: 2002-01-03:3

Resetting Terminal/Shell
by Walt R.

Typing "stty sane "enter key"" into the shell
will normally recover an unreadable terminal.

See man stty, for explanation of what sane does.


 
23)   category: System Administration Language:English,  article number: 2001-11-20:1

Linux Networking Guide
by Eran Levy , homepage: http://levy.dyn.dhs.org

Looking for a comprehensive Networking guide? Here it is:
http://www15.brinkster.com/liloboot/linux/linetworking.txt



 
24)   category: UNIX Basics Language:English,  article number: 2001-10-17:1

Resetting your terminal/shell window
by Buffer_7

When accidentally doing a :
cat /bin/somefile_binary
you can end up with a "broken terminal". The binary file may possibly contain characters that
put a terminal into a mode where the output becomes unreadable. To put the terminal back to
normal you can type blindly:
reset
and it's normal.
best regards


 
25)   category: System Administration Language:English,  article number: 2001-10-11:10

EZ Email Security With Stunnel
by Pat Parsons

This is a little crash course in how to setup email over SSL painlessly using Stunnel. First you need to have installed a mail transfer agent to handle the SMTP portion of the mail. Then you need to have installed either an IMAP server or a POP3 server. Many distributions come with Stunnel, if yours does not you can get it from http://www.stunnel.org. Stunnel requires that you have OpenSSL or SSLeay installed first. This should come with your distribution. Generally if you have SSH installed you also have a SSL library.

Get and install Stunnel. I am not going into detail on that because if you are at this point you probably already know how to do so. Make a SSL certificate for use with Stunnel. OpenSSL provides a makefile to do just that. In my distribution it is located in /usr/share/ssl/certs . CD to that directory and type make stunnel.pem to create the certificate that is named stunnel.pem. Now you need to a few lines to your rc.local file to start Stunnel at bootup (assuming you ever reboot that is) these lines are:
/usr/sbin/stunnel -d 995 -r 110
/usr/sbin/stunnel -d 465 -r 25
This will start stunnel listening on port 995 for POP3 and 465 for SMTP. Now all you need to do is edit the options for your mail client and there you go. No need to worry about cleartext email passwords. If you are too impatient to wait for the next reboot you can type the commands given previously to start Stunnel right away. There may be some problems with certificate validation for some email clients. Make sure when asked by the makefile you get the server name correct. If your email client will not let you add certificates you may need to change or obtain a certificate from a certification authority. If you cannot get the certificate vaidation worked out there is no way to ensure that you are connecting to the correct machine. Have a nice day.


 
26)   category: UNIX Basics Language:English,  article number: 2001-07-23:1

Mounting ISO images (no CD-R required)
by Adrian Chung [ajchung[at]email.com]

You've just downloaded a 650MB ISO file, ready for burning to a CD-R. The MD5 hash checks out, but you're still not sure if the image contains what you want. If you're too impatient to wait for the CD-R to burn, you can browse the actual downloaded file via the loopback device. First create a mount point

  bash# mkdir /mnt/iso

Then mount the .iso file:

  bash# mount -t iso9660 -o loop Mandrake80-inst.iso /mnt/iso

Now browse the directory tree mounted on /mnt/iso. This is useful as a space saving measure when you want access to both the directory tree and to the raw .iso image on the same machine.


 
27)   category: UNIX Basics Language:English,  article number: 2001-05-25:3

klick any key to continue
by erkan yanar

In shell-programming you often want to continue a programm, when the user clicks any button. Normaly "read" is used if you would like to continue with any key then use this:

stty raw; dd if=$(tty) of=/dev/null bs=1 count=1; stty -raw

It just waits for any key



 
28)   category: UNIX Basics Language:English,  article number: 2001-05-13:1

Swapping CTRL key with CAPS_LOCK key (X11 and console mode)
by Igor [furlan at telocity dot com]

X11 environment:

Enter into /etc/X11/XF86Config (REDHAT 6.2) the following line:

Section "Keyboard"
XkbOptions "ctrl:swapcaps"
EndSection

Console

The solution from above does not swap keys in console Here is the solution for console: You have to modify the file "us.kmap.gz" (if you use US keyboard maping)
keycode 58 = Caps_Lock
to
keycode 58 = Control
AND from
keycode 29 = Control
to
keycode 29 = Caps_Lock
And life is nice again :)))

file "us.kmap.gz" is here (REDHAT 6.2) /usr/lib/kbd/keymaps/i386/qwerty


 
29)   category: System Administration Language:English,  article number: 2001-04-18:1

Having fun with BIND Version number.
by Mario Rafael [mrafael[at]arrakis.es]

Often when you have a large amount of DNS servers you tend to forget wich version of BIND you were running in each of them. With this little tips you will learn how to know wich version of bind you are running and how to change that version to show up anything you like. Ok.. start nslookup and type: > server target.host > set query=txt > set class=chaos > version.bind Server: localhost Address: 127.0.0.1 VERSION.BIND text = "8.2.3-REL" Ok this thing above is nice to show up to your friends to show them "the real BIND mastaH" inside you, but for usefullnes use the following script. #!/bin/bash for i in `cat iplist.txt`;do dig @$i txt chaos version.bind done It is obvious from the above that there NEEDS to exist a file named iplist in wich you specify the IP addresses of the name servers you want to check. Now comes the second part: Changing the BIND version shown by the above script. Fire up you prefered editor(vi) and edit /etc/named.conf and in the op options section type something similar to: version ":******"; Restart your bind and there yoy are. Mario Rafael.


 
30)   category: System Administration Language:English,  article number: 2001-03-08:1

Howto log in to your server passwordless via ssh ( rsa version )
by Murat Ilker Balaban [murat[at]enderunix.org]  , homepage: http://www.enderunix.org/

Create your private and public keys via ssh-keygen program
$ ssh-keygen
Computing keys
Testing the keys..
Key generation complete..
Enter the file in which to save the key (/usr/home/murat/.ssh/identity)

Press enter for the default value...

Your identification has been saved in /usr/home/murat/.ssh/identity
Your public ket is:
blah....blah...blah....
Your public key has been saved in /usr/home/murat/.ssh/identity.pub

Now that we have created our `public` key, take your
public key which is ~/.ssh/identity.pub to your server,
in the ~/.ssh/ directory, create a file named authorized_keys
and append the content of identity.pub file to your authorized_keys file
now, in your machine, type
$ ssh -l username your_remote_machine.domain.com
Boom, no password, no headache, you're in the other side...;)


 
31)   category: Community Language:English,  article number: 2001-03-02:1

http://www.portico.org/
by Guido Socher

There is a Linux site with a lot of tips and tricks: http://www.portico.org/



 
32)   category: UNIX Basics Language:English,  article number: 2001-02-13:9

Removing ^M from file
by Ismail YENIGUL [ismail[at]enderunix.org]  , homepage: http://www.enderunix.org

if you have transferred a file from MS Windows to UNIX, you might find that the file looks like this:
bleh bleh ^M
leh leh ^M
tey tey tey^M

This is because Windows uses carridge return and newline to indicate a new line.
Here are a number of ways to get rid of the ^M characters:
1- cat filename1 | tr -d "^V^M" > newfile
2- sed -e "s/^V^M//" filename > outputfilename
where ^V is actually control-V and ^M is actually control-M (you must type these yourself, don't just copy and paste this command from this web page)
3-vi solution : open file with vi
   1. hit the ESC key
    2. :%s/^V^M//

3 - some distributions contain a command called dos2unix which removes these carridge return characters

4- use the texteditor vim (www.vim.org) and edit the file. If all the lines (not only some) contain consistently the carridge return characters then vim will show [textmode] and when you change the mode with the command
:set notextmode
it will remove them.


 
33)   category: System Administration Language:English,  article number: 2001-02-13:5

Hide your Bind version
by Ismail YENIGUL [ismail[at]enderunix.org]  , homepage: http://www.enderunix.org

Any user can get your bind version using following command:
$ nslookup -q=txt -class=CHAOS version.bind. remote.dns.server
Server: remote.dns.server
Address: 212.2.2.3
VERSION.BIND text = "8.2.2-P5"
to hide you version add folowing value to named.conf

version "[Secured !!! Please Go away idiot lamer ! ]";
in the options section as follows:
options {
directory "/var/named";
version "[Secured !!! Please Go away idiot lamer ! ]";
};

and restart your named. Finally when anyuser writes
$ nslookup -q=txt -class=CHAOS version.bind. remote.dns.server
Server: remote.dns.server
Address: 212.2.2.3
VERSION.BIND text = "Secured !!! Please Go away idiot lamer"
That's all


 
34)   category: System Administration Language:English,  article number: 2001-02-08:1

How to delete and recreate /tmp
by Jordan [jordan.papaseit[at]free.fr]

The directory /tmp is a special one. When you "stat" it, it shows a 1777 mod ie drwxrwxrwt. Well, it's the same for .X0-lock, .X11-unix and .font-unix.

    "t" means that the files in the directory can only be deleted by the owner even though the directory is world writable.

So after a "mv /tmp /no_more_room/tmp or a rm /tmp", just do:
  • mkdir /tmp
  • chmod 1777 /tmp

To re-create it with the correct permissions. You have to do that if you want your x font server (xfs) to be working properly.


 
35)   category: Community Language:English,  article number: 2001-01-04:1

Mojolin, The Linux Job Site, goes international
by Dan Barber , homepage: http://mojolin.com

article image
Mojolin (http://www.mojolin.com) has added international support to its full featured online Job/Resume database. Job listings and resumes can now be entered with full location specifics. This new ability is complemented by a feature that allows an individual to search by countries, and by states and provinces in the United States and Canada. In addition, links have been provided to BabelFish for translation of the site into five different languages: German, French, Italian, Spanish and Portuguese. Other features include a nightly email agent which informs job seekers of the latest opportunities, and the ability for Webmasters to include Mojolin's job listings on their own sites.



 
36)   category: System Administration Language:English,  article number: 2000-11-16:2

Blocking anyone to su to root
by Ismail YENIGUL , homepage: http://apache.cslab.itu.edu.tr

The su (Substitute User) command allows you to become other existing
users on the system. For example you can temporarily
become "root" and execute commands as the super-user "root". If
you don't want anyone to su to root or restrict "su" command to
certain users then add the following two lines to the top of
your "su" configuration file in the "/etc/pam.d/" directory.
1- Edit the su file (vi /etc/pam.d/su) and add the following two
lines to the top of the file:

auth sufficient /lib/security/pam_rootok.so debug 
auth required /lib/security/pam_wheel.so group=wheel
After adding the two lines above, the "/etc/pam.d/su" file should
look like this:
#%PAM-1.0
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_wheel.so group=wheel

auth required /lib/security/pam_pwdb.so shadow nullok
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so shadow use_authtok nullok
session required /lib/security/pam_pwdb.so
session optional /lib/security/pam_xauth.so
Which means only those who are a member of the "wheel" group can su to root;
and to add a user to wheel group use:
root# usermod -G10 username
Ok, now everybody can not be root using su. When an user that is not in wheel group runs su command ,he/she can not be root even if he/she writes correct root password.


 
37)   category: System Administration Language:English,  article number: 2000-11-16:1

Disable rreboot,halt ,shutdown for users
by Ismail YENIGUL [yenigul[at]itu.edu.tr]  , homepage: http://apache.cslab.itu.edu.tr

On Redhat
[root@apache /]# rm -f /etc/security/console.apps/halt
[root@apache /]# rm -f /etc/security/console.apps/poweroff
[root@apache /]# rm -f /etc/security/console.apps/reboot
[root@apache /]# rm -f /etc/security/console.apps/shutdown
[root@apache /]# rm -f /etc/security/console.apps/xserver (if removed, root will be the only user able to start X).


 
38)   category: UNIX Basics Language:English,  article number: 2000-10-09:1

Create /dev/null
by Mariusz Zinowicz

I have moved a file to /dev/null and now my system doesn't work

If you move a file with the mv command to "/dev/null" then it will be overwritten with an ordinary file.
How to fix it:
Boot your system. If it doesn't boot take a one disk distribution like Toms rtbt and mount your /dev/hdXX partition.
Now type in a shell "mknod /dev/null c 1 3" to create a nod file. /dev/null is the path where the nod file will be saved. The c stands for a character device and the two numbers are the major and the minor numbers for the null device.
After that you must change with "chmod 666 /dev/null" the read, write and execute permissions.

With "ls -alF /dev/" you will see all nod files with it's own three parameters like
"crw-rw-rw- 1 root root 1, 3 Oct 4 11:34 null ".
You will see a "c" in the near of the rwx flags an a " 1, 3" left of the date.


 
39)   category: UNIX Basics Language:English,  article number: 2000-05-19:1

How to create many subdirectories in one time
by Pascal Mulier [pascal.mulier[at]francetelecom.fr]

Sometimes, we want to create 2 or 3 (or more) directories at the same time.
For example, you are in "rep1" directory ("rep1" doesn't contain any subdirectory) and want to create rep1/rep2/rep3
With "p" option of the mkdir command , it's very easy :

mkdir -p rep1/rep2/rep3



 
40)   category: Webdesign Language:English,  article number: 2000-04-10:1

Translating articles from/to English, French, German and Spanish from within Netscape.
by Egon Willighagen [egon.w[at]linuxfocus.org]

Webpages can conveniently be translated from English to French, Italian, German, Spanich and Portoguese or visa versa by means of Babelfish.

Altavista has a website where you can have a text translated. Alternatively you can have a website translated.

If you add the link below to your bookmarks (name it "translate"), you can translate any page by choosing this "translate" bookmark while visiting a website:

 
Example english to french: 

javascript:location.href=
'http://babel.altavista.com/tr?lin=en&lout=fr&translate_me=yes
&urltext='+escape(window.location);
The above should be written as one line. I just split it into a couple of lines for easy reading.

Translations are not very good, but it will give a very good clue about the content of the page.

An other interesting site for online translation is www.freetranslation.com.


 
41)   category: Applications Language:English,  article number: 2000-03-24:2

How to ispell a german text file?
by Dino Korn

Solution:
ispell -T latin1 -d deutsch textfile.txt
The -T latin1 causes ispell to handle Umlaute correctly.


 
42)   category: UNIX Basics Language:English,  article number: 2000-03-24:1

How to easily shutdown your Linuxbox without beeing root?
by Bernd Muller

People who do not boot to run-level 5 (grapical login) but use normal startx to start the window system I have the following trick:

Edit /etc/inittab and search for ctrlaltdel
ca::ctrlaltdel:/sbin/shutdown -t1 -r now
Replace the -r by -h:
ca::ctrlaltdel:/sbin/shutdown -t1 -h now
After that reboot once. Now you can shutdown and halt your computer by typing CTRL-ALT-DELETE. And this can be done by anybody without root rights.


 
43)   category: UNIX Basics Language:English,  article number: 2000-03-01:2

How to delete all files from /tmp?
by Katja Socher [katja[at]bearix.oche.de]

Simple question? Well, how do you delete files in directories that start with a dot in the name?
Rm -r /tmp/.* WILL DELETE THE WHOLE DISK as it selects also the file /tmp/.. Therefore never try this. The solution is to add two question marks before the '*'-wildcard:

rm -rf /tmp/.??* /tmp/*

You can put this into /etc/rc.d/init.d/syslog into the "stop)" section. This will clean up /tmp at every shutdown and keep your disk tidy.
Do not run the above command while running X11 or before you run startx. X11 needs the /tmp/.font-unix which is created by xfont server and X11 it self creates the directory /tmp/.X11-unix which is needed to talk to the X11 windows.



 
44)   category: Kernel Corner Language:English,  article number: 2000-03-01:1

How to make Linux ignore a ping?
by Antonio Schifano [a.schifano[at]linuxfocus.org]

Sometimes it can be useful to hide a Linux machine a bit. Here is how you can make Linux ignore a ping:

Simple, to turn answers to icmp_echo off type:
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
to turn it on again use:
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all


 
45)   category: UNIX Basics Language:English,  article number: 2000-02-15:3

Resetting your terminal/shell window
by Guido Socher [guido.s[at]writeme.com]  , homepage: http://www.oche.de/~bearix/g

When accidentally doing a :
cat /bin/somefile_binary
you can end up with a "broken terminal". The binary file may possibly contain characters that put a terminal into a mode where the output becomes unreadable. To put the terminal back to normal you can type
/bin/echo -ne "\017"
To make it easier you can put this into a small shell script and call it kscreen. When your terminal is again in this funny mode you just type blindly kscreen and it is back to normal.


 
46)   category: UNIX Basics Language:English,  article number: 2000-02-15:2

Finding out what libraries a program requires
by Guido Socher

  1. First find out where the program is located:
    In bash use: type yourprogram
    In tcsh use: which yourprogram

  2. To find out which shared libraries a program requires, type:
    ldd /the/path/to/yourprogram

Example:
> which gnome-terminal
/usr/bin/gnome-terminal

> ldd /usr/bin/gnome-terminal
        libart_lgpl.so.2 => /usr/lib/libart_lgpl.so.2 (0x400e1000)
        libgdk_imlib.so.1 => /usr/lib/libgdk_imlib.so.1 (0x400ef000)
        libgtk-1.2.so.0 => /usr/lib/libgtk-1.2.so.0 (0x40131000)
        libgdk-1.2.so.0 => /usr/lib/libgdk-1.2.so.0 (0x40251000)
        libgmodule-1.2.so.0 => /usr/lib/libgmodule-1.2.so.0 (0x40283000)
        libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x40286000)
        libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40292000)
        libgnome.so.32 => /usr/lib/libgnome.so.32 (0x4032f000)
        libgnomesupport.so.0 => /usr/lib/libgnomesupport.so.0 (0x40345000)
        libaudiofile.so.0 => /usr/lib/libaudiofile.so.0 (0x40350000)
        ....


 
47)   category: UNIX Basics Language:English,  article number: 2000-02-15:1

Mtools
by Guido Socher , homepage: http://www.oche.de/~bearix/g

article image
mtools is a collection of programs to access ms-dos files on floppy disks without mounting them. You can read dos floppy disks in Linux by mounting them somewhere but mtools are usually easier and faster to use. An advantage is also that the floppy does not need to be mounted because accidentally ejecting a mounted floppy under Linux can be quite fatal.

Using mtools

mtools work basically like msdos commands. The command names are identical with the corresponding msdos command except that a "m" is prepended. Mtools understand also long file names. The most important commands are:
  • mcopy
  • mdel
  • mdir
  • mformat
Make sure that the device /dev/fd0 is writable for you before you use them. You many make the /dev/fd0 device writable for everybody. To do that log in as root and type "chmod 666 /dev/fd0".

To get a directory listing of the floppy in /dev/fd0 (drive a:) you type:
mdir a:
Note the device specifier. It is "a:" and not the normal Linux name /dev/fd0.

To copy the files a.txt and b.txt to the floppy you use:
mcopy a.txt b.txt a:


To copy all files (not directories) from the floppy to your current directory you use:
mcopy "a:*" .
Note the quotes. They are important because you want the star to go to the mcopy command and avoid that it gets expanded by the shell.

To delete all files that have a filename which starts with a "x" you type:
mdel "a:x*"
Again remember to put quotes.

To remove all files from the floppy you can use mformat
mformat a:

The mtools are included in almost every distribution. If they are not yet installed then install them from cdrom. Otherwise mtools are available from
http://www.tux.org/pub/tux/knaff/mtools/index.html



 
48)   category: UNIX Basics Language:English,  article number: 2000-02-14:5

Colors in the command prompt
by Guido Socher [guido.s[at]writeme.com]

article image
All terminal windows for Linux understand Ansi color codes and with these codes it is possible to have colors in the shell prompt.

The color codes are:

  • Foreground colors: 30=black, 31=red, 32=green, 33=yellow, 34=blue 35=purple, 36=turquoise, 37=white
  • Background colors: 0=transparent, 40=back, 41=red, 42=green, 43=yellow, 44=blue 45=purple, 46=turquoise, 47=white
The syntax to print the codes is "Esc[background;foreground;1m" for bold print and "Esc[background;foreground m" for normal print. The Esc is a literal Esc character (octal 33). The coloring is switched off with "Esc[m"

This command prints e.g Linux in yellow on a red background:
/bin/echo '\033[41;33;1m Linux \033[m'
Just try it out copying the command into the next shell.

To insert special characters such as (a literal Esc) into the shell prompt you must include them in %{ %} for tcsh and \[ \] for bash

This gives e.g the tcsh prompt that you can see in the picture above:
set prompt='%{^[[44;33;1m%}%!\-%n@%m%{^[[m%} \n%{^[[44;37;1m%}(%~)%#%{^[[m%} '

A yellow prompt for bash is e.g:
PS1='\[^[[40;33;1m\]\u@\h:\w\$\[^[[m\] '

In both cases the literal Esc character is shown as ^[. Note: You can not copy and paste these lines from the web browser to the shell. To get a literal Esc in Vi you type crtl-v Esc and in Emacs this is crtl-q Esc.

Happy color command prompts!


 
49)   category: UNIX Basics Language:English,  article number: 2000-02-14:1

2 vi tricks
by Guido Socher [guido.s[at]writeme.com]  , homepage: http://www.oche.de/~bearix/g

article image
Here are 2 interesting tricks for the VI editor.

  1. While editing something in VI you suddenly get a phone call. You need to go to the shell type a few commands and then go back to VI and continue working. What do you do? It's easy with VI. Hit Crtl-z to suspend VI then type the commands and afterwards type fg to continue the suspended VI process in foreground.

  2. The commands in makefiles must be preceded by a tab-character. Unfortunately it is not easy to distinguish tabs from spaces but a makefile with spaces just wont work. In VI you just type:
    :set list
    to see the tab characters as ^I. This way you can see all tabs at once and verify that the makefile is correct. When done you type:
    :set nolist


 
50)   category: Webdesign Language:English,  article number: 2000-02-13:1

Finding Netscape bookmarks
by Guido Socher [guido.s[at]writeme.com]  , homepage: http://www.oche.de/~bearix/g

article image

Searching through bookmarks

Sometimes you are looking for a bookmark in netscape and you can only remember that the URL or title did contain some key word. A little perl script, I called it showbook, can help in that case.

showbook linux
does e.g list all your bookmarks that contain the string Linux somewhere.

Click here to download the script.
(Note: If you download the script under windows then you must convert the dos textfile first to a unix textfile before it will run under Linux.)

Copy paste a url while not online

Somehow it is not possible to copy/paste a URL from your bookmark list into an other program. You can click on the bookmark go to the page and then copy the URL from the location entry at the top of the window in netscape. The problem is that you need to be online to do that. Again the above showbook program helps. It just lists the URL in the terminal window and you can easily copy/paste from there.