The log file is written to achieve the function under linux and windows

In doing recently command php dos function, in order to facilitate the execution result of the recording, then you need to add a function of generating log. Very simple, work together to learn about it.

windows

In order to meet the log file is generated by date.

Step 1: Set command current time (2016/08/04 Thursday).

Step two: transforming the current time and date into a standard format (2016/08/04).

The third step: / rev - (2016-08-04), why is there the third command, because the date is 2016/08/04 get the windows, so the need to turn about.

Step 4: Date fight on the log file extension .log.

Step five: that is, the contents of the execution is written to the log files in the specified directory, remember the contents of the file's execution to be recorded with echo output, in order to successfully write a log file.

@echo off

set nowDate=%date%

set tmp=%nowDate:~0,-3%

set ymdDate =% tmp: / = -%

set file =% ymdDate% .log

@echo on

D:\wamp\bin\php\php5.4.3\php.exe index.php /Ceshi/server >> D:\wamp\www\logs\rabbitmq\%file%

Note:

Create a directory

md d:\aaa

% Name% is equivalent to a variable

A pointer to the next log file will be written to cover the contents of the log

Two were added in the log file contents on the basis of

@echo off if the command line is written in the .bat file, then there is this line of code, double-click execution, dos not demonstrate these in order, if not, it will show the command to write a .bat.

@echo on allowing the display on the command line.

linux

This is relatively simple, linux command more powerful.

Create a directory by date

mkdir date +%y%m%d

The contents of the log written to the log file, here to write a simple, PHP program but it is still above the use of the same.
echo 'log content' >> date +%y%m%d.log

NOTE: The next date must have a space, or do not recognize, will complain. 这个符号是英文状态下的tab键上面的那个按键~.

Guess you like

Origin blog.51cto.com/14591361/2447058