How to change the date automatically on script?

Hello Experts,

There is a log file which has date stamp, I just wanted to change the date automatically on daily basis when it runs.

Tried the below, but no luck.

grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.`date +\%Y\%m\%d` | tee error_bv03.doc

I would highly appreciate if i get a solution here.

Regards,
Sri

Hi,

Check out

man touch

This will show you how to change the date stamp of a file.

Regards

Dave

Can you explain what you tried to do?
And what was the output so we can help you

Hi Sri,

Could you please let us know the input and expected output. Also kindly use the code tags for same while posting the same.

Thanks,
R. Singh

You are doing it right
Try the below if this works

grep -i error "/var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.$(date +%Y%m%d)" | tee error_bv03.doc

If this doesn't work, tell us the error you get

Hi Ravinder,

I have created a simple script for find the error message from logs and added it on cron job file to get it by mail every 4hrs once.

That log file has time stamp, daily we will new logs. Now i am daily altering the date manually, so i need some assistance to fix it to change dates automatically.

This is the exact script

grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.20140905 | tee error_bv03.doc 

I changed it as [/code]
grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.`date +\%Y\%m\%d` | tee error_bv03.doc
[/code]
Is it right, will it work !!!

---------- Post updated at 07:37 AM ---------- Previous update was at 07:35 AM ----------

Hi,

I have created a simple script for find the error message from logs and added it on cron job file to get it by mail every 4hrs once.

That log file has time stamp, daily we will new logs. Now i am daily altering the date manually, so i need some assistance to fix it to change dates automatically.

This is the exact script

grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.20140905 | tee error_bv03.doc 

I changed it as

grep -i error /var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.`date +\%Y\%m\%d` | tee error_bv03.doc

Is it right, will it work !!!

Why | tee ?
I doubt cron finds that to its taste...

You are the one that should answer and tell us what is happening...

1 Like

That's not an issue, or we can use > also.

I need only the log file date should get update automatically without any manual interruption.

/var/bv1to1_var/logs/bv03.bectondickinson.com/bvlog.out.20140905

We agree you want to use the current date in your command line, not changing the actual file name in order to use grep...

What is your OS and what shell are you using?
cron by default uses bourne shell...

Thanks for the confirmation.
It will work, tee wont affect the cron, its working for last few days and receiving attached file by mail regularly.
For this date issue, i can answer tomorrow only, i need to check the log mail to confirm the date update.

Thanks vbe...

---------- Post updated at 08:36 AM ---------- Previous update was at 08:34 AM ----------

$uname -a
SunOS 5.10 Generic_141414-09 sun4u sparc SUNW,Sun-Fire-V245
$echo $SHELL
/bin/bash

Thanks guys,

My issue is solved now.

Regards,
Sri