linux - Take latest Log File & store in a variable -
I am looking for a solution for the latest log file (for example abc-20141028-005356.log) Which was revised. I can do this with the command "ls -1t | head-1", which gives the solution, but there are other files which are also modified in the logs folder. I tried to do with a head -2, which Gives 2 files; Then unloaded the file ... Say "LS-1T | Head-2 | GRP ABC-"
The real problem occurs when we have the same file name with the latest file; New time & amp; Date How do I store the latest logfile in a variable that has the same duplicate file name & amp; Pursuit with date & amp; time.
path = '$ 1 CD; LS-1T | Head -1` Hanged = $ 1 $ Pat
$ 1 = / opt / server1 / log /
Please advise on the same
I 'may not be able to redeem a unique file based on time stamp for an example, for example abc-20141028-005356.log has been modified & amp; The next file is abc-20141028-005358.log, which is only a time difference. But the complete file name remains the same.
A solution is needed where I can specify the latest file modified in a variable, despite the file name & amp; Timestamp (revised latest)
I have a total of some files 0 -RRR-R1 root route 0 4 Nov 11:14 ABC-20141028-005348. log -rade- R-R1 root route 0 4 Nov 11:14 ABC-20141028-005358. log -R-R-R1 root route 0 4 Nov 11:19 ABC-20141029-005358. log -Rad -R - R - 1 root root 0 November 11:19 ABC-20141029-005360. log This is the latest file I received if I [Root @ ABCD RKP] #LS-1T | Top-1ABC-20141029-005360.log can be mentioned above only when there are files starting with ABCD-*** Now I have the following files: -RR-R1 root root 0 4 Nov 11:14 ABC-20141028-005348. log -R-R-R1 root route 0 4 Nov 11:14 ABC-201541028-005358 .log -R-R-R1 root route 0 4 Nov 11:19 ABC-20141029-005358. log -R-R-R1 root route 0 4 Nov 11:19 ABC-201441029-005360.log -R -R-R1 root route 0 4 Nov 11:21 EFG-20141028-005348. log -R-R-R1 root route 0 4 Nov 11:21 EFG-201441028-005358.log -R-R -1 root route 0 4 Nov 11:21 EFG-20141029-005358.log When I order the above [Route @ ABCD RKP] #LS-1T | Head-1 EFG-20141029-005358.log I want only those files that are modified on the last modfied time at ABC-XXXXX.XXXX. Sorry for making me so confused. Please tell me if you need more then the solution can be simpler, but how can I not do it? !!!!
Thank you for working ....
Thank you ... This is done by running the above mentioned script in my script, I get this error line 30: [:: Integer Expectation of the expression
The script is down for whatever part I am missing.
if [-e $ POSFile]; Then read # previous position previous condition = `cat $ POSFile` file file =" stat -c% s $ LOGFILE` "if [" $ lastPosition "-gt" $ fileLength "]; Then # log file last position = 0; Fi difference = 'XPR $ file length - $ last position' #POS file new place here Enter the file $ fileLength & gt; $ POSFile
Get the latest file starting with abc - $ 1
:
ls -t "$ 1" / abc- * | Head-n1
If a file does not match this method, then you get a no such file or directory
error in that case $ Check the value of 1
some useful commands:
$ 1 ls "$ 1" ls "$ 1" / abc- *
echo The script script snippet should be in your post:
LOGFILE = $ (ls -t "$ 1" / abc- * | head-n1)
I have also found that you can not end this well to do pat =
in the shell
For the second part of your question:
Line 30: [:: Expecting an integer expression
It comes from this line:
if ["$ lastPosition" - Gt "$ fileLength"]; Then both sides of
-gt
must be an integer to work on. For example:
echo lastPosition = $ lastPosition echo fileLength = $ fileLength if ["$ lastPosition" - if those variables are actually numeric, then some echo to check it < / Code> Add line. Gt "$ fileLength"]; Again
In addition, it would be better to rewrite all your `...`
with $ (...)
.
Comments
Post a Comment