Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Monday, September 22, 2014

Manage Files Older than certain days

Today, I found a quite useful trick to list, delete or manage file that is older than certain days
This trick is simple to housekeep and simply check if archiving process is running well day on day basis.

The basic is

find /path/to/files* -mtime +5 -exec command {} \;

You may easily change the command to :

ls -- to list files
rm -- delete
tar -czf -- to create a tar.gz archive

or anything you may try, and let me know the result.

Change the /path/to/files* to exact path you want to check
+5 means older than 5 days. Simply change to let say +30 for files older than 30 days

This should work on any linux. Tested on Ubuntu, CentOS, and RedHat.
Hope this small trick could save your precious working time, and let more time for having fun :)

Cheers

Wednesday, August 26, 2009

PHP Multithreading for beginner

This entry is inspired by Iman "Sapi". Thank you sapi.

PHP has become not just web scripting language. Now PHP also widely use for simple server side shell scripting. PHP is proven a strong platform do perform database and www operation, such as querying, CURL-ing, http tunnelling and API's function.


The differences is at output and how long the script allowed to runs. Output of web-based PHP mostly markup languages bounded with fancy images and media files. But shell scripting only output only-God-knows log messages, and has no time limit.


Supported by enormous of active developer, PHP server scripting are very easy to those actively build applications under web. PHP also powerful to build heavy-duty task, such as file backup, backend server-to-server processes. Like Java, PHP5 now has the capability for multithreading, to increase processing speed. The only limit is memory and processor. But I found for doing certain task (my case) it's much lighter than using Java.

To enable, first make sure you've installed pcntl extension. On Ubuntu machine, install the extension files :
$ sudo apt-get install php5-dev
$ cd ~
$ mkdir php-temp
$ cd php-temp
$ sudo apt-get source php5
$ cd php5-xx.xx/ext/pcntl (xx.xx is your PHP5 subversion, pressing tab would reveal it)
$ sudo phpize
$ sudo ./configure
$ sudo make

