Monday, November 11, 2013

Autospawn screen session on ssh connection

This is particularly useful in a situation where your ssh connection always get disconnected, and you have no privilege to tweak the ssh server settings to avoid that.


  1. First method, simple and easy, but will create multiple screens if you have more ssh sessions: 
    echo "screen -R" >> ~/.bash_profile; source ~/.bash_profile
  2. 2nd method, smarter than the above, will attach to the existing screen session if there is any, and create new one if none is available 
    echo "if $(screen -ls | grep -q pts); then screen -x; else screen -R; fi" >> ~/.bash_profile; source ~/.bash_profile

Tuesday, September 24, 2013

Changing background color theme in vim

Sometimes, when you open a document in vim, the color of the font and background is not easy on the eye, like below:













In order to encounter this, you can change the backgroud of vim to use light background, by using
:set background=light
or
:set bg=light
in vim to become like below:












You can change the backgound back to dark by using
:set background=dark
or
:set bg=dark
in vim.

That's all, hope this is going to be useful to you.


Monday, August 26, 2013

How to extract deb file without having dpkg

.deb files are regular ar archives. You can manipulate the file by using ar command.

For example, I have a package called lynx_2.8.8dev.15-2_all.deb in a centos box.

$ cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m

$ ls -lh
total 4.0K
-rw-rw-r--. 1 foo foo 3.9K Jan 18  2013 lynx_2.8.8dev.15-2_all.deb

To extract the file, just run ar x <.deb.filename>
$ ar x lynx_2.8.8dev.15-2_all.deb
You will see 3 files being extracted, control.tar.gz, data.tar.gz and debian binary.
$ ls
control.tar.gz  data.tar.gz  debian-binary  lynx_2.8.8dev.15-2_all.deb

debian-binary is a text file containing deb packaging version number.
$ cat debian-binary 
2.0

control.tar.gz contained control, preinst and md5sums.
$ tar -tf control.tar.gz ./
./md5sums
./control
./preinst

data.tar.gz is a compressed file containing the files which are going to be installed on the system.
$ tar -tf data.tar.gz ./
./usr/
./usr/share/
./usr/share/doc/
./usr/share/doc/lynx/
./usr/share/doc/lynx/copyright
./usr/share/doc/lynx/changelog.Debian.gz

Wednesday, July 10, 2013

Print to pdf from command

To enable this, there are 2 packages that you need to install, which are cups and cups-pdf. This has been tested on CentOS 5.5.

# yum install cups cups-pdf -y

Once installed, check which printer is available:

$ lpstat -p -d 

printer Cups-PDF is idle.  enabled since Wed 10 Jul 2013 09:30:05 AM EST

no system default destination

where lpstat is to show cups status information, -p is to tell lpstat to list all printers available and -d is to show the current default destination. In this case, this system has one printer installed, which is Cups-PDF.

To print, lpr command is needed:

$ echo "Printing some characters to a pdf file" | lpr -P Cups-PDF -J print01.pdf

where -P is to specify the printer name that you want to use, and -J is for the output file name.

The file will be saved in ~/Desktop, but this can be changed in /etc/cups/cups-pdf.conf.

$ ls ~/Desktop/

print01.pdf

Tuesday, June 11, 2013

Unmounting stuck nfs mounts

This usually happened when the nfs server is down, you cannot umount the nfs mount, because the system will say "not found or server not reachable"

$ sudo umount /opt/logs/production

umount.nfs: nfs.local:/var/lib/backup: not found / mounted or server not reachable

umount.nfs: nfs.local:/var/lib/backup: not found / mounted or server not reachable

To fix this, you need to force mount it with lazy flag:

$ sudo umount -f -l /opt/logs/production

where -f is to do force unmount, and -l is for lazy unmounting. From man:
"Lazy  unmount.  Detach  the  filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore."

That's all folks.