12-22-2004 02:29 AM
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
12-22-2004 02:38 AM
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?
12-22-2004 02:40 AM
You will see everything you need and then some.
Owner of ISN Corporation
12-22-2004 02:44 AM
12-22-2004 02:55 AM
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
12-22-2004 03:00 AM
I guess you parse the top dump from something similar to
top -d 2 -f /tmp/top.dump
12-22-2004 03:56 AM
In your script you read in a command into the variable COMM.
However you use the variable COMMAND rather than COMM in several places, including an IF statement. Fix that and you might see a bit of progress.
12-22-2004 04:13 AM
Stupid question, but have you tried to run your script with the shell's poor man's debugger "sh -x"?
12-22-2004 06:01 AM
Yes /home/sysadmin/topcpu exists
Permissions are set as root, running script as root.
Changed COMMAND to COMM, still doesn't create files.
And yes, some of my if statements do evalutate to true.
Seems like this should be so easy, I don't know why I can't get these files to create. I'm sure I've missed something.
12-22-2004 06:06 AM
echo "$var1 $var2" > /newfile.txt
My problem was my last if statement wasn't evaluating the correct variable. Oversight on my part.
12-22-2004 06:06 AM
# sh -x scriptname
Or just put
at the top of the script, execute it and attach the results. Maybe the trace will give us some more clues.
12-22-2004 06:14 AM
Thanks to all who helped. Working from home is great, if you have the tools
Happy Holiday's to all!!