How to change the date automatically on script?


 
Thread Tools Search this Thread
Operating Systems Solaris How to change the date automatically on script?
# 1  
Old 09-05-2014
Oracle 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.
Code:
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


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks
# 2  
Old 09-05-2014
Hi,

Check out
Code:
man touch

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

Regards

Dave
# 3  
Old 09-05-2014
Can you explain what you tried to do?
And what was the output so we can help you
# 4  
Old 09-05-2014
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
# 5  
Old 09-05-2014
You are doing it right
Try the below if this works
Code:
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
# 6  
Old 09-05-2014
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
Code:
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
Code:
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

Is it right, will it work !!!


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-05-2014 at 10:41 AM.. Reason: code tags please!!!
# 7  
Old 09-05-2014
Why | tee ?
I doubt cron finds that to its taste...

Quote:
Is it right, will it work !!!
You are the one that should answer and tell us what is happening...
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Script to change date/time

Hi everybody! I need to perform a task with a script but I have no idea how to do it, I hope someone could help me: - on my linux pc I have many folders with movies, tv shows, toons, ecc. They are shared by a dlna server to my panasonic tv where I can browse and see them. The problem is that... (6 Replies)
Discussion started by: Torquemada
6 Replies

3. Shell Programming and Scripting

Script to change name of a file with date

I have a file that contains todays date(for ex- test_08/30/2013) Now I want a script which will run and change the name of the file and put yesterday's date (for ex- test_08/29/2013) Please help. ---------- Post updated at 04:40 AM ---------- Previous update was at 04:31 AM ---------- I... (2 Replies)
Discussion started by: sv0081493
2 Replies

4. Shell Programming and Scripting

Change date format in shell script

Plz help me To display date in the mm/dd/yyyy. Eg. if date is 28-09-2012 the output of the shell script should be date 09/28/2012. (1 Reply)
Discussion started by: shivasaini
1 Replies

5. Shell Programming and Scripting

Perl script to change the date in some scenario

Hi , I have file FSN.log which contains number 100. i have other Perl script when i run it , it ll increment this FSN.log value. now my requirement is when the count in FSN.log becomes 999, it should make the value to 100 again and Perl script to change the date or it should make the date... (2 Replies)
Discussion started by: santhoshks
2 Replies

6. Programming

date change shell script in java code

hi, I have a code to connect to a remote Linux server through windows using SSH, with host-name, username and password built in the code. I want to add a shell script in the code which should execute automatically without any user intervention. (as u know that date change requires you/us to be... (0 Replies)
Discussion started by: tarkan
0 Replies

7. Shell Programming and Scripting

help for change date format script

Someone can help me write a script for change date fromat from "Feb 4 18:44:03 2009" to 2009020418 ? from "Mar 17 16:44:03 2009" to 2009031716 ? (4 Replies)
Discussion started by: pccwtest
4 Replies

8. Shell Programming and Scripting

script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09 Thanks (15 Replies)
Discussion started by: shehzad_m
15 Replies

9. Shell Programming and Scripting

Script to automatically change password.

I want to write a script which will automatically take password sequentially from a file after every 10 days. i.e the passwd command should be executed automatically every 10 days and it should take the input from the password file sequentially. Has any1 got a solution?????????????? (1 Reply)
Discussion started by: rahulrathod
1 Replies

10. UNIX for Dummies Questions & Answers

How would I telnet & change user password automatically in a script

I would like to create a script that logs into a list of several servers 50+ and changes my password all at once. Every 60 days we are required to login to each system and change our passwords or else they expire and our login account is deleted. I have an idea on how I could do this but... (4 Replies)
Discussion started by: darthur
4 Replies
Login or Register to Ask a Question

Featured Tech Videos