# Solved: ksh and writing to log files



## surfnschultz

I am trying to create a log file of activity when a tool is used.

I want to put date, whoami, answer1 and dec (answer1 and dec are varibles in the script date is the date command and whoami is unix whoami)

I can make this happen easily with

#!/bin/ksh
date >> logfile
whoami >> logfile

It works well and the now the big question.

How do I get it to write all the info on a single line? I got it workling but each entry to the logfile is on it's own line.


----------



## tsunam

echo $date $who $var $var2 >> logfile

should work


----------



## surfnschultz

Didn't work, I got a blank line in the output log file
Tried on command line echo $date blank line returned....

Anymore suggestions? This is on AIX, and in the korn shell

Thanks.


----------



## codejockey

You can combine all of the output on the same line in several ways; here are two:

(1) use back-ticks to execute a command and assign the output to a variable. Example:



Code:


DATE=`date`
WHO=`whoami`
echo on $DATE I am $WHO >> logfile

(2) use back-tics without assigning the output to a variable. Example:



Code:


echo on `date` I am `whoami` >> logfile

Hope this helps.


----------



## surfnschultz

Codejockey thank you you help has been invaluable. I really appreciate your help. Let me go check it out.


----------



## surfnschultz

OK first one failed saying DATE and WHO were not found. Second method worked perfectly. THANKS!!!!!!!!!!!!!!!!!


----------



## codejockey

Glad to hear things are working for you. You're more than welcome for any help I provided. I don't know why the first script wouldn't have worked; your error message almost makes it sound like you didn't use the '$' in the echo command (e.g., DATE instead of $DATE), but that's just a guess. Both scripts work fine on my system -- but all's well that ends well.


----------



## Squashman

surfnschultz said:


> OK first one failed saying DATE and WHO were not found. Second method worked perfectly. THANKS!!!!!!!!!!!!!!!!!


The first one should work for you as well. I use KSH on my FreeShell account and it works just fine. I don't think it would be an issue with running it on AIX. My Shell account is NetBSD with KSH.


----------

