LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 06: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, 08:29 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
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, 09: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, 09: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, 09:55 AM   #5
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
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, 10: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, 10: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, 10:21 AM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
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, 10: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:58 PM
Date issue with httpd log sopiaz57 Linux - Software 2 12-19-2003 09:27 AM
How to control log file size in /var/log? yan Linux - General 2 10-13-2003 06:00 PM
what log file generator that support squid log? heero82 Linux - Software 2 07-11-2003 09:52 PM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 09:38 PM


All times are GMT -5. The time now is 07:35 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration