Search This Blog

Friday, October 18, 2013

Linux: cannot set LC_CTYPE locale or related problems

To make it permanent just edit the file “/etc/environment” and add the line:
LC_ALL=C
or in
/etc/profile
add
export LC_ALL=C

Wednesday, October 9, 2013

Simple access SVN Subversion repository behind proxy

Uncommenting and set the following lines: 

[global]
http-proxy-host=my.proxy
http-proxy-port=80
http-proxy-username=[username]
http-proxy-password=[password]

in file
~/.subversion/servers

Wednesday, October 2, 2013

Simple essential TAR usage

create archive:
tar -cvf test.tar /home/test/
extract archive:
tar -xvf test.tar
list archive content:
tar -tvf test.tar

Thursday, August 29, 2013

QNAP: Automatically run a script at startup

Running Your Own Application at Startup
QPKG-based method (new)
This method consists of declaring a dummy QPKG which launches your script at startup.

Log into your QNAP device using SSH or Telnet, for instance by using Putty

Edit QPKG config file:
# vi /etc/config/qpkg.conf

Declare a new dummy package by adding something like that in this file:

[autorun]
Name = autorun
Version = 0.1
Author = neomilium
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/autorun/autorun.sh
Install_Path = /share/MD0_DATA/.qpkg/autorun
Enable = TRUE

As you can see, Shell is the interesting variable: at boot-time, QNAP OS will launch each QPKG's Shell variable content.

Note: if your NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables and adapt the following commands to your needs.

Create the dummy package directory:
# mkdir /share/MD0_DATA/.qpkg/autorun

Create the autorun script with the contents of your choice:
# vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
Note: don't forget "#!/bin/sh" at the beginning of script.

Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
Reboot and enjoy!

from

Wednesday, August 21, 2013

Check blackout length (for BeagleBone Black)

timer.sh:
root@beaglebone:~/Desktop# cat timer.sh

#!/bin/bash

KEEPALIVE=/home/root/Desktop/log.txt
#TARGET=/home/root/Desktop/log_$(date -r $SOURCE +"%Y-%m-%d_%H-%M-%S").txt
TARGET=/home/root/Desktop/log_$(date -d "today" +"%Y-%m-%d_%H-%M-%S").txt
BOOT=/home/root/Desktop/boot.txt


# se esiste bootfile salva log.txt con ora corrente
if [ -e $BOOT ]
then
echo "$BOOT exist"
mv $KEEPALIVE $TARGET
rm $BOOT
fi

echo $(date -d "today" +"%Y-%m-%d %H:%M:%S") > $KEEPALIVE

timerboot.sh:
root@beaglebone:~/Desktop# cat timerboot.sh

#!/bin/bash

TARGET=/home/root/Desktop/boot.txt

echo "boot" > $TARGET

crontab:
root@beaglebone:~/Desktop# crontab -l

30 * * * *    /usr/bin/ntpdate-sync silent
*/5 * * * * /home/root/Desktop/timer.sh
@reboot /home/root/Desktop/timerboot.sh

Linux scripting to save blackouts hours

In my house sometimes I got a blackout, don't know why yet, but it happens.
Now, I want to know for how long blackout lasted.
I made up some simple bash scripting for this; possible next actions, link this info to a nagios or ninjablock application to receive notifications:

timer.sh:
root@beaglebone:~/Desktop# cat timer.sh

#!/bin/bash
TARGET=/home/root/Desktop/log.txt
echo $(date -d "today" +"%Y-%m-%d %H:%M:%S") > $TARGET

timerdown.sh: 
root@beaglebone:~/Desktop# cat timerdown.sh

#!/bin/bash
SOURCE=/home/root/Desktop/log.txt
TARGET=/home/root/Desktop/log_$(date -r $SOURCE +"%Y-%m-%d_%H-%M-%S").txt
touch $TARGET
mv $SOURCE $TARGET

crontab:
root@beaglebone:~/Desktop# crontab -l

30 * * * * /usr/bin/ntpdate-sync silent
*/5 * * * * /home/root/Desktop/timer.sh
@reboot /home/root/Desktop/timerdown.sh

BeagleBone Black: setting the correct timezone

Set your localtime file according to your time zone

Next you need to set your /etc/localtime file according to your timezone.
If you go into the directory /usr/share/zoneinfo you will see a lot of different timezone files, e.g. 

root@beaglebone:/usr/share/zoneinfo# ls
Africa CET EST5EDT GMT Greenwich MST7MDT PST8PDT UCT WET America CST6CDT Etc GMT+0 HST NZ Pacific UTC Zulu Asia EET Europe GMT-0 MET NZ-CHAT ROC Universal iso3166.tab Australia EST GB GMT0 MST PRC ROK W-SU zone.tab

You can copy the file directly or use one of the presets. In my case, Irish time is the same as London time. So,

root@beaglebone:/usr/share/zoneinfo# cd Europe/
root@beaglebone:/usr/share/zoneinfo/Europe# ls -al

total 20 
drwxr-xr-x 2 root root 4096 Mar 18 2013 . 
drwxr-xr-x 9 root root 4096 Jan 1 11:42 .. 
-rw-r--r-- 1 root root 3661 Mar 19 2013 London
-rw-r--r-- 1 root root 1464 Mar 19 2013 Moscow
-rw-r--r-- 1 root root 2945 Mar 19 2013 Paris

So, I am going to use the London file – back to the /etc directory:

root@beaglebone:/etc# rm localtime
root@beaglebone:/etc# ln -s /usr/share/zoneinfo/Europe/London /etc/localtime

by setting a symbolic link from /etc/localtime to the timezone file. The advantage of this over copying the file is that you can see the timezone that was set when you ls:

root@beaglebone:/etc# ls -al|grep localtime 
lrwxrwxrwx 1 root root 33 Jan 1 12:05 localtime -> /usr/share/zoneinfo/Europe/London

root@beaglebone:/etc# ls -al localtime 
lrwxrwxrwx 1 root root 33 Jan 1 12:05 localtime -> /usr/share/zoneinfo/Europe/London

source

Tuesday, July 30, 2013

Automatic set proxy on boot on Linux

You can set the variable globally in /etc/profile or by creating a script for your variable in /etc/profile.d:

export http_proxy="http://\:@:"
export https_proxy="http://\:@:"

Use network proxy environment settings for "sudo" user on Linux

the trick is to add enviroment variables to sudoers config:
sudo nano /etc/sudoers
add these lines:
Defaults env_keep +="http_proxy"
Defaults env_keep +="https_proxy"
from ArchLinux wiki https://wiki.archlinux.org/index.php/Sudo#Environment_variables_.28Outdated.3F.29