#TIL : Make cron job runs every seconds

Cron is a UNIX service that helps user run command periodically. And crontab is simple tool to setup cron job as user, just type in the command crontab -e then setup your cron schedule.

Btw, sometimes you want to run the cronjob every seconds (5, 10 or 20 seconds), but crontab only support every minute. How to achieve your goal without using another tool ?

I got an idea that we can use the sleep command to make it done. So this is solution.

This below is crontab rule that run command every 10 seconds.

* * * * * [command]
* * * * * sleep 10 && [command]
* * * * * sleep 20 && [command]
* * * * * sleep 30 && [command]
* * * * * sleep 40 && [command]
* * * * * sleep 50 && [command]

It’s simple, right ? ;)

#TIL : Disable IPv6 to stop getting stuck in network

I know IPv6 will be future for networking, but at this moment “It’s suck !” :(

Some service will be failed when trying to connect IPv6 destination :

  • apt package manager
  • smtp
  • curl

So I decided to disable IPv6 on every production server.

1
2
3
4
5
$ echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
$ echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
$ echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
$
$ sudo sysctl -p

I will re-enable it when everything works perfectly !

#TIL : Using watch command to tracking changes in period time

watch to a good command to run a command every N seconds.

And like its name, means you can watch something, its output changes with flag -d

It’s a great tool to help you learn a new language without hitting compile and run everytime you save a file.

1
$ watch -n 1 -d go run learn.go

This command will compile and run learn.go every 1 second

More flags :

  • -t : no title
  • -b : beep on non-zero exit code
  • -e : stop loop on error and exit on a keypress
  • -g : exit on change
  • -c : support colors
  • -h : you know ! ;)

#TIL : Send ENTER key to kernel

When you try to send an Enter keyboard to linux kernel, it looks like nothing happens.

This is because you only send a key press (KEY DOWN) but don’t send an key release (KEY UP) event after that.

#TIL : Remap Capslock to Control key

Edit file /etc/default/keyboard and set

1
XKBOPTIONS="ctrl:nocaps"

Then, logout and log in again to impact