Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

sshd: 1.2.3.4 : 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: 1.2.3.4 : spawn (echo `date "+\%F \%T` ALLOWED from %a >> /var/log/%d.log)

Could somebody please advise ?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Double the percent sign, and it should work:

sshd: 1.2.3.4 : 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

 
discard

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.