Operating System - HP-UX
1748022 Members
4963 Online
108757 Solutions
New Discussion юеВ

Writing Variables to a File

 
Scott Frye_1
Super Advisor

Writing Variables to a File

First of all I apologize for putting a basic question out here. Due to heay snow, I'm working from home so I don't have documentation to refer to...
I need to write several variables to a file. I'm trying...
echo "$CPU $TTY $PID $USERNAME $PRI $NI $SIZE $RES $STATE $TIME $WCPU $CPU $COMMAND" > /home/sysadmin/topcpu/check_cpu.txt
but it is not working. Can someone tell me what I'm doing wrong?

Thanks to all

Scott
22 REPLIES 22
Ralph Grothe
Honored Contributor

Re: Writing Variables to a File

Does a "set" at the shell display these variables as set?
What kind of content do you get in the file (empty)?
Is this run from a script with a different environment or other variable settings?
Madness, thy name is system administration
Steven E. Protter
Exalted Contributor

Re: Writing Variables to a File

env > /tmp/env.txt

You will see everything you need and then some.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Scott Frye_1
Super Advisor

Re: Writing Variables to a File

Sorry, I wasn't clear. This is for a script I am writing. The variables contain a line from top. I want to write each of these variables to a file. With this command, the file doesn't even get created. Do I have the syntax correct? Do I need to touch the file first?
harry d brown jr
Honored Contributor

Re: Writing Variables to a File

I know this sounds stupid, but does the directory "/home/sysadmin/topcpu" exist??

ls -l /home/sysadmin/topcpu

live free or die
harry d brown jr
Live Free or Die
Georg Tresselt
Honored Contributor

Re: Writing Variables to a File

What exactly goes wrong?
Do you get an error message?
Or what do you find in the file if it is created at all?
http://www.tresselt.eu
Victor BERRIDGE
Honored Contributor

Re: Writing Variables to a File

Hi,
I just tried your echo, and I get the script created (empty line because none of the VARs have values...) so I suspect you have something wrong with the permissions on your directory, has whatever executes the script the write permission to that directory?


All the best
Victor
Ralph Grothe
Honored Contributor

Re: Writing Variables to a File

Has your shell the noclobber option set?

# set -o|grep clobber
noclobber off
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Writing Variables to a File

Bah, forget my silly question,
even if the file should at least be created.
Madness, thy name is system administration
Ralph Grothe
Honored Contributor

Re: Writing Variables to a File

How does your script populate the variables?

I guess you parse the top dump from something similar to

top -d 2 -f /tmp/top.dump
Madness, thy name is system administration