Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have following line in my /etc/hosts.allow

sshd: : spawn (echo `date` ALLOWED from %a >> /var/log/%d.log) &

The problem is, the date command prints time in the standard format, such as

Thu May 16 15:54:55 CEST 2013

which is complicated to process with my script. I would like to have date to specify my own format, such as date "+%F %T", to get following format:

2013-05-16 16:01:07

even if I escape the special characters (%), the following does not work:

sshd: : spawn (echo `date "+\%F \%T` ALLOWED from %a >> /var/log/%d.log)

Could somebody please advise ?

share|improve this question
up vote 4 down vote accepted

Double the percent sign, and it should work:

sshd: : spawn (echo `date "+%%F %%T"` ALLOWED from %a >> /var/log/%d.log) &

For more information, see the "% Expansion" section of the corresponding man page (hosts_access(5)).

share|improve this answer
that's great. Thanks a lot – user1968963 May 16 '13 at 17:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.