Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Standard out/Error out

Status
Not open for further replies.

Tim2525

Technical User
Feb 7, 2005
51
0
0
US
Hi All,

My apologies for the VERY simple qs. Want to send echo messages to a log file. Is my code right? Can this be done with printf function? Currently what is happening is the message appears on my screen with the path following it and backup.log file not created.

Message that appears on screen:
Forcing any existing sampleDB applications offline... /db2_backup/backup.log

Code:

logFilePath=/db2_backup/backup.log

echo '\n' "Forcing any existing ${dbName} applications offline... " 2>&1 $logFilePath


TIA,
T
 
First you need to make sure that the directory and the file exist.

logFilePath=/db2_backup
if [ -d ${logFilePath} ]
then
continue
else
mkdir ${logFilePath}

logFile=${logFilePath}/backup.log
export logFile
# Create logfile if it does not exist
if [ -f ${logFile} ]
then
continue
else
touch ${logFile}
fi

echo '\n' "Forcing any existing ${dbName} applications offline... " >> ${logFilePath}


Look into other options like "tee" .
 
Thanks much rbod for the information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top