Aug 25: Strace with multiple processes
strace -f -p $(ps -ea f| grep httpsd | cut -f 1 -d " " | xargs | sed -e 's/ / -p /g') 1>/tmp/strace.log 2>&1
Jun 17: Dumping json-data in shell
When using web services, its sometimes hard to read the serialized json data. I wrote a small helper script to dump the contents
File: /usr/local/bin/json_decode
#!/usr/bin/php
<?php
error_reporting(E_ALL);
ini_set('display_errors',true);
if(!empty($argv[1])) {
$json = file_get_contents($argv[1]);
}
else {
$json = '';
while(!feof(STDIN)) {
$json .= fgets(STDIN, 1024);
}
}
$data = json_decode($json);
if($data === null) {
fwrite(STDERR, "Invalid json data\n");
exit(1);
}
print_r($data);
Usage:
wget --quiet -O - "http://domain.tld/file.json" | json_decode
Nov 12: Find symbolic links
Jul 16: Flushing swap space
From time to time machines use some swap space due to heavy load. But Linux doesn't free the swap space itself if enough memory is available.
An easy method to flush all disk swap to memory is to disable and re-enable the swap. Eg:
# free -tm
total used free shared buffers cached
Mem: 4096 3269 826 0 31 76
-/+ buffers/cache: 3161 934
Swap: 509 114 395
Total: 4605 3384 1221
# swapoff /dev/xvdb1
# swapon /dev/xvdb1
# free -tm
total used free shared buffers cached
Mem: 4096 3375 720 0 31 78
-/+ buffers/cache: 3265 830
Swap: 509 0 509
Total: 4605 3375 1230
Jun 17: Uptime-Devil
Aug 6: for-loop in bash
If you want to update several hosts at once you can use a for-loop in a shell to execute a command on serveral hosts
for i in 1 3 `seq 4 7` 9; do HOST="1.2.3.$i"; ssh root@$HOST; done;
As you can see it is very easy to create a custom set of items to loop through. On the one hand you can use any value seperated by a space or you can create a sequence of numbers with the seq-command.
Nov 23: Locales support
I tried setting up a new blog that should display german date format, but none of the (usually valid) locales worked. The php function setlocale() always returned false. So I searched and found a debian package that fixed my problem, by installing all locales:
apt-get install locales-all
Sep 8: Setting up a MoinMoinWiki
Sep 7: Removing files and free disk space
# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 45G 41G 4.4G 91% / # cd /var/log/mysql # ls -al total 27062512 drwxr-x--- 2 mysql mysql 82 Jul 17 00:05 . drwxr-xr-x 9 root root 4096 Aug 29 19:32 .. -rw-r--r-- 1 mysql mysql 0 Jul 17 00:05 .keep_dev-db_mysql-0 -rw-rw---- 1 mysql mysql 0 Jul 17 00:06 mysql.err -rw-rw---- 1 mysql mysql 0 Jul 17 00:06 mysql.log -rw-rw---- 1 mysql mysql 27712011858 Sep 7 15:32 mysqld.errSo after resolving the spamming issue I removed the error logfile.
# rm mysqld.err # /etc/init.d/syslog-ng restart \* Stopping syslog-ng ... [ ok ] \* Starting syslog-ng ... [ ok ] # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 45G 41G 4.4G 91% / udev 512M 24K 512M 1% /devHuh? No effect on the free disk space? The problem is, that mysqld had still an open filehandle on the error logfile. So the filesystem didn't free the disk space. Restarting mysqld resolved this issue.
# /etc/init.d/mysql restart \* Stopping mysql ... [ ok ] \* Stopping mysqld (0) [ ok ] \* Starting mysql ... \* Starting mysql (/etc/mysql/my.cnf) [ ok ] # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 45G 15G 31G 33% / udev 512M 24K 512M 1% /dev
Jul 25: Bash: Arithmetic operations using bash
i=10 echo $[$i/5]; 2Better use-case: do 10 times the same command
host ~ # i=0; while [ $i -lt 10 ]; do echo $i; i=$[$i+1]; done 0 1 2 3 4 5 6 7 8 9






PHP/MySQL



