Category Archives: Linux

Wondering why messages are deleted from your trash after a week?

I had a special script that removes e-mail from Trash after 90 days. But one day I was looking for a message older than 7 days and realized that older messages are no longer in trash!

I checked Roundcube settings, but it does not have such option. There is only an option to delete all messages from after logout.

Auto expunge can be configured in dovecot, but there was not such configuration:

doveconf | grep expunge

People on the internet were pointing to mail clients like Thunderbird. After some more digging I found out the iPhone by default has such setting! OMG!!!

You need to go to your mail account advanced settings on your iPhone.

Lock Screen and Hibernate in Ubuntu 22.04

In Ubuntu you can hibernate your PC by using the following command:

sudo systemctl hibernate

The problem is it does not automatically lock the screen. To lock the screen use:

xdg-screensaver lock

Now we can combine it together:

xdg-screensaver lock && systemctl hibernate

Note that you will need to enable your user to execute systemctl hibernate without sudo. You can do it by editing /etc/sudoers. Just add:

your-username ALL= NOPASSWD: /usr/bin/systemctl hibernate

OpenOffice service init.d script for CentOS

This script will start soffice headless listening on port 8100. You can use it eg. with JODConverter.

#!/bin/bash
# openoffice.org headless server script
#
# chkconfig: 2345 80 30
# description: headless openoffice server script
# processname: openoffice
#
OOo_HOME=/usr/bin
SOFFICE_PATH=$OOo_HOME/soffice
PIDFILE=/var/run/openoffice-server.pid

set -e

case "$1" in
start)
if [ -f $PIDFILE ]; then
echo "OpenOffice headless server has already started."
sleep 5
exit
fi
echo "Starting OpenOffice headless server"
$SOFFICE_PATH -nologo -nodefault -norestore -nocrashreport -nolockcheck -headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp" & > /dev/null 2>&1
touch $PIDFILE
;;
stop)
if [ -f $PIDFILE ]; then
echo "Stopping OpenOffice headless server."
killall -9 soffice && killall -9 soffice.bin
rm -f $PIDFILE
exit
fi
echo "Openoffice headless server is not running."
exit
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0

How to rescue damaged harddisk

For the past three days I was trying to rescue a damaged disk of my colleague. I already knew about a great disk cloning tool called ddrescue in Linux. So this was the first step I did. After 20 hours of work the clone has been created, but with some errors during read. I was hoping that I will be able to boot from it after I put it back to the PC, but in this case there was some problem with the partition table, so Windows has not been even be able to recognize it as NTFS, even though Linux did!
I didn’t want to reinstall the system after so much hours spend on this, so I was looking for some other tools which could help me save the disk. There was a lot of suggestions on using some paid software, but I don’t have good experience with them.
Finally I found another great open source software called TestDisk. It is a command line tool, but I don’t care much if it helps 🙂 Using this software I was able to recreate the partition table, after it found the lost NTFS partition and as soon as I restarted PC, Windows finally fixed the NTFS using chkdsk.

Running wuala in background with no gui

I have finally found a solution for my problem described in older post. Today I have found out that you can run Wuala without GUI. To do this you have to call wuala with the following parameter.

wuala -nogui

But only this is not enough. You have to also login to your account, because Wuala won’t auto login in this case. I have created a bash script which runs Wuala and as soon as it is initialized it logs you in.

#!/bin/sh

# Run Wuala with no GUI
wuala -nogui &

# Give Wuala some time to initialize
sleep 30

# Login
wuala login USERNAME PASSWORD

Change USERNAME and PASSWORD with your credentials and save this piece of code to /usr/bin/start-wuala.sh. Make it executable by calling sudo a+x /usr/bin/start-wuala.sh. After that you can put it to Startup Applications. But before you do that, you should setup your synchronization, because when Wuala starts in background you are not able to start another instance. To shutdown existing instance go to terminal and execute wuala shutdown.
You can also check status of the background process on the following address: http://127.0.0.1:33333/.

Running UltraVNC repeater under Linux server

I am playing with remote support tools. There are a lot of good payed tools like TeamViewer, GoToMeeting and others but they are expensive. I found that UltraVNC has some tools like Single Click which can make it easy to provide remote support to your customers. Finally I ended by ChunkVNC which is basically UltraVNC but looking much more better.
There is a lot of tutorials on the Internet but they describe direct connection support. Which means at least one of the PC’s has to be accessible from the outside world. But I wanted to setup some server which I would connect to instead of connecting directly to customer’s PC. This server is called Repeater. UltraVNC has a repeater targeting Windows platform. But I have a Linux server and I wanted it to be running there. Fortunately a Linux port of the UltraVNC Repeater is also available. I have created a mirror of the latest version in case the original page won’t work.
The installation itself is not a big problem even though you have to compile the sources.

  1. Connect to the server using SSH
  2. Go to temp: cd /tmp/
  3. Download the sources: wget http://downloads.stefko.cz/uvncrepeater.tar.gz
  4. Extract them: tar zxvf  uvncrepeater.tar.gz
  5. Go to the sources directory: cd uvncrepeater/
  6. Compile the sources: make
  7. Copy repeater to sbin: cp repeater /usr/sbin/repeater
  8. Run it: /usr/sbin/repeater

If you want to make it running as a service you can use the following piece of code:

#! /bin/sh
# vnc: start/stop/restart the VNC repeater server
# chkconfig: 3 20 80
# description: VNC repeater server

vnc_start() {
if [ ! -f /etc/uvncrepeater.ini ]; then
echo "File /etc/uvncrepeater.ini does not exist. Aborting."
exit
fi
/usr/sbin/repeater 2>>/var/log/vnc.log &
pgrep repeater >/var/run/vnc.pid
}

vnc_stop() {
killall repeater
rm /var/run/vnc.pid
}

vnc_restart() {
if [ -r /var/run/vnc.pid ]; then
kill `cat /var/run/vnc.pid`
else
echo "Killing repeater in the absence of /var/run/vnc.pid"
killall repeater
fi
sleep 1
vnc_start
}

case "$1" in
'start')
vnc_start
;;
'stop')
vnc_stop
;;
'restart')
vnc_restart
;;
*)
echo "usage $0 start|stop|restart"
esac

Take the code and save it into /etc/init.d/vnc file on the server. Then run the following commands to install it as a service:

  1. chmod +x /etc/init.d/vnc
  2. chkconfig –add vnc
  3. chkconfig –level 3 vnc on

Connection problem when stunnel is run on boot time in Ubuntu

If you are using stunnel in client mode you may experience connection problems when connecting to your stunnel services.
To avoid these problems make the following changes in your stunnel.conf file:

  1. Comment out the following line: chroot = /var/lib/stunnel4/
  2. Update pid file location with this: pid = /var/lib/stunnel4/stunnel4.pid
  3. Add delay = yes into the service configuration

In this case DNS lookup will be done when the service is needed for the first time.