Sponsored Content
Full Discussion: Read the latest file
Top Forums UNIX for Dummies Questions & Answers Read the latest file Post 302165920 by HPAVC on Saturday 9th of February 2008 11:12:26 PM
Old 02-10-2008
Quote:
Originally Posted by wereyou
Thanks, HPAVC

This is what I have. Your command works but I just want to read the Lates/current file so I put *0209_TWSMERGE.log which works but I will probably have to change it again tomorrow?
I might be way to sleepy to understand the problem, i assume you have a directory full of log files and every so often a new one is made.

"ls -ctr PATTERN" should list the contents

-t sort by modification time
-r reverse order while sorting
-c just one column

so if the files where

mon.txt
thu.txt
tues.txt
wed.txt

ls -ctr *.txt would list them

mon.txt
tues.txt
wed.txt
thu.txt

the tail -1 just lists the last file (the newly modifed one)

so "cat `ls -ctr *.txt | tail -1`" gives cat the newest modified file.

if the issue is that you want some sexy 'look busy' dedicated window that always has the tail -f LATESTFILE going. yeah some sort of loop would be needed or a sexy tail. I dont know the tail command you have but ...

#
# this will try and get a PID from something and when that PID dies it will
# 'untail', then re-tail
#
while true; do
PID=`cat /var/run/TWSMERGINGTHING.pid`
tail --pid=$PID --follow `ls -ctr *_TWSMERGE.log | tail -1`
sleep 5
done

#
# this will keep tailing until the file goes sour (100 attempts looking
# at it with the no changes) and then it will get a new one
#
while true; do
tail --max-unchanged-stats=100 --follow `ls -ctr *_TWSMERGE.log | tail -1`
sleep 5
done

if you have a 'runfor' like command then obviously you could do that for "runfor 3600 tail ..." and it would run it for an hour and then retail every hour.

now for sleep
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Getting latest file from ftp

Hi, i have multile JAMA01.DAT.* files in my ftp. how can i get the latest file in from the ftp by executing the script :rolleyes:? Regards, Arun S (3 Replies)
Discussion started by: arunavlp
3 Replies

2. Shell Programming and Scripting

How do I get the name of latest file?

1) How do I get the name of latest file in a variable? 2) Is it safe to delete all files from a dir I am doing cd $dir_name if return_code > 0 rm * fi what are other alternates to delete all files from a dir in a shell script? :) (5 Replies)
Discussion started by: Hangman2
5 Replies

3. Shell Programming and Scripting

how to get the latest file

I am trying to scp the latest file which ends with "_abc.log". Can some help me figure out how can do that? (3 Replies)
Discussion started by: shehzad_m
3 Replies

4. Shell Programming and Scripting

get latest file

i have the following in my directory x: 3 files with the word "LIST" inside the files 2 files without the word "LIST" 1 folder (sudirectory) i want to get the filename of the latest file (timestamp) with the word "LIST". by the way the script and the list of files are in seperate... (4 Replies)
Discussion started by: inquirer
4 Replies

5. Shell Programming and Scripting

To get the latest file

Hi Experts Team, I wish to store the latest file name of partcular pattern in the remote server in a variable. i tried this LATEST_FILE=`ssh ${USER_ID}@${REMOTE_HOSTNAME} 'ls -t ${SOURCE_DIRECTORY}/${SOURCE_FILEPATTERN}'` but its nt working..pls guide me.. Regards, Kanda (2 Replies)
Discussion started by: spkandy
2 Replies

6. AIX

How to read the latest file name in adirectory.

Hello all, In a shell script, I need to get the name of the latest file which was created in a directory. i.e. I have the following directory. /tmp/public/logs/ In this directory, I want to get the latest file that was created. Can you give me a hint as how can I get the latest file,... (2 Replies)
Discussion started by: haroon_a
2 Replies

7. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

8. Shell Programming and Scripting

Read latest file name with a date and time and then download from FTP

Hi All, Please help. I have requirement to read the file / folder based on the latest date and download the file and folder. There will be files and folders in the location like 20140630-144422 20140630-144422.csv 20140707-182653 20140707-182653.csv 20140710-183153... (7 Replies)
Discussion started by: Praveen Pandit
7 Replies

9. Shell Programming and Scripting

Picking the latest file based on a timestamp for a Dynamic file name

Hi , I did the initial search but could not find what I was expecting for. 15606Always_9999999997_20160418.xml 15606Always_9999999998_20160418.xml 15606Always_9999999999_20160418.xml 9819Always_99999999900_20160418.xml 9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Discussion started by: chillblue
4 Replies

10. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies
UBUNTU-DISTRO-INFO(1)					      General Commands Manual					     UBUNTU-DISTRO-INFO(1)

NAME
ubuntu-distro-info - provides information about Ubuntu's distributions SYNOPSIS
ubuntu-distro-info [OPTIONS] OPTIONS
--date=DATE date for calculating the version (default: today) -h, --help display help message and exit -a, --all list all known versions -d, --devel latest development version --lts latest long term support (LTS) version -s, --stable latest stable version --supported list of all supported stable versions --unsupported list of all unsupported stable versions -c, --codename print the codename (default) -r, --release print the release version -f, --fullname print the full name SEE ALSO
debian-distro-info(1), distro-info(1) AUTHOR
The script and this manual page was written by Benjamin Drung <bdrung@debian.org>. distro-info January 2011 UBUNTU-DISTRO-INFO(1)
All times are GMT -4. The time now is 05:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy