Cacomania: tag


Unix timestamp conversion with date

Guido Krömer - 1199 days ago - Tags: ,

If you are not smart enough to interpret a Unix timestamp by yourself date can do it for you.

$ date -u -d @1234567890
Fri Feb 13 23:31:30 UTC 2009

The timestamp can be formatted, too.

$ date -u -d @1234567890 +"%Y-%m-%d %T"
2009-02-13 23:31:30

If you need a timestamp, %s lets date print one.

$ date +"%s"


Search all config files for a specific term

Guido Krömer - 1430 days ago - Tags: , ,

A common problem, which of all ini file contains the part loading module XYZ?

The find command below searches all ini files in the /etc folder for the term "mysqli".

$ find /etc -name "*.ini" -printf "echo \"FILE: %f\"\ngrep \"mysqli\" %h/%f\n" | bash


Mono, WebClient and "Invalid certificate received from server."

Guido Krömer - 1568 days ago - Tags: , ,

Playing around with MVC on Mono and the Facebook API Login for Server-side Apps the System.Net.WebClient threw a TslException with the message: "Invalid certificate received from server. Error code: 0xffffffff800b010a". Invalid certificate received from server.

After that, I experimented importing all general certificates using mozroots.

$ mozroots --import --ask-remove

But the error still occurred so that importing the needed certificates directly by defining the URL using the certmgr solved the problem.

$ certmgr -ssl


Some bash special variables you should never forget

Guido Krömer - 1570 days ago - Tags: ,

Since the main topic here in the last time was JavaScript here is a small foray into the world of bash special variables. Although there are a lot more special variables in bash this might be the most common in my opinion.

Getting all params

There are two variables containing all params, the first one is $* which represents all params as single quoted string and $@ where each word is quoted separate. If it's not clear what is going on there, let's have a look at the example below.

echo STAR: ${ALL_ARGS_STAR[0]}
echo STAR: ${ALL_ARGS_STAR[1]}
echo AT: ${ALL_ARGS_AT[0]}
echo AT: ${ALL_ARGS_AT[1]}

Accesing the variables ALL_ARGS_STAR and ALL_ARGS_AT using the array indexer should make the difference of $* and $@ more clear.

[caco@MacBook-Air ~]# ./ Foo Bar 1337
STAR: Foo Bar 1337
AT: Foo
AT: Bar

The other usefull ones

  • $0, which is the first param and holds the called script name including the path.
  • $# represents the number of arguments.
  • $1 .. $n access the param directly.
  • $$ gets the PID of the running script.

If you got confused by $0, $#, $1337 or $$ have a look at the self explaining script below:

SCRIPT_NAME=`basename $0`

echo "Script name: $SCRIPT_NAME"
echo "Number of arguments: $NUM_ARGS"
echo "PID: $PID"
echo "Arg one: $ARG_ONE"
echo "Arg two: $ARG_TWO"

echo -e "Arg:\tVal:"
for ARG in $ALL_ARGS; do
  echo -e "$i\t$ARG"
  i=$(( $i + 1 ))

Here is the generated output:

[caco@MacBook-Air ~]# ./ Foo Bar 123
Script name:
Number of arguments: 3
PID: 25052
Arg one: Foo
Arg two: Bar
Arg:    Val:
1   Foo
2   Bar
3   123


Remove the phassprase from a ssh keyfile

Guido Krömer - 1633 days ago - Tags: ,

Just a command you maybe need sometimes when a shh keyfile with a phassprase becomes annoying. You will still need the actual phassprase(123456 in the example below) to remove it.

# ssh-keygen -p -P 123456 -N "" -f /home/user/.ssh/id_rsa


Merging files together

Guido Krömer - 1661 days ago - Tags: ,

Having a website CSS or JS separated into different files and sorted in sub folders is great for development, but ends up in many requests during live operation. Instead of using a “complex” script which merges those files together this one liner can do the job, too.

# find /path/to/css/* -type f -name *.css | xargs cat > /path/to/css/screen.css

Comment [1]

Auto cleaning up your download folder with find

Guido Krömer - 1681 days ago - Tags: ,

Is your download folder messy, too? Why not let find tidy it up periodically?

# find ~/Downloads/* -ctime +7 -exec rm -rf {} \;

The command above let find search for files and folder which are older than 7 days and deletes them. But be carefully files in a folder will be deleted even if the file age is newer than 7 days if the folder is older than 7 days!

0 * * * * find ~/Downloads/* -ctime +7 -exec rm -rf {} \; > ~/Downloads/deleted.files

Running this as a cronjob will do the work once a hour, or how often you wants.


FTP upload via cURL

Guido Krömer - 1684 days ago - Tags: , , ,

Uploading a file to a ftp server with cURL is really easy:

# curl -u user:pass -T my_file

Or with a little potion of bash for uploading multiple file:

# for file in ./*; do curl -u user:pass -T "$file"; done;


Turn your Linux system into a sandbox with KVM

Guido Krömer - 1687 days ago - Tags: , , , ,

Using a sandbox system is in many cases really handy, but a sandbox that is a snapshot of your "main" system is a little bit more handy. For example, if you want to test how a system update will perform, especially if you are using Arch or Gentoo Linux, on your main system or just for testing new software without messing up or destroying your system.

sandbox running as kvm

This a screenshot of my Thnkpad T61 running Xubuntu 12.04 with a running sandbox vm.

read more TEST


Updating DynDNS via Bash

Guido Krömer - 1693 days ago - Tags: , , ,

Because of my old wireless router was not able to update DynDNS, I spend a lot annoying time configuring the ddclient daemon on my home server. But the stability of this tool was really disappointing, after being blocked two times by dyndns, I decided writing my own script to update DynDNS frequently.

read more TEST

Comment [5]