Forum Moderators: bakedjake

Message Too Old, No Replies

CAT Command

I WANT DATE & TIME IN "CAT" COMMAND OUTPUT

         

hayat7373

5:28 pm on Jun 22, 2006 (gmt 0)



Hi everybody,
sometime I receive check.txt file with 1 line containing 10 digits. I use
cat check.txt >> /usr/bin/allchecks.txt
I want date & time in output file whenever I execute cat.
I will be greatfull if anybody help me.

schmiddy

8:40 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



hayat,

There are several ways you could go about doing that. I'm assuming you're using a cron job -- a line in your crontab specifying a regular interval to perform the command "cat check.txt >> /usr/bin/allchecks.txt ".

The simplest way would be to change that line so that it executes both the cat command and the 'date' command, which should output the date and time. You could change the line to "cat check.txt >> /usr/bin/allchecks.txt ; date >> /usr/bin/allchecks.txt"

Note that the semicolon tells the shell executing the command to execute two commands, one after the other. So 'date' will run just after 'cat' finishes.

Another way you could do it would be to create a simple bash script (or perl script, or whatever) that would execute 'cat' and 'date' for you, and run the bash script from the cron job.

One last note -- the directory "/usr/bin/" is intended for general programs, not for logfiles. It might be more "proper" to output the logfile somewhere else, maybe your home directory.