Appending request headers to a request forwarded by mod_rewrite

Set an environment variable using env flag in RewriteRule and use it in RequestHeader append.

  RewriteEngine on
  RewriteRule ^/(.*)$ http://appserver/$1 [P,L,QSA,env=ORG_REMOTE_ADDR:%{REMOTE_ADDR}]
  ProxyPassReverse / http://appserver/
  RequestHeader append X_ORG_REMOTE_ADDR %{ORG_REMOTE_ADDR}e env=ORG_REMOTE_ADDR
  RequestHeader append X-Forwarded-Proto https

mod_rewrite - Apache HTTP Server
たまねぎプログラマハマリ日記:Apache内のCGI環境変数をTomcatに渡す。 - livedoor Blog(ブログ)

Delete or grep the results of find

-exec command {} \;
  • Execute command after find. To pass results of find use {}.
  • You must put a blank before "\;". If a blank is missing, an error occurrs like below.
    $ find . -name *~ -exec rm {}\;
    find: missing argument to `-exec'
    
    $ find . -name *~ -exec rm {}\;
    find: -exec: no terminating ";" or "+"
    
  • To execute more than one command, specify multiple -exec.

Example:

find ~ -name '*bak' -exec rm {} \;
  • In above example, "rm {} \;" following "-exec" is the command to execute. Last ";" denotes the end of the parameters. "\" before ";" is needed to escape "\" so that shell does not evaluate ";".

Example:

Delete all files whose name are *~ (Emacs backup file) in home directory.

$ find ~/ -name "*~" -exec rm {} \;

Delete all .svn directories from working directory tree of Subversion.

find . -name .svn -exec rm -rf {} \;

Grep files in directory tree.
(grep option -H for printing filename headers, -n for printing line number)

find <directory> -type f -exec grep -nH <pattern> {} \;

You can't specify target table 'xxx' for update in FROM clause

On MySQL, you cannot use the same table for both the subquery FROM clause and the update target.

Source: MySQL :: MySQL 5.1 Reference Manual :: 13.2.9.9 Subquery Errors

Example:

mysql> delete from user \
    -> where user.id in \
    -> (select user.id from user \
    -> left join reserve_data on user.id = reserve_data.user_id where reserve_data.id is null);
ERROR 1093 (HY000): You can't specify target table 'user' for update in FROM clause

Workaround

mysql> delete from user \
    -> where user.id in \
    -> (select x.id from \
    -> (select user.id from user left join reserve_data on user.id = reserve_data.user_id where reserve_data.id is null) \
    -> as x \
    -> );
Query OK, 350 rows affected (0.00 sec)

In the above example, the subquery creates an implicit temporary table, so it doesn't count as the same table you're updating.

Source: SQL Delete: can't specify target table for update in FROM clause - Stack Overflow