LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-01-2006, 05:44 AM   #1
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Rep: Reputation: 15
Date in Log file name


Hi,

Does anyone know how to get the date automatically placed in the name of a log file? I have log file generated daily and I want to be able to differentiate and archive easily.

Thanks for you help.
 
Old 06-01-2006, 07:29 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
there are plenty of ways to insert a date:

date=$(date +%d%m%y)

and then use as you see fit... you need to give mroe info about how these files are created if this isn't what you're after.
 
Old 06-01-2006, 08:11 AM   #3
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Original Poster
Rep: Reputation: 15
thanks,

that's a good starting point.
 
Old 06-02-2006, 08:49 AM   #4
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Original Poster
Rep: Reputation: 15
There must be something else required as it is not working. Here is the script I am running

#!/bin/sh
#
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
echo "Starting rman for ORACLE_SID: $ORACLE_SID" >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
date >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
#
rman <<EOF
connect target backup_admin2/backup2pa;
spool log to $HOME/rman_scripts/backup_logs_$ORACLE_SID_%Y-%m-%d.log append;
backup database plus archivelog;
delete noprompt obsolete;
quit;
EOF
#
echo "End of rman for $ORACLE_SID" >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
date >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_%Y-%m-%d.log
exit

I'm trying to get a file name that would look like this:

backup_logs_GEN_06-06-02.log

but what I get is

backup_logs_%Y-%m-%d.log

any ideas?
 
Old 06-02-2006, 08:55 AM   #5
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
It's better to put the date-part into a variable beforehand.
So:
Code:
my_date=$(date +%d%m%y)
echo ${my_date}
 
Old 06-02-2006, 09:14 AM   #6
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Original Poster
Rep: Reputation: 15
OK I have adjusted the script as such:-


#!/bin/sh
#
log_date=$(date +%Y%m%d)
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_{log_date}.log
echo "Starting rman for ORACLE_SID: $ORACLE_SID" >> ./backup_logs_$ORACLE_SID_{log_date}.log
date >> ./backup_logs_$ORACLE_SID_{log_date}.log
#
#rman <<EOF
#connect target backup_admin2/backup2pa;
#spool log to $HOME/rman_scripts/backup_logs_$ORACLE_SID_{log_date}.log append;
#backup database plus archivelog;
#delete noprompt obsolete;
#quit;
#EOF
#
echo "End of rman for $ORACLE_SID" >> ./backup_logs_$ORACLE_SID_{log_date}.log
date >> ./backup_logs_$ORACLE_SID_{log_date}.log
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_{log_date}.log
exit

now I get a file called

backup_logs_{log_date}.log

notice how it also misses the $ORACLE_SID variable, why is that? it even misses the second _.
 
Old 06-02-2006, 09:20 AM   #7
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Original Poster
Rep: Reputation: 15
my mistake, I missed the $.

Thanks
 
Old 06-02-2006, 09:21 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_{log_date}.log
should be
echo "---------------------------------------" >> ./backup_logs_$ORACLE_SID_${log_date}.log

As always, take babysteps in the beginning so start by echoing the intended output of the variables:
echo "backup_logs_$ORACLE_SID_${log_date}.log"

Now you can see that maybe the ORACLE_SID variable is not set at all.
I don't know ORACLE_SID, the way you're using it suggests it should be set in your environment ...

I'm not sure but if the file does not exist beforehand it might be better to create it first by using:
Code:
touch ./backup_logs_$ORACLE_SID_${log_date}.log
 
Old 06-02-2006, 09:45 AM   #9
Runningonair
Member
 
Registered: Apr 2004
Location: London, UK
Distribution: suse 8 and 9
Posts: 30

Original Poster
Rep: Reputation: 15
Thanks,

$ORACLE_SID is an environment variable set in another script. I have found that by using curly brackets, as with the date variable, it now works fine.

i.e.

${ORACLE_SID}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
get date (file) os2 Programming 1 03-07-2005 11:58 AM
Date issue with httpd log sopiaz57 Linux - Software 2 12-19-2003 08:27 AM
How to control log file size in /var/log? yan Linux - General 2 10-13-2003 05:00 PM
what log file generator that support squid log? heero82 Linux - Software 2 07-11-2003 08:52 PM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration