RSS Feed

Tag Archives: solution

bash less resize terminal overflow problem solved

I always have a problem with terminal emulator when using bash but not zsh. The problem can be produced like this,

  1. Open any terminal emulator (gnome-terminal, xfce4-terminal, etc)
  2. Run any command with less, such as “ls |less”
  3. Resize the window to larger size, such as maximize
  4. Quit less
  5. Type anything in the terminal, then the text will not wrap to new line if the text length beyond the window size before resie. And it will overflow to the same line and overwrite the prompt.

This problem can be solved by adding “shopt -s checkwinsize” in .bashrc.

Use WiFi router as switch

My workplace uses WiFi everywhere. Yet, my office room has a very poor WiFi signal. I was not sure whether it is poor signal problem or the ISP problem or any other problem, my Internet connection is suffered from the instability. When I use the Internet, or sending email, it is slow like heck and the messenger always disconnected from time to time. This is really annoyance. No Internet is better than slow or unstable Internet, because I need not wasting time to try to check mail or try to search information. Really wasting time.

Since my office room has an Ethernet cable port on the wall, and I was told by my colleague that using the cable is stabler and faster than using WiFi. Therefore, I decided to install a router in the room for me and my colleague. Without actual networking knowledge, I have to look for the information, and I found this page.

Since I do not have much information about the network topology of my workplace, I just try the solution and it works! In my workplace, when connected to WiFi network, then I can use the network printer and have Internet connection. My computer is assigned with IP address and also DNS servers IP addresses are given.

Thus, in order to install the router, yet can still connected to the network printer, online, and automatically obtain the IP address, I have to disable the NAT and DHCP server so that the router works as bridge or switch only.

I connected the computer to the Ethernet port on the wall to get the IP address of the default route and some other information such as DNS servers.

Since the router was no more acting as a router, and it did not assign IP address to the connected machine, with the available feature, I configured the router to use the remote DHCP server.

Enable the WiFi access point, then I can connect to the router with the wireless network and work as expected.

Since the network is using another IP address class, so I cannot access my router unless I configure my connection to connect to the router.

Though the connection is smooth and stable, there is a drawback. When using some Arch Linux commands such as yaourt or cURL, the connection does not work properly. Yet I have no idea how to solve this problem.



The problem of yaourt and cURL I faced was showing the message such as “port: 80 No route to host” when using yaourt, or “curl error: Couldn’t connect to server” when using cURL, for some domains. After looking for some information from Internet, some forums mentioned that it is caused by IPv6 problem, by disabling it, the problem can be solved.

I have tried to disable it from the Network Manager. Then I found that it is not the solution. To disable the IPv6 effectively, I have to disable it from sysctl too. Now everything works fine.

(Without the router, there is no such problem. I am not sure that whether the router is configured incorrectly.)

tcplay script

Posted on

Recently, when I was using TrueCrypt in Arch Linux to mount a truecrypt container file, it was very slow to mount the container. Furthermore, I also read that the TrueCrypt is discontinued.

Therefore, I decided to use the tcplay. However, it is a command-line. Arch Linux wiki page shows a good tutorial on how to use tcplay.

When using tcplay in Linux, unlike mounting the folder like encfs, tcplay requires losetup for loop device. Thus, it involves 3 steps to mount a truecrypt container: i) setup loop device, ii) setup device-mapper with tcplay, and iii) mount. Consequently, to unmount the truecrypt containter need to reverse these 3 steps.

In order to make my life easier, I wrote a simple script as following. Feel free to modify it.

# @author Allen Choong
# @date    2014-06-29
# @version    1.0.1
# Easy mount the truecrypt encryptinog by using tcplay.
# Assuming the truecrypt mounting name does not have whitespace.
# Changelog:
# 2014-06-29    1.0.1    Add display help if there is no argument
# 2014-06-02    1.0    Initial

tc_mount() {
  lo=`losetup -f`
  losetup "$lo" "$1"
  tcplay -m "`basename "$1"`" -d "$lo"
  mount "/dev/mapper/`basename "$1"`" "$2"

tc_unmount() {
  echo -en "Unmount ... "
  umount "/dev/mapper/$1"
  lo=`losetup -l | grep "$1" | cut -d ' ' -f 1`
  dmsetup remove "$1"
  losetup -d "$lo"
  echo "OK!"

mklist() {
  for ((i=1;$i<=$num;i++)) ; do
    ret+=$(echo " `expr $start + $i`")
  echo $ret

show_mount() {
  mount|grep '/dev/mapper' |while read l ; do num=`echo "$l" | tr ' ' '\n' | wc -l`;
    cutnum=$(mklist 3 `expr $num - 6`)
    echo "$l" | cut -d ' ' -f "1 $cutnum" | sed -e 's/\s/ => /'

#Get arguments
for ((i=0;i<=$#;i++)) ; do


#Print help
if [ $# == "0" ] ; then
  echo "This command requires root privilege."
  echo "Usage:"
  echo ""
  echo "To list the mounted container:"
  echo "`basename $0` -l"
  echo ""
  echo "To unmount (requires root):"
  echo "`basename $0` -u CONTAINER_FILENAME"
  echo "where CONTAINER_FILENAME is the device mapper name"
  echo ""

for ((i=1;i<=$#;i++)) ; do
  case ${args[$i]} in
      unmnt=`echo ${args[$i+1]}`

if [[ "$action" == "mount" ]] ; then
  tc_mount "$1" "$2"
elif [[ "$action" == "unmount" ]] ; then
  tc_unmount "$unmnt"

Update (2014-06-29):
In order to use this script, if you have a file called (already make file system),

sudo /path/to/mnt

After this, you can list the mounted point as, -l

To unmount the container,

sudo -u #where the is the device mapper name, not the path to the file

Preserving text information in LibreOffice/OpenOffice Impress when producing PDF

PDF file is usually my favourite format when distributing the documents to other end users. In Windows, we can install PDFCreator, subsequently there is a virtual printer which can be used to “print” the documents as a PDF format.

In Linux, there is no PDFCreator. Yet the most common alternative is CUPS-PDF. CUPS-PDF is depending on CUPS (Common Unix Printing System). If we want to do any printing in Linux, this is the package that we need.

However, in the recent CUPS-PDF (my current version is 2.6.1), if we print the file as PDF, all the text information are lost. The text is no more a vector data but the raster data. That is, if we zoom into it, they are pixelated. Moreover, we cannot highlight and copy the text. This makes the CUPS-PDF become less useful, and it is my last solution to produce the PDF file.

When using LibreOffice Writer and Calc, instead of using CUPS-PDF, I can “export directly as PDF”, which is a built-in export function. By this, the text information are all preserved.

However, when using the web browser like Firefox or Chromium, there is no “export directly as PDF” function. Fortunately, when we want to print, among the printers there is a “Print to File” printer. This is the solution in web browser. By “Print to File”, all the text information are preserved in PDF so that we can select and copy the text if needed.

LibreOffice Impress is a little different. We can also “export directly as PDF”, yet the output is the PDF with each slide as a page. This is not what we intend if we want to print some handouts. Because each page is a slide, and the background is colourful.

LibreOffice Impress actually has “Print to File” like Firefox or Chromium. However, we cannot see the “Print to File” printer like Firefox or Chromium. To get this, we go to File > Print. There are several tabs. In the Options tab, we can see the option “Print to File”. Check it, now the “OK” button becomes “Print to File…” button. As a result, we can customise our handouts, such as change the handouts to “Black & White”, 6 pages per sheet, and so on. After customising the settings, press the “Print to File…” button, we will produce a PDF file as handouts instead of slides and all the text information preserved.

Update 2015-09-22: This does not work on 5.0.1.