30 Haziran 2013 Pazar

Raspberry - cgi dizini


./apache2/sites-available/default dosyasındadır.

Örnek:
./apache2/sites-available/default:      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

Sonuçta Raspbian da bir Debian dağıtımıdır.



Raspberry - Hostname değiştirmek

sudo vi /etc/hostname
sudo reboot
hostname --fqd

21 Haziran 2013 Cuma

Linux kabuk değişkenleri

$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$* = All the arguments on the command line.
$# The number of command line arguments.

Linux - Koşullar

There is a function provided by bash called test which returns a true or false value depending on the result of the tested expression. Its syntax is:

test expression

It can also be implied as follows:

[ expression ]

The tests below are test conditions provided by the shell:

-b file = True if the file exists and is block special file.
-c file = True if the file exists and is character special file.
-d file = True if the file exists and is a directory.
-e file = True if the file exists.
-f file = True if the file exists and is a regular file
-g file = True if the file exists and the set-group-id bit is set.
-k file = True if the files' "sticky" bit is set.
-L file = True if the file exists and is a symbolic link.
-p file = True if the file exists and is a named pipe.
-r file = True if the file exists and is readable.
-s file = True if the file exists and its size is greater than zero.
-s file = True if the file exists and is a socket.
-t fd = True if the file descriptor is opened on a terminal.
-u file = True if the file exists and its set-user-id bit is set.
-w file = True if the file exists and is writable.
-x file = True if the file exists and is executable.
-O file = True if the file exists and is owned by the effective user id.
-G file = True if the file exists and is owned by the effective group id.
file1 –nt file2 = True if file1 is newer, by modification date, than file2.
file1 ot file2 = True if file1 is older than file2.
file1 ef file2 = True if file1 and file2 have the same device and inode numbers.
-z string = True if the length of the string is 0.
-n string = True if the length of the string is non-zero.
string1 = string2 = True if the strings are equal.
string1 != string2 = True if the strings are not equal.
!expr = True if the expr evaluates to false.
expr1 –a expr2 = True if both expr1 and expr2 are true.
expr1 –o expr2 = True is either expr1 or expr2 is true.
The syntax is :

arg1 OP arg2



where OP is one of –eq, -ne, -lt, -le, -gt, or –ge. Arg1 and arg2 may be positive or negative integers or the special expression "-l string" which evaluates to the length of string.

Unix shell scripting - Log yazma fonsiyonu


Log-function

In a private message, I was asked how the log-function worked that I described above. Since this might be helpful to other people too, I'm answering the question in public.

First of all, I use Bash, don't know if this trick works in other Shells.

Content of script:


Code:
#!/bin/bash
. lib/functions.conf # mind the SPACE between the DOT and the path/filename!!! 
logfile=scheduler.log
func_eventlog "STARTING ABG JOB"
-=script runs some more, but that's irrelevant, the example is clear=-

Content of file: lib/functions.conf which by the way is executable :


Code:
################################################
#                                              #
# Log functie                                  #
#                                              #
# Usage:                                       #
#                                              #
# func_eventlog "Dit wil ik loggen"            #
#                                              #
# Variabelen:                                  #
#                                              #
# $logfile (logfile inclusief pad)             #
#                                              #
################################################

func_eventlog()
{
 echo -e "`date` - $1" >> $logfile
}

So whenever I want something logged, I just use:

func_eventlog "Send this text to logfile"

and I never ever have to worry about accidentally overwriting my logs instead of appending to them. 

14 Haziran 2013 Cuma

Awk - Boş satırları silmek

awk /./ dosya.txt

11 Haziran 2013 Salı

Ramlog - Raspberry Pi


SD CARD

An SD Card has a limited lifetime, it depends on various factors. Normally the lifetime declared by manufacturers is very long, but I have experienced that sometimes the lifetime is very short. °v°.

So taking care of the healt status of the SD CARDs could lead to a high reliability.

One of the factors that could broke your SD Card is the write cycles. As said, this number is normally very high but you cannot say if your SD CARD will have a behaviur in the average or under the average. So you can think to reduce the number of writes.

 

 



The /var/log directory contains the log files for your services and these files are often updated, if you have a lot of services running you have a lot of writes on your SD CARD, if the log files are not essential in your system you can move them on a RAM disk and then you can backup them when you want.

In my production system I'm using a tool that does the job: Ramlog.

"Ramlog act as a system daemon. On startup it creates ramdisk, it copies files from /var/log into ramdisk and mounts ramdisk as /var/log. All logs after that will be updated on ramdisk. Logs on harddrive are kept in folder /var/log.hdd which is updated when ramlog is restarted or stopped. On shutdown it saves log files back to harddisk so logs are consistent. Ramlog 2.x is using tmpfs by default, ramfs and kernel ramdisk are suppored as well. Program rsync is used for log synchronization."

To install Ramlog on your Raspbian system run the following instructions:

# sudo apt-get install lsof

# wget http://www.tremende.com/ramlog/download/ramlog-2.0.0.tar.gz

# cp -a ramlog /etc/init.d/ramlog

# cp -a ramlog.8.gz /usr/share/man/man8/ramlog.8.gz

# cp -a ramlog.cron /etc/cron.daily    #or to other dir based on your need

# cp -a ramlog.logrotate /etc/logrotate.d/ramlog

# cp -a ramlog.conf /etc/default/ramlog

 

With your favourite editor, edit the file /etc/default/ramlog and set the value for your RAM filesystem, for example TMPFS_RAMFS_SIZE=20 means you want to use 20 mega bytes of RAM.

You can retrieve the actual size for /var/log directory issueing the following command:

# ramlog getlogsize

 

Last, reboot your system

# sudo reboot -n