Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Solved: ksh and writing to log files

Reply  
Thread Tools
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
02-Jun-2005, 06:53 PM #1
Solved: ksh and writing to log files
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's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
02-Jun-2005, 07:16 PM #2
echo $date $who $var $var2 >> logfile

should work
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
02-Jun-2005, 07:26 PM #3
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's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
02-Jun-2005, 11:45 PM #4
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's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
03-Jun-2005, 01:32 PM #5
Codejockey thank you you help has been invaluable. I really appreciate your help. Let me go check it out.
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
03-Jun-2005, 01:38 PM #6
OK first one failed saying DATE and WHO were not found. Second method worked perfectly. THANKS!!!!!!!!!!!!!!!!!
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
03-Jun-2005, 11:54 PM #7
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.
__________________
The slowest component still sits at the keyboard.
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
05-Jun-2005, 09:32 PM #8
Quote:
Originally Posted by surfnschultz
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.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:46 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.