Friday, October 21, 2011

Virtual Box Helpfull commands

1. To get the cliipboard working you may have to run following command in your guest operating system ( I run windows XP as host and Ubuntu as guest) and this works for me :)

  $ sudo VBoxClient --clipboard

 2. Will be updating commands as and when I encounter them

Saturday, October 1, 2011

Identifying 32bit/64 bit for different OS

SOLARIS

 If Solaris has been configured for 32 bit, the output of following command will be

command:  $ isainfo -v
output     : 32-bit sparc applications

command: isainfo -b
output     : 32

If Solaris has been configured for 64 bit,

command:  $ isainfo -v
output     : 64-bit sparcv9 applications 32-bit sparc applications

OR
command:  isainfo -b
output      : 64

WINDOWS


LINUX

Thursday, September 8, 2011

Creating a Daemon ...

Most of the time I use daemon() function call to get my things done.
But it is always good to know exactly what are the basic steps that needs to be done to make a process a daemon.

Following is the sample code to create a daemon.
The usual steps are
1. Fork out
2. close parent , following code is to be done in child
3. Set file mode mask
4. open any log files
5. set SID
6. change working directory to something safe..( may be to "/")
7. close standard file descriptors ( stdin, stdout and stderr)
8. have your big loop to perform stuff you want your daemon to perform... :)

-------------------------CODE SAMPLE ---------------------------





#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>

int main(void) {

/* Our process ID and Session ID */
pid_t pid, sid;

/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
exit(EXIT_SUCCESS);
}

/* Change the file mode mask */
umask(0);

/* Open any logs here */

/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}



/* Change the current working directory */
if ((chdir("/")) < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}

/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

/* Daemon-specific initialization goes here */

/* The Big Loop */
while (1) {
/* Do some task here ... */

sleep(30); /* wait 30 seconds */
}
exit(EXIT_SUCCESS);
}

Friday, January 22, 2010

Find out who is using your port

Many a times I forget this command. I have no Idea why.
So here it is, to your rescue the mighty lsof command

Just type this and you will have all the ports with their PID
# lsof -nl | egrep "TCP|UDP"

And then use ps for rest of your work. :)

UPDATE:
Since this was all good...there is even simpler way
adding -p option to netstat gives you the pid.


# netstat -anp | grep 'port number'

And again use ps for rest of your work.. :)

Yum repository on FC11

I was trying to create a yum repository for 389 directory and its dependencies

Setting up YUM repository:
Skip to next part if you already know the 389 directory repository.

This part explains the creation of yum repository for 389 directory server. Once created, this repository can be used for any fresh installation of 389 directory server.

1.Freshly install Fedora 11 on the machine. (Please refer the document OS Install & Config doc for security and OS hardening points)
2. edit the yum.conf file presently most of the time at /etc/yum.conf
replace the lines
keepcache=0 to keepcache=1
This will keep all the rpm's downloaded in next part at a location
/var/cache/yum/packages/

3.run yum install 389-ds
4.This will install 389 directory server and its dependencies. These packages will also be saved at /var/cache/yum//packages/
5.Save the packages at a secure location. e.g. /mnt/nfs_mounted_repo/
6.go to the directory where the rpm's are saved and run
$> createrepo -v .
This will create the necessary files for repository
7.Since 389-ds is already installed from step 3 you need not install it again.
8.Check out the section Configuration of 389 DS.






Update Yum to use new repository

Assuming that the repository is already prepared using the steps from section setting up repository, This section will describe configuration of yum to point to the new repository and installation of 389 DS.

We will assume that the repository is created and mounted at location /mnt/nfs_mounted_repo/

1.Create a repo file in /etc/yum.repos.d/ directory (you can name anything to your file make sure a .repo extension is added)
vim /etc/yum.repos.d/ds.repo
2.Add following data in that file
[DSrepo]
name=DSrepo
baseurl=file:///mnt/nfs_mounted_repo/
enabled=1
gpgcheck=0
3.disable the fedora.update repository
open the file /etc/yum.repos.d/fedora-updates.repo
and replace enable = 1 with enable = 0 in the file.

4.Now run following commands
$> yum clean all
This will clean yum database
$> yum list
This will list the files / packages available on that directory
5.The repository is now set and yum is ready to use the new repository.

Installing 389 directory server

Simply run
$> yum install 389-ds

And this will do the task

To setup the 389-ds run
$> setup-ds-admin.pl

answer the questions and voila you are up and ready to go...

Want to check if all is working fine ???
run the 389 console

$> 389-console

Disclaimer

The only intention of this blog is to help remember myself.
I don't take responsibility of any of the tips mentioned in this blog.