Τετάρτη 31 Οκτωβρίου 2012

Tip for Unix, set maximux share size for Samba

Samba is a server (developed on unix) that provides Network Filesystem Service for Windows users. It is equivalent to NFS for Unix. Samba is free and open source and emulates Windows Server Functions as User Domain Authentication and Nework Directories based on NetBios (proWin98-me era) or Smb/Cifs (post Win2000 era) Service.

A tip to Set maximum share size per user for Samba Network Filesystem Server is as follows:
 In Global parameters of /etc/sfw/smb.conf file:
[global]
max disk size = 15000

So, the network share will show 15Gb in the next service reboot
(solaris 8-9-10-11) -> svcadm restart samba

Τρίτη 30 Οκτωβρίου 2012

How to edit crontab

Crontab is a unix background process that schedules other unix jobs. In order to be edited, the admininistrator must set the EDITOR enviromental variable. The steps are:

Change or Set Environment Variable

You can use the following command to change the environment variable for the current session as per your shell.

For Korn shell (KSH)

The syntax is as follows:
 
EDITOR=vi
export EDITOR
 

For Bourne shell (sh and bash)

The syntax is as follows:
 
export EDITOR=vi
 
or

EDITOR=vi
export EDITOR
 
To set PATH, enter:
 
export PATH=$PATH:/opt/bin:/usr/local/bin:$HOME/bin
 

For C shell (csh or tcsh)

The syntax is as follows:
 
setenv var value
 
Set EDITOR to vim, enter:
 
setenv EDITOR vi 
 
 
There are plenty of type editors, the most common are vi, , emacs, joe 
 
After having set the EDITOR, type the command "crontab -e" to edit crontab 
job scheduler.
To list the cron jobs type "crontab -l"
 

More information about the enviromental variables in Unix and
how to manipulate them can be found on this article
http://www.cyberciti.biz/faq/set-environment-variable-unix/
 




Τρίτη 23 Οκτωβρίου 2012

What is Unix and how to start to use it

Unix is an Operating System (OS) that was officially developed for first time by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, Michael Lesk and Joe Ossanna. Nowadays, it is developed and distributed by Enterprize Vendors, such as HP, IBM, ORACLE and many more. It is used as a platform for database and web applications that hosted in big data centers with high rate transactions of gibabyte or terrabyte.
Unix can only be found in central sites and it is not intended as an OS for common end users, except for Apple MacOS (MacOS is Unix)
It is popular amongst army, Government, Intustry as an OS platform for central data center sites, due to its powerfull, secure multitasking kernel and its capabilities to integrate with sophisticated storage devices, ensuring high availability, integrity of crucial data and zero-downtime.
Some represantive UNIX OS trademarks for Server-Oriented applications are Sco-Unix, HP-UX, IBM-AIX, Oracle-Solaris, SGI-IRIX
Apart from these, there is Apple-MacOS and the open-source Gnu-Linux kernel (Unix-like) for PCdesktop-based applications, in a field where the Microsoft Windows Operating Systems would always prevail.

A good start to learn unix is, first of all, to try to install unix or unix-like OS. An original unix system that is X86-PC-capable is Oracle Solaris and anybody can download it and install it just for curiosity, but due to its server-oriented architecture lacks friendly desktop applications, as it would be expected. Instead, I would recommend a friendly version of Gnu-Linux kernel (Unix-like), that is Fedora Linux.
Fedora is friendly and challenging. The next thing users have to do is to follow the online installation-quick-start guide step-by-step. Sticking to this procedure, user makes his first step learning something different and unconventional about computers as he had seen or as taught till that momment. Linux can do everything, you can do social media (twitter, facebook etc..), play games online, hear music, watch movies, edit or print your windows office documents, even use it as a platform to develop new software.
But someone could ask "Why would someone use Linux in business and what is the relationship with unix;"
Well, Linux is the perfect cost-free choice for small-sized businesses and the entry level before starting to learn unix for those IT engineers who are interested to work as application developers on unix or administration.