Copy the compiled extension into modules library.
$ cp modules/* /usr/lib/php5/xxxxxx/ (xxxxx is php library date)

Restart apache
$ sudo /etc/init.d/apache2 restart


Next is, try copy and paste this simple script simulate the multithreading.
Further reading, please visit PHP official manual page. Happy multi-threading.



$children = 5;

for ($i=1; $i<=$children; $i++) {
$pid = pcntl_fork();
if ($pid == -1) {
SaveLog("THREADING","could not fork thread $i");
die("could not fork\n");
}
else if ($pid) {
# If we are the parent, we did our job of giving birth,
# now lets finish our job and die!
SaveLog("THREADING","Parent thread exiting..");
exit(0);
}
else {
# Since we are the child, fork so that init will become our parent. Init
# is good at wait()ing on children - ie: reaping.
$cpid = pcntl_fork();
if ($cpid == -1) {
SaveLog("THREADING","could not fork in child process $i");
die("could not fork in child process\n");
}
if (!$cpid) {
# Put your real task here, dont forget they're run as separate process, make sure no dependency each thread
SaveLog("THREADING","Thread $i started");
$result = StupidTask(10000000);
SaveLog("TASK","Result on thread $i : $result");
SaveLog("THREADING","Thread $i finished");
# Don't forget to exit after the child processing is done. Certainly
# change this exit code if you need to however.
exit(0);
}
}
}

function StupidTask($count) {
for ($i=1;$i<$count;$i++) {
}
return "I'm done doing stupid thing for $count times";
}

function SaveLog($type,$msg) {
global $logfile;
file_put_contents($logfile,date('Y-m-d H:i:s') . ' ' . $type . ' ' . $msg . "\n",FILE_APPEND);
return true;
}

Friday, July 10, 2009

Install fancy fonts for your Ubuntu Java apps

Java is well-known development platform, not for enterprise system, but also to small application like rendering picture and processing video. One of the application I involve it, requires so many fancy fonts to make the output more beautiful.

It's not common that Java requires such fonts, but this really matters as it related to graphic and colour. Under Ubuntu box, Font that Java loads different from the system has. So we might need to copy all needed fonts into folder that reads by JRE.

For Ubuntu, Java fonts is available under folder /usr/lib/jvm/{your-java-version-folder}/jre/libs/fonts/. To find out what java version your working, see configuration of your Java apps. Refer to it, browse into /usr/lib/jvm, and match any possible version that's closest match.

By default no configuration file needed to edit if all your required fonts is satisfied. Once copied, reload your Java Application.

Wednesday, March 11, 2009

Setting up gammu with smsd

Gammu is the most popular program to build customized sms  server. It can connect to various of handset, from the oldest model until recently launched model.  Also it support populars os(es) such as Microsoft Windows and Linux Ubuntu. 


To setup gammu under windows simply download win32 binary from gammu site. For Ubuntu, even easier.

$ sudo apt-install gammu

That's all.

Once installed try edit gammurc (gammu config files). Windows version, config file will be in same folder as gammu.exe. For Ubuntu version, the config file is in /etc. Edit where needed.
My working setting is :


[gammu]

port = /dev/ttyS1
;model = 6110
connection = at19200
;synchronizetime = yes
logfile = /home/says/gammulog
logformat = textall
;use_locking = yes
;gammuloc = locfile
;startinfo = yes
;gammucoding = utf8
;rsslevel = teststable
;usephonedb = yes


To test out :

$ gammu --identify


On success connection it should display our gsm modem properties.

Manufacturer : Nokia
Model : 6150 (NSM-1)
Firmware : 4.12 E (02-12-98)
Hardware : 2320
IMEI : 493002107068660
Original IMEI : 493002107068660
Manufactured : 1298
Product code : 0502690
Simlock 1 : MCC+MNC 00101, opened, factory, counter 0
Simlock 2 : GID1 0000, opened, factory, counter 0
Simlock 3 : GID2 0000, opened, factory, counter 0
Simlock 4 : MSIN 0000000001, opened, factory, counter 0
MSID : 823c21bb67cc5d6aab0f3caae6
MCU checksum : 4057
DSP ROM : 4


Next is configure smsd engine. Create a smsd config file. Ussually named smsdrc. Edit where needed. Put the file in same folder as we running Gammu. I strongly recommend using files style, as you can easily to customize the system.

[smsd]
PIN = 327426
logfile = /home/says/sms/logs/smsdlog
commtimeout = 10
sendtimeout = 20
#receivefrequency = 0
#resetfrequency = 0
deliveryreport = log
phoneid = mdsms

inboxpath = /home/says/sms/inbox/
outboxpath = /home/says/sms/outbox/
sentsmspath = /home/says/sms/sent/
errorsmspath = /home/says/sms/error/
inboxformat = standard
transmitformat = auto

The main part of the system just to read incoming sms save it to /inbox, send any message that we put in /outbox. Next gammu smsd able to do the rest.

Next, create an agent just to read message source to be send out, and retrieve incoming msg in inbox to store in your database. last thing is create nice fancy interface, of course dont forget the user authentication. Then hola, your own sms server is ready to serve.


Download : php agent to read & delete files

Tuesday, December 16, 2008

Sharing USB files on Ubuntu

USB flash disk is no doubt industry standard for portable storage. Everybody carrying one or more, even that's a "pure" USB flash disk or any portable device with storage, since most these modern gadget has USB Mass Storage profile.

To share these files on Ubuntu for other users, you may use Samba file sharing. Samba is file sharing server act just like Windows share, for sharing files and printer. To install samba on ubuntu as simple as installing other program.

> sudo apt-get install samba

Once installed, start sharing folder by right-click on a folder name opened using Nautilus (the de-facto file manager) -> Sharing. Make sure the file you going to share has appropriate permission. To be able to read, at least has read privileges on "other". Chmod them to 644.

To be able to share USB files, you need to change default privileges of USB flash disk files. As it auto-mounted when you insert it, USB flash disk get file permission setting from gnome setting editor. Change them with :

> gconf-editor


Go to system>storage>default_options>vfat, double click "mount_options" on the right, click "add", enter the text "fmask=000", click ok. Also double click on umask need to change to "000" (that's triple zero). Remember that's masking code not the mode itself. So umask = 000 equal to 777 filemode. Save it then remount the volume.

Tuesday, October 28, 2008

Create Profesional Chart using PHP

As it function spread, PHP also can be develop into reporting agent. But creating chart graphic report using php never been this easy before i found ChartDirector. ChartDirector is a programming module that enable creation of chart based on given numeric data.

To install ChartDirector, simply go to its download section. Choose your platform, then extract into web-browsable folder. For Windows installation supposed no issue to highlight here. On Ubuntu, after several attempt, finally I got the installation works.

For Linux (Ubuntu) version, extract the package tar.gz into a web browseable folder. Then copy all co
ntent of lib into PHP shared object (so) folder, including all dll and font files. Remember to copy not move as the original file is needed for web browsable folder as well. To find out correct folder where the so lies, create a phpinfo() script.


Next is create an include entry in INI file. For Ubuntu, you may create a new file name it : chartdir.ini, put in /etc/php5/apache2/conf.d/ along with existing modules. For other system, put in php.ini :

#configuration for php chart director module
extension=phpchartdir520.dll

Remember, eventhough the loaded extention is dll, but it is a Linux extention. Do not load the so file as it will reported non-valid PHP module error. Restart your apache server. To make sure your installation is runs well, rerun the phpinfo, you should get this of your info page

This software is shareware, and lots of platform and programming language are available not just PHP. Even its cracks are easily to find on the net, please support by purchasing full version licences.

Wednesday, October 15, 2008

Enrich your browsing experience under Ubuntu

Ubuntu now is not just geek box. Web developer also can be more convenient using it by installing various browser in it.
Not less than 4 browsers you can install:

1. Firefox
no doubt, this is de facto browser, most widely used among Ubuntu user, as it installed by default.

2. Opera

Eventhough Opera market share is not as big as Firefox, this browser has certain fanatic fans. Deliver a unique render style, browsing using Opera give a different feel.
To install, go to www.opera.com linux download section. Select Ubuntu deb package. Double click downloaded deb file, follow the installation instruction. Otherwise, you may follow instruction by ubuntu forum

3. Internet Explorer

IE is the most widely used, as it come preinstalled with the OS that ruled PC user for years.
To install, follow instruction from my previous post.

4. Safari
Mac fans is unable to accept other browser, but safari. Run on wine, with some display issue, Safari can still shows its beauty. As it run on Wine emulator, simply download safari installation file, then run it.

All browsers above, only Firefox and Opera is running natively, while two others are emulated from Windows version. Meaning you have Wine installed properly before proceed to install them.
Overall, all browsers does have own characteristic and render style that a web developer should have installed them all.

Tuesday, June 24, 2008

Repair Grub Entry after a Ubuntu Hardy Updates

Just few months after its official launch, Ubuntu Hardy Heron has release some kernel updates. Every kernel updates suggest us to create a new Grub menu. But unfortunately, if you choose wrong option, it might overwrite original grub menu entries, including non-ubuntu entries. I accidentally chosen let aptititute update whole list.

If this happen to you, no worry. No need reinstallation of OS. First is recover your lost non-Linux entries. Mostly user mixed with Microsoft OS, like Windows XP or Vista. Insert Windows XP or Vista installation CD. Upon setup option, instead of setup, select "Repair A Windows Installation". Choose command line repair. After a command line windows shows, type :
$ fixboot
$ fixmbr

For more command, your can type :
$ help

Close repair session, remove Windows CD, and then reboot. Now your box should be able to boot Windows. Next is repair grub entries. Insert Ubuntu Live CD, then reboot. Open a terminal session from Start Menu -> Accessories -> Terminal. Type :

$ sudo grub
grub >find /boot/grub/stage1

From given information, setup grub root and entries

grub> root (hd0,1)
grub> setup (hd0)
grub> quit


More reading about dual boot tips and emergency tips your may read Ubuntu official tutorial

Saturday, May 10, 2008

Firefox 2 on Ubuntu Hardy Heron

Ubuntu 8.04 Hardy Heron just rolled out from it's beta stage. For those ubuntu-lover, we just can't wait what are new features on this new release, especially that can be seen directly from its fancy desktop.

Firefox is one of among list. Even Firefox 3 offer lot of new browsing features, but unfortunately, I don't like beta softwares. Even it proved stable, but one thing is sure, it slow down my laptop, compare to previous version. Maybe you have same opinion with me.
Also, lot of my favorite plugin does not work with Firefox 3, including Foxmarks.

To roll back using Firefox 2 as Ubuntu Hardy default browser, simply uninstall firefox 3, get firefox 2 and change some shortcut links. Open a terminal session

$ sudo aptitute remove firefox
$ sudo aptitute remove firefox-3
$ sudo apt-get install firefox-2

Next is change default command firefox shell script to firefox-2, by type :
$ cd /usr/bin
$ sudo ln -s firefox-2 firefox

As bonus here is an article for you who love Internet Explorer, and wish to run it on your Ubuntu. Installing Wine, Internet Explorer and Visio 2003

Just like Asus tagline, now you can enjoy rock-solid heart-touching Firefox 2 :) and alternative IE on your Ubuntu.

Saturday, March 8, 2008

Running MS Visio 2003 On Ubuntu

Ubuntu is now become main stream OS that used by desktop user, not just alternate to those already in the stream like Macintosh MacOS and Microsoft Windows family. By this time, latest Ubuntu version is Gutsy Gibbon 7.10.

Most task that require Windows now can be run on Linux as well thanks to Wine, a Windows emulation program. But to make a Windows based software install and runs smoothly on Linux, need some quite tricks. These knowledge is shared among internet user which is sometime not a comprehensive how-to guide. There are some tips that helped me so much on running MS Visio 2003 on linux.

First of all make sure you have latest Wine version installed. Run
$ sudo gedit /etc/apt/sources.list
Add following repository to your apt-get repo list :
deb http://wine.budgetdedicated.com/apt feisty main

It's recommended to completely uninstall existing Wine installation and rename folder /home/your_user/.wine into something else.
Now install Wine and supporting components :

$ sudo apt-get update
$ sudo apt-get install wine
$ sudo apt-get install cabextract

Install IE4Linux. IE4Linux needed by certain part of the Visio installation and runtime.

$ wget ttp://www.tatanka.com.br/ies4linux/downloads/ies4linux-2.0.tar.gz -O - | tar xvzf -

or this alternate link :

$ wget http://modzer0.cs.uaf.edu/~hardwarehank/files/ies4linux-2.0.tar.gz -O - | tar xvzf -

When completed, run :

$ cd ies4linux/
$ ./ies4linux

Follow the installation by choosing some simple installation option. Now you have IE installed in your Ubuntu box.

Next proceed with Ms Visio 2003 installation. Insert the CD into CD-ROM or mount appropriate file. In terminal, change to source folder then run :

$ wine setup.exe
A installation wizard will show up, follow the wizard as you install on Windows.
Once completed, try to run it.
Application -> Wine ->Programs->Microsoft Office ->Microsoft Office Visio 2003

If you get error message "IOPL not enabled", run
$ winecfg

On application tab, change Windows version to Windows XP. On libraries tab, add new library
gdiplus.dll (native)
Save and close config window. And now your Visio should be run perfectly. Any other issue, please check out the community testing result.

My Environment :
Linux Ubuntu Gutsy Gibbon 7.10, 32 bit version
Wine 0.9.57
Microsoft Visio 2003 (11.3216.5606)

Tuesday, February 5, 2008

Moving SVN repository to another machine

SVN is a great tool for collaborated programmer to keep every copy files up to date and track changes made by everyone. In my case, I use SVN for synchronize my working file between my workstation and portable one. If you haven't get the SVN installed, follow the instruction given from the SVN site. For Ubuntu user (like me) there's a useful instalation guide here.
Since it's a collaboration tool across the internet, SVN repository supposed can be move from one server to another. Even the server are using different OS. First, you need to dump current repository to a dump file (assummed you have existing repo at /opt/svn/svnrepo/) :

$svnadmin dump /opt/svn/svnrepo > svnrepo.dump

Make the file smaller by compressing it :

$tar -cvzf svnrepo.tar.gz svnrepo.dump

Then transfer the file to new server using SCP (assummed your SSH using different port number 222) :

$scp -P 222 svnrepo.tar.gz username@server2:/home/username/

Once transferred, login to server2 :

$ssh username@server2 -p 222


Extract the dump file and copy to new location (assummed at /opt/svn/svnrepo/)

$tar -xvzf svnrepo.tar.gz
$mkdir /opt/svn/
$mv svnrepo.dump /opt/svn/

Import dump file into running SVN server :

$svnadmin create svnrepo
$svnadmin load svnrepo < face="verdana">Once you complete the step, you can delete the .dump file and the tar.gz file as well.
When running the SVN server make sure it loads repo from the location we just imported by

$svnserve -d -r /opt/svn/svnrepo/

Dont forget on SVN client side, make sure to relocate repo to new location as well