May 13

rsync is an open source utility that provides fast incremental file transfer. rsync is freely available under the GNU General Public License and is currently being maintained by Wayne Davison.

The command for automatic backup

#On the rsync server [192.168.1.29].
touch /var/log/rsyncd.log

#Add the following lines to /etc/rsyncd.conf file.
motd file = /home/rsync/welcome.msg
log file = /var/log/rsyncd.log
use chroot = yes
[server_bkp]
path = /var/www/html
comment = Default rsync module
read only = yes
list = yes
uid = root
gid = root
max connections = 20

#Allowable client machines. Comma separated list.
hosts allow = 192.168.1.70

#Now restart the rsync daemon.
rsync –daemon

#On the client side [192.168.1.70].
mkdir /backup/html

#Set crontab for the backup.
crontab -e
#30 11 * * * /usr/bin/rsync -aqz 192.168.1.29::server_bkp /backup/html

For more information please visit http://rsync.samba.org

written by admin

Feb 19

The buzz is the computing world is about getting on to the clouds. Cloud computing is a general term for anything that involves delivering hosted services over the Internet. These services are broadly divided into three categories: Infrastructure-as-a-Service (IaaS), Platform-as-a-Service (PaaS) and Software-as-a-Service (SaaS).The vague concept has been around for decades, and it is still a doozy.
A “Cloud” is a bag of stuff that is out there, in no particular place, but you can reach into it whenever you need it, or as they say “on demand”. You can apply this to servers, to apps – features and capabilities – to team members that are there when you need them. A cloud resource should be globally accessible, and hosted, so you don’t have to worry about how to get to it or maintain it. The idea that we can rub our laptop and summon out of the smoke a powerful genie, a huge bag of resources, is emotionally intense. That’s why “Cloud” is such a great marketing term.

What you need?

Computing devices with enough processing power to get online forget about the storage space and application.

The advantage

The cloud brings down the cost of a continuously available computing instance by 30%.

For those planning their cloud usage, you can use Amazon’s handy cloud services calculator to run your own scenarios.

written by admin \\ tags:

Sep 29

Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.

Due to the length of the words, the terms are frequently abbreviated to the numeronyms i18n (where 18 stands for the number of letters between the first i and last n in internationalization, a usage coined at DEC in the 1970s or 80s[1]) and L10n respectively. The capital L in L10n helps to distinguish it from the lowercase i in i18n.

Internationalization and localization instructions

Basic Terms

pot-file: Text file automatically generated with rake task (rake updatepo) or rgettext that shows all the original messages (msgid) inside the app code. Developers should generate this files and send them to translators as a template to write the po files (translated version of the pot file for a language).

po-file: Text file which is language-specific. It includes msgid(Original message) and msgstr(Translated message)

mo-file: Binary Files which are created from po-files with rake task (rake makemo) or rmsgfmt. The Ruby-GetText-Package library reads this compiled mo-files, not po-files.

File Maintenance

To do I18n maintenance, you need to install ruby-gettext-package

As it is not in the gem repository, you need to:
1) Download ruby-gettext-package- from here
2) Extract ruby-gettext-package-
3) Go to the extracted directory and run “sudo ruby setup.rb”

How to add a new language?:

1) create language directory inside “po” folder (eg: es/)
2) Go inside new language folder and run: msginit -i ../ur_application_name.pot -o ur_application_name.po

How to update po files (when new keys are added or modified)?:
1) Go to app folder and run: rake updatepo

To recompile files (when you get new/modifed po files translated)
1) Go to app folder and run: rake makemo

How to add i18n to a Page?


Basics

If you want to translate a text. Eg. “This text” You need to simple call _(). E.g _(“This text”).

The key will be added to the po file and someone will translate it later. If the key is already in the po file (and compiled in the mo file) it will appear translated. You should choose keys that make sense and that might be reusable. Try not to pick very long texts as keys.

Model: All field names are automatically added to the po file from the database (whith the rake task). If you need to define constants or translate new error messages, you can use the N_() function. For more information, check: http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html

written by admin

Sep 24

  GIT
   
What is Git?
    Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git was initially designed and developed by Linus Torvalds for Linux kernel development.
To install Git on Debian/Ubuntu based Linux distribution use

 apt-get install git-core 

     

Run once to create your local work branch

git checkout -b  

Then make changes and commit to local branch.

Commit good practices:

  • If you commit with git-gui, please inspect diff of every file included in the commit. You should not modify or delete any files that are not part of logic changes related to a task.
    If you do not have a gui program to commit, inspect diff from command line: git-status – check files that need to be added/removed and git-diff to inspect changed files.
  • Enter a good description for commit: first line should be a  summary up to 80 chars, other lines can contain more descriptive message, if commit is related to a ticket use re #ticket_number to automatically add a comment to the ticket with commit description.

To push to repository:

rake git:push

this command will update code from remote repository and will rebase your work branch with master, merge master branch  and it will push your changes to remote server.

To update the code from central repository

rake git:update
git checkout master
git checkout -b

commit your changes and after push this branch to remote

git push origin  
  • You want to copy one commit from other branch to current branch
    git checkout current_branch
    git cherry-pick sha_id_from_other_branch

    Using gitk: 

    1. right click on current branch and click check out this branch from popup menu
    2. click on commit from other branch, right-click and select Cherry-pick this commit
  • You forget to add some files to previous commit:
    git reset --soft HEAD^
    # do some changes, add files that you forget
    git commit -c ORIG_HEAD

    Using git-gui:

    1. Click Amend radio button above text area for commit description
    2. Add/remove files from commit
    3. Commit new changes

   

You can find more information regarding the Git here.
You can also find some useful miscellaneous git tools here

written by admin \\ tags:

Jul 13

1 Command to burn a dvd image to DVD.
growisofs -dvd-compat -Z /dev/dvd=/root/fedora.iso

2 Command to burn a cd image to CD.
cdrecord -v speed=20 dev=/dev/scd0 /root/pfSense-1.2-RC3-LiveCD-Installer.iso

3 Command to make DVD image.
dd if=/dev/scd0 of=/root/Desktop/fedora.iso
cd /root/fc10

4 To make bootable iso of a directory.
mkisofs -J -R -o /opt/fc10.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table /root/fc10

5 To make iso of a directory.
mkisofs -r -o /tmp/var-www-disk1.iso /var/www

6 To make a data dvd.
growisofs -Z /dev/scd0 -R -J /home/happyuser
growisofs -Z /dev/dvd -R -J /some/files

7 Converting avi to DVD and burning the DVD.
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9:acodec=ac3:abitrate=192 -ofps 25 -o your_video.mpg your_video.avi
dvdauthor -o Memento -x dvd.xml
mplayer dvd:// -dvd-device ./Memento/
growisofs -dvd-compat -Z /dev/dvdrw -dvd-video ./Memento/

8 To format DVD-RW
dvd+rw-format -force /dev/dvd

9 To create ISO images of directories on your hard drive.
mkisofs -o Directory.iso Directory

10 To format CD-RW
cdrecord blank=fast dev=1,0,0

11 To create an empty disk image, to be used as the disk for an emulator for example, one can get data from /dev/zero. To create a 10mb image:
dd if=/dev/zero of=myimage bs=1024 count=10240

12 To merge more than one avi files.
avimerge -o filename.avi -i first_file.avi second_file.avi

13 To convert avi to mpeg-2
mencoder /root/ItalianJob.avi -mf fps=1 -o /opt/ItalianJob.mpg -ovc lavc -oac pcm -lavcopts vcodec=mpeg2video

14 To convert mpg to avi.
mencoder /editor/Seval.mpg -ovc xvid -oac mp3lame -xvidencopts bitrate=800 -o /opt/Seval.avi

15 To convert all jpeg files in the current directory to avi.
mencoder “mf://*.jpg” -mf fps=1 -o outputs.avi -ovc lavc -lavcopts vcodec=mpeg4

written by admin

Jun 25

1. On your firewall (you do have one don’t you?) check the incoming MySQL port and if 3306 is open, close it. If this port is left open it can pose both a security and server abuse threat since not only can hackers attempt to break into MySQL, any user can host their SQL database on your server and access it from another host and so (ab)use your server resources

2. Check /tmp permissions. /tmp should be chmod 1777

3. Check /tmp ownership /tmp should be owned by root:root

4. Check /etc/cron.daily/logrotate for /tmp noexec workaround. Due to a bug in logrotate if /tmp is mounted with the noexec option, you need to have logrotate use a different temporary directory. If you don’t do this syslog may not restart correctly and will write to the wrong (older) log files.

5. Check /var/tmp permissions. /var/tmp should be chmod 1777

6. Check /var/tmp ownership. /var/tmp should be owned by root:root

7. Check /var/tmp is mounted as a filesystem. /var/tmp should either be symlinked to /tmp or mounted as a filesystem

8. Check /var/tmp is mounted noexec,nosuid. /var/tmp isn’t mounted with the noexec,nosuid options (currently: none). You should consider adding a mountpoint into /etc/fstab for /var/tmp with those options

9. Check /usr/tmp permissions. /usr/tmp should be chmod 1777

10. Check /usr/tmp ownership. /usr/tmp should be owned by root:root

11. Check /usr/tmp is mounted as a filesystem or is a symlink to /tmp. /usr/tmp should either be symlinked to /tmp or mounted as a filesystem.
Check /etc/resolv.conf for localhost entry. You should not specify 127.0.0.1 or localhost as a nameserver in /etc/resolv.conf – use the servers main IP address instead

12. Check /etc/named.conf for recursion restrictions. If you have a local DNS server running but do not have any recursion restrictions set in /etc/named.conf this is a security and performance risk and you should look at restricting recursive lookups to the local IP addresses only. Unrestricted recursive lookups are as good as a DDoS attack against your system. They will eat up all your system resources

13. Check server runlevel. For a secure server environment you should only run the server at runlevel 3. You can fix this by editing /etc/inittab and changing the initdefault line to:
id:3:initdefault: and then rebooting the server.

14. Check nobody cron. You have a nobody cron log file – you should check that this has not been created by an exploit.

15. Check Operating System support. Make certain that your OS version is still supported by the manufacturer and that upgrades continue to be available.

16. Check SSHv1 is disabled. You should disable SSHv1 by editing /etc/ssh/sshd_config and setting: Protocol 2 (remove the hash # from in front of the line and edit out the 1.1)

17. Check SSH on non-standard port. Moving SSH to a non-standard port avoids basic SSH port scans. Edit /etc/ssh/sshd_config and setting: Port nnnn Where nnnn is a port of your choosing. Don’t forget to open the port in the firewall first!

18. Check SSH PasswordAuthentication. For ultimate SSH security, you might want to consider disabling PasswordAuthentication and only allow access using PubkeyAuthentication.

19. Check telnet port 23 is not in use. Close this port in your firewall. Telnet is an insecure protocol and you should disable the telnet daemon if it is running

20. Check shell resource limits. You should enable shell resource limits to prevent shell users from consuming server resources – DOS exploits typically do this. If you are using cPanel/WHM set Shell Fork Bomb Protection.

21. Disable all instances of IRC – BitchX, bnc, eggdrop, generic-sniffers, guardservices, ircd, psyBNC, ptlink. If you are using WHM you can do this in the Background Process Killer.

22. Check apache for mod_security if not installed install it from source.

23. Check apache for mod_evasive. You should install the mod_evasive apache module from source to help prevent DOS attacks against apache. Note that this module breaks FrontPage functionality.

24. Check apache for RLimitCPU. You should set a value RLimitCPU to prevent runaway scripts from consuming server resources – DOS exploits can typically do this.

25. Check apache for RLimitMEM. You should set a value RLimitMEM to prevent runaway scripts from consuming server resources – DOS exploits can typically do this.

written by admin

Jun 09

1 To get hard disk information.
hdparm -I /dev/sda

2 Search and replace option in vi.
:%s/old/new/g

3 To make an icon.
convert -size 900×120 xc:black -font Times-Roman -pointsize 100 -fill green -annotate +20+80 ‘Linux is the Best’ -fill green -annotate +25+90 ‘Linux is the Best’ -trim +repage logo1.png

4 To replace one word with another with the backup of the original one.
sed -ibackup s/orange/grapes/g sedd

5 To search for a particular word and delete it.
find / -name aaa* -delete

6 To delete the last 30 days files. For files before 30 days +30.
find /root/wallpapers/ -mtime -30 | xargs /bin/rm -f

7 Command to dump partitions, directory etc..
dump -0aj -f /back/mydump /dev/sda2

8 Command to restore the dumped partition.
restore -rf mydump /back

9 To convert all jpeg files in the current directory to avi.
mencoder “mf://*.jpg” -mf fps=1 -o outputs.avi -ovc lavc -lavcopts vcodec=mpeg4

10 To convert avi to mpeg-2
mencoder /root/ItalianJob.avi -mf fps=1 -o /opt/ItalianJob.mpg -ovc lavc -oac pcm -lavcopts vcodec=mpeg2video

11 To convert mpg to avi.
mencoder /editor/Seval.mpg -ovc xvid -oac mp3lame -xvidencopts bitrate=800 -o /opt/Seval.avi

12 To delete lines 23-47 using vim or vi.
:23,47 d

13 Command to display the installed fonts.
fc-list

14 To check the CD/DVD drive/eject.
fuser /media/cdrom [eject]/[eject -p]

15 To kill the process.
fuser -k /media/cdrom

16 Find all files that have the .exe extension in the current directory.
find . -name \*.exe

17 Lists all of the files in the queue, as well as the user, the job number, the size and the root directories from which the print jobs originate.
lpq

18 To free memory when memory is in short.
memhog 500m

19 Cron to shutdown machine.
55 23 * * * /sbin/shutdown -h now

20 To password protect a zip file.
zip -e -r /root/Desktop/new /root/Desktop/old

21 To delete all hidden files from current directory.
rm -rf .*

22 Extracting files to a specific directory
unzip Commonly\ Used\ Malayalam\ Fonts.zip -d /usr/share/X11/fonts/TTF/ -(Sorry! I’m a Malayali)

23 To format CD-RW
cdrecord blank=fast dev=1,0,0

24 To stop all process except your shell.
kill 0

25 To disable usb in linux, eg. fedora 8.
mv /lib/modules/2.6.23.1-42.fc8/kernel/drivers/usb/storage/usb-storage.ko /opt/

written by admin

May 21

ls – Display the contents of the current directory.
pwd – Display Present working directory.
cd .. – Change directories.
cd - Enter into that directory.
mv – Change the name of a directory.
cp – Copy files and directories.
startx – Start the GUI.
halt – To shut down the system.
kill/killall – Stop a process from running. The difference between the two commands is that kill requires the PID (process ID number) and killall requires only the executable name.
logout – To quit using the system.
mkdir – Make directories Create the Directory(ies), if they do not already exist.
top – Displays the taks that are currently running.
who – Show who is logged on.
man – To help you understand how to use a command.
mount/umount -Mount a file system.
cal – Displays a calendar.
clear – Clears the terminal screen.
su/su- – Allows one user to temporarily become another user/ – Switching to root path.
vi and nano – These are some most widely used editors in linux.
ps – Used to find process status.
ifconfig – Configure a network interface and also to find the ip of machine.
cat – Concatenate one or more files.
find – Used to search files in a directory .
free – Display statistics about memory usage.
df-h – To find the amount of hard disk space and what’s free .

written by admin \\ tags: ,

May 21

will_paginate‘ is one of the most widely used plugins in most of the ruby on rails projects.will_paginate is an alternative to the classic_pagination plugin, which is the pagination plugin that basically took the pre Rails 2.0 pagination implementation and packaged it in plugin form
1.How to Install will_paginate
the simple method
gem install mislav-will_paginate

There are some other method you can find it here.

2.Example

In controller
@gallery=Gallery.find(:all,:order=>”position asc”).paginate :page => page,:per_page=>10

where :per_page passes the number of gallery you want to display.You can change it according to your need 1-100
will_paginate defines it to be 30 by default

In View

you can simply use

<%= will_paginate @gallery %>
some advanced …

<% if @gallery.previous_page %>
<%= will_paginate @gallery,:page_links=>false, :next_label => “”, :prev_label => image_tag(“/images/icon/arrow.png”, :border => “0″) %>
<% end %>

<% if @gallery.next_page %>
<%= will_paginate @gallery,:page_links=>false, :next_label => image_tag(“/images/icon/arrow.png”,, :border => “0″), :prev_label => “” %>
<% end %>

If we put page_links=>false then it won’t display 1,2,3… and next_label and prev_label => “” as null it won’t display Next and Prev

Ryan Bates made an awesome screencast check it out here

written by admin

Oct 13

How to install Ruby on Rails In Linux

$ su -
# yum install ruby ruby-rdoc ruby-irb

Note: If you get an error, similar to the following, just wait a while and try the above command again.

Loading “installonlyn” plugin
Existing lock /var/run/yum.pid: another copy is running as pid 2321. Aborting.

Note: If you get something similar to the following, just enter y.

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Importing GPG key 0x4F2A6FD2 “Fedora Project ” from /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
Is this ok [y/N]:

Install RubyGems via source

Note: Note: Latest version of RubyGems (1.3.3) .
Enter into the Terminal:

cd /tmp
wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
tar -zxvf rubygems-0.9.4.tgz
cd rubygems-0.9.4
# ruby setup.rb

Install Ruby on Rails using RubyGems

Enter into the Terminal:

# gem install -y rails

To check the installed gems on your local machine
gem list –local

written by rubyfreaks