Finally, I would suggest users to install and try many OS before they make their choice for their computers.

 Attachment link: Fedora Installation Quick Start Guide

http://docs.fedoraproject.org/en-US/Fedora/17/html/Installation_Quick_Start_Guide/index.html



Δευτέρα 24 Σεπτεμβρίου 2012

Unix Solaris 10 greek alphabet support

Three weeks ago, I realised that my unix Solaris 10u8 system has a font representing problem with the letters of Greek alphabet. I couldn't read any of my text files, containing greek filename or inner greek text, and all these files were recently backed up in unix system. Consequently, that situation would be very uncomfortable in case that I would need to proceed on partial recovering of some files by using filename.

To encounter this problem we should install greek font support on the Solaris 10 unix system. Everything we need is on installation cdrom of Solaris 10.

There is an administration utility -called localeadm- that helps to install the required fonts.

Steps.
  1. The required fonts are in the Solaris 10 cdrom. Supposing that the mounting directory is on /cdrom/cdrom0, we list the available language font systems by entering "localeadm -ls -d /cdrom/cdrom0" We notice that the representing description name for the Greek font system is el_gr.
  2. To install the font system we enter "localeadm -a el_gr -d /cdrom/cdrom0"
Additional localeadm commands:

  1. localeadm -q el_gr : This example queries whether the Greek font system called "el_gr" is installed on the current machine
  2. localeadm -r el_gr  : This example removes the Greek font system from the current machine     

Τρίτη 28 Αυγούστου 2012

What does “> /dev/null 2>&1″ mean?

While browsing the internet, I came up with a very good article about What does “> /dev/null 2>&1″ mean in unix shell programming?

The article's source here

Article:
" I remember being confused for a very long time about the trailing garbage in commands I saw in Unix systems, especially while watching compilers do their work. Nobody I asked could tell me what the funny greater-thans, ampersands and numbers after the commands meant, and search engines never turned up anything but examples of it being used without explanation. In this article I’ll explain those weird commands.
Here’s an example command:
wibble > /dev/null 2>&1

Output redirection

The greater-thans (>) in commands like these redirect the program’s output somewhere. In this case, something is being redirected into /dev/null, and something is being redirected into &1.

Standard in, out, and error

There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors (you can think of them as “data pipes”) are often called STDIN, STDOUT, and STDERR.
Sometimes they’re not named, they’re numbered! The built-in numberings for them are 0, 1, and 2, in that order. By default, if you don’t name or number one explicitly, you’re talking about STDOUT.
Given that context, you can see the command above is redirecting standard output into /dev/null, which is a place you can dump anything you don’t want (often called the bit-bucket), then redirecting standard error into standard output (you have to put an & in front of the destination when you do this).
The short explanation, therefore, is “all output from this command should be shoved into a black hole.” That’s one good way to make a program be really quiet! "

source  http://www.xaprb.com



Πέμπτη 9 Αυγούστου 2012

Unix exit error handling

Exit Codes

Exit codes are a number between 0 and 256, which is returned by any Unix command when it returns control to its parent process.
Other numbers can be used, but these are treated modulo 256, so exit -10 is equivalent to exit 246, and exit 257 is equivalent to exit 1. These can be used within a shell script to change the flow of execution depending on the success or failure of commands executed. This was briefly introduced in Variables - Part II. Here we shall look in more detail in the available interpretations of exit codes.
Success is traditionally represented with exit 0; failure is normally indicated with a non-zero exit-code. This value can indicate different reasons for failure.
For example, GNU grep returns 0 on success, 1 if no matches were found, and 2 for other errors (syntax errors, nonexistant input files, etc).
We shall look at three different methods for checking error status, and discuss the pros and cons of each approach.
Firstly, the simple approach:

#!/bin/sh
# First attempt at checking return codes
USERNAME=`grep "^${1}:" /etc/passwd|cut -d":" -f1`
if [ "$?" -ne "0" ]; then
  echo "Sorry, cannot find user ${1} in /etc/passwd"
  exit 1
fi
NAME=`grep "^${1}:" /etc/passwd|cut -d":" -f5`
HOMEDIR=`grep "^${1}:" /etc/passwd|cut -d":" -f6`
echo "USERNAME: $USERNAME"
echo "NAME: $NAME"
echo "HOMEDIR: $HOMEDIR"

This script works fine if you supply a valid username in /etc/passwd. However, if you enter an invalid code, it does not do what you might at first expect - it keeps running, and just shows:
USERNAME: 
NAME: 
HOMEDIR: 
Why is this? As mentioned, the $? variable is set to the return code of the last executed command. In this case, that is cut. cut had no problems which it feels like reporting - as far as I can tell from testing it, and reading the documentation, cut returns zero whatever happens! It was fed an empty string, and did its job - returned the first field of its input, which just happened to be the empty string.
So what do we do? If we have an error here, grep will report it, not cut. Therefore, we have to test grep's return code, not cut's.

#!/bin/sh
# Second attempt at checking return codes
grep "^${1}:" /etc/passwd > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
  echo "Sorry, cannot find user ${1} in /etc/passwd"
  exit 1
fi
USERNAME=`grep "^${1}:" /etc/passwd|cut -d":" -f1`
NAME=`grep "^${1}:" /etc/passwd|cut -d":" -f5`
HOMEDIR=`grep "^${1}:" /etc/passwd|cut -d":" -f6`
echo "USERNAME: $USERNAME"
echo "NAME: $NAME"
echo "HOMEDIR: $HOMEDIR"

This fixes the problem for us, though at the expense of slightly longer code.
That is the basic way which textbooks might show you, but it is far from being all there is to know about error-checking in shell scripts. This method may not be the most suitable to your particular command-sequence, or may be unmaintainable. Below, we shall investigate two alternative approaches. As a second approach, we can tidy this somewhat by putting the test into a separate function, instead of littering the code with lots of 4-line tests:

#!/bin/sh
# A Tidier approach

check_errs()
{
  # Function. Parameter 1 is the return code
  # Para. 2 is text to display on failure.
  if [ "${1}" -ne "0" ]; then
    echo "ERROR # ${1} : ${2}"
    # as a bonus, make our script exit with the right error code.
    exit ${1}
  fi
}
### main script starts here ###
grep "^${1}:" /etc/passwd > /dev/null 2>&1
check_errs $? "User ${1} not found in /etc/passwd"
USERNAME=`grep "^${1}:" /etc/passwd|cut -d":" -f1`
check_errs $? "Cut returned an error"
echo "USERNAME: $USERNAME"
check_errs $? "echo returned an error - very strange!"

This allows us to test for errors 3 times, with customised error messages, without having to write 3 individual tests. By writing the test routine once. we can call it as many times as we wish, creating a more intelligent script, at very little expense to the programmer. Perl programmers will recognise this as being similar to the die command in Perl. As a third approach, we shall look at a simpler and cruder method. I tend to use this for building Linux kernels - simple automations which, if they go well, should just get on with it, but when things go wrong, tend to require the operator to do something intelligent (ie, that which a script cannot do!):

#!/bin/sh
cd /usr/src/linux && \
make dep && make bzImage && make modules && make modules_install && \
cp arch/i386/boot/bzImage /boot/my-new-kernel && cp System.map /boot && \
echo "Your new kernel awaits, m'lord."
This script runs through the various tasks involved in building a Linux kernel (which can take quite a while), and uses the && operator to check for success. To do this with if would involve:

#!/bin/sh
cd /usr/src/linuxif [ "$?" -eq "0" ]; then
  make dep 
    if [ "$?" -eq "0" ]; then
      make bzImage 
      if [ "$?" -eq "0" ]; then
        make modules 
        if [ "$?" -eq "0" ]; then
          make modules_install
          if [ "$?" -eq "0" ]; then
            cp arch/i386/boot/bzImage /boot/my-new-kernel
            if [ "$?" -eq "0" ]; then
              cp System.map /boot/
              if [ "$?" -eq "0" ]; then
                echo "Your new kernel awaits, m'lord."
              fi
            fi
          fi
        fi
      fi
    fi
  fi
fi

... which I, personally, find pretty difficult to follow. The && and || operators are the shell's equivalent of AND and OR tests. These can be thrown together in strings, as above, or:

#!/bin/sh
cp /foo /bar && ( echo Success ; echo Success part II ) || ( echo Failed ; echo Failed part II )
This code will either echo
Success
Success part II
or
Failed
Failed part II
depending on whether or not the cp command was succesful. Look carefully at this; the construct is
command && command-to-execute-on-success || command-to-execute-on-failure
Only one command can be in each part, though the ( ) brackets make a subshell, which is treated as a single command by the top-level shell. This method is handy for simple success / fail scenarios, but if you want to check on the status of the echo commands themselves, it is easy to quickly become confused about which && and || applies to which command. It is also very difficult to maintain. Therefore this construct is only recommended for simple sequencing of commands.

Source:  http://steve-parker.org/sh/exitcodes.shtml

Πέμπτη 19 Ιουλίου 2012

How to clear log files in Solaris 10 unix

Directories with log files
  • /var/adm/        -> system messages, login/logout logs
  • /var/log/          -> various logs, Xorg logs...
  • /var/svc/log/    -> logs with information about services
Clear:   rm -fr /var/adm/* ; rm -fr /var/log/* ;  rm -fr /var/svc/log/

Σάββατο 2 Ιουνίου 2012

Saturday.. the Backup Day!

My English practise through technology.

Since Microsoft has decided to exclude :-( the powerful utility, commonly known as Ntbackup, from windows 7, we shall try some other tools to make a full backup of a disk.

The Os we 'll be using is linux Fedora 16.

Given Scenario:

We have two usb disks, the first 120Gb will be fully backed up to the second one 500Gb.
  1. Connect both disks to linux, preferably via usb connectors. 
  2. Linux automatically mounts them in the folder /media as /media/disk1/ and /media/disk2/
  3. In order to determine which disk contains the file structure to backup, open a command line terminal and use the command "ls -ltr /media/disk1/" and "ls -ltr /media/disk2/" without the double quotes. Disk1 contains the file structure. Disk2 is blank.
  4. We 'll use the tar and gzip commands to backup the disk1. Tar makes a destination file to disk2, which is used as a backup container for disk1. Tar uses .tar extension, and gzip compresses the tar file to a .tar.gz extension. The tar is equivalent to Microsoft Ntbackup. The disadvantage is that is a command line utility. In contrast with tar,  Microsoft Ntbackup was fully graphical and easy to use.
  5. Now, use the following command syntax (without the double quotes) to backup disk1 to disk2
  6. "cd /media/disk1/; tar -cvf - . | gzip > /media/disk2/oldbackup010612.tar.gz"  and then press enter.
  7. This command syntax tells us "Go to disk1, start taking the backup of disk1 to disk2 through gzip compression". The final result is a backup file oldbackup010612.tar.gz with a reduced file size of the initial disk1 size.
  8. ........I wish Ntbackup back!!!!!

Παρασκευή 4 Μαΐου 2012

Δώστε κώδικα στο λαό

Ο προγραμματισμός σε κάποια γλώσσα προγραμματισμού για μερικούς είναι κάτι εύκολο, αλλά τους περισσότερους τους φοβίζει. Αν κάποιος θέλει να μάθει μερικά βασικά πράγματα για το πως να γράφει κώδικα, υπάρχει ένα μέρος το οποίο προσπαθεί να το κάνει όσο πιο ανώδυνο γίνεται. Το Codeacademy (www.codeacademy.com) είναι ένας χαλαρός, αλληλεπιδραστικός ιστότοπος ο οποίος προσφέρει δωρεάν οδηγίες για το πως μπορεί να δημιουργηθούν ιστοσελίδες και εφαρμογές. Δεν πρέπει να συγχέεται με τον οργανισμό Code Academy (www.codeacademy.org), ο οποίος προσφέρει μαθήματα on-site στο Σικάγο και δεν είναι δωρεάν.
Από το πρώτο μάθημα σας ζητείται να πληκτρολογήσετε το όνομα Ryan μέσα σε εισαγωγικά "" και να πατήσετε το πλήκτρο enter από το πληκτρολόγιο. Στη συνέχεια θα σας ζητηθεί να κάνετε χρήση της εντολής ".length" για ν' ανακαλύψετε το πλήθος των χαρακτήρων του ονόματός σας.
Αυτό ήταν. Τώρα προγραμματίζετε. Αποτελεί μία έξυπνη κίνηση από την Codeacademy, η οποία προσπαθεί να κάνει τον προγραμματισμό προσβάσιμο σε όλους. Μέσα σε λίγα δευτερόλεπτα, νέοι χρήστες κάνουν θεμελειώδης προγραμματιστικές κινήσεις. Σ' ένα λεπτό μεταπηδάτε στο βασικό tutorial της JavaScript.
Μόλις εισάγετε το πρώτο σας προγραμματιστικό σφάλμα, η Codeacademy σας επιβραβεύει με την πρώτη on-line κονκάρδα και σας αφήνει να δημοσιεύεσετε το επίτευγμά σας τόσο στο Facebook όσο και στο Twitter. Ο ιστότοπος κάνει πολύ καλή δουλειά επειδή σπάει την διαδικασία εκμάθησης σε διαχειρίσιμα τμήματα, τα οποία είναι διασκεδαστικά και αφήνει τους εκπαιδευόμενους να εισάγονται σε αυτά με πολλαπλούς τρόπους. Αυτή τη στιγμή εστιάζεται στον προγραμματισμό Web με χρήση της JavaScript και πρόσφατα μπήκαν μαθήματα για την εκμάθηση των CSS. Η εκπαίδευση στην JavaScript καλύπτει συνατήσεις, πίνακες και βρόχους. Ο χρήστης μπορεί να κάνει τα μαθήματα με τη σειρά ή ν' απορρίψει οποιοδήποτε από αυτά. Ο ιστότοπος προσφέρει και απλά μαθήματα για την εκμάθηση των τεχνικών αλλά και εκμάθηση μέσω κάποιων εργασιών (project). Για παράδειγμα, στην εισαγωγή για την JavaScript, ο χρήστης μπορεί να δημιουργήσει ένα βασικό παιδικό παιχνίδι, το FizzBuzz. Μόλις τελειώσετε την βασική εκπαίδευση, η Codeacademy σας προκαλεί να φτιάξετε ένα blackjack παιχνίδι. Καθόλη τη διάρκεια της εκπαίδευσης, τα επιτεύγματα (κονκάρδες) σας μπορούν να κοινοποιηθούν στα διάφορα κοινωνικά δίκτυα, αν το επιθυμείτε φυσικά.

Δευτέρα 23 Απριλίου 2012

Processes in unix

1) List processes in detail including execution path, using legacy ps as shown in the next line :: 
ps -ecdf 













Advantages: full listing detail having execution path unveiled
2) How to Kill processes
kill -9 PID example: kill -9 741 this command kills the java runtime server regarding the image above
3) How to restart processes
kill -HUP PID example: kill -HUP 741, restarts the process in memory session. HUP isn't aware of changes in configuration files that lie on disk. In such circumstance, PID must be restarted using convential execution command via source path, specifically an example is given below to clarify our case ::
>su root
>cd /usr/java/bin/
>./java -server -Xmx128m -XX:+UseParallelGC -XX:ParallelGCThreads=4