Writing string to file
Can't get rid of echo to console. When I do this:
echo "<br>" >> /etc/temp.txt Is echos to the console also. Is there a way to stop this? This also sends a message to the console: lsb_release -a >> /etc/temp.txt Any way to stop this? Thanks |
It doesn't on my machine.
Are you sure you aren't just referring to the line which your are typing? |
Quote:
|
Is it possible you have gotten the verbose option set on your shell? (could you show a recorded sequence that shows the problem?)
|
|
Here is the code that does this:
#!/bin/bash # # Script to build server statistics Lstats.html # varupt=$(uptime) serverid="test.net - " webpgnm="Lstats.html" tempvar="" tempnum=0 fontsz="2" hfontsz="2" cat /dev/null > /var/www/$webpgnm # clear html file echo "<html><head><title>Server Stats</title></head><body><body bgcolor="#E7DFAD" TEXT="#000040" LANG="en-US" DIR="LTR">" > /var/www/$webpg$ #date echo "<br><font face=\"Verdana\" size=$fontsz> " >> /var/www/$webpgnm echo $serverid $(date) >> /var/www/$webpgnm echo "</font><br><br>" >> /var/www/$webpgnm # machine echo "<font face=\"Verdana\" size=$hfontsz><caption> Machine</caption></font>" >> /var/www/$webpgnm echo "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\"><tr><td><font face=\"Courier New\" size=$fontsz>" >> /var/www/$webpgnm uname -mrs > /etc/temp.txt echo "<br>" >> /etc/temp.txt lsb_release -a >> /etc/temp.txt sed '/No LSB/d' /etc/temp.txt sed 's/Description:/<br>Description:/g' /etc/temp.txt > /etc/temp2.txt sed 's/Release:/<br>Release:/g' /etc/temp2.txt > /etc/temp.txt sed 's/Codename:/<br>Codename:/g' /etc/temp.txt > /etc/temp2.txt cat /etc/temp2.txt >> /var/www/$webpgnm varupt=`echo ${varupt//up/Up}` varupt=`echo ${varupt//load/Load}` awk -F '[ \t\n\v\r]' '{print "<br>"$2" "$3" "$4" "$5" "$8" "$9" "$10" "$11" "$12" "$13" "$14" "$15}' <<< $varupt >> /var/www/$webpgnm echo "</font></td></tr></table><br>" >> /var/www/$webpgnm # end build Machine echo "</font></td></tr></table><br>" >> /var/www/$webpgnm echo "</body></html>" >> /var/www/$webpgnm exit 0 This is what it prints to screen with a ./pgmname No LSB modules are available. Linux 3.2.0-4-686-pae i686 <br> Distributor ID: Debian Description: Debian GNU/Linux 7.5 (wheezy) Release: 7.5 Codename: wheezy |
Overly complex...
Three errors: 1) Line 15. I believe $webpg$ should be $webpgnm 2) Line 15. You have "<body><body ...". There should be only one. There are some other HTML errors too. 3) Line 28. you use a "sed" with no output file specification - thus the output is sent to the terminal. I say overly complex because you are using multiple echo commands for what could be more easily done with a "hereis" input. Here is an example of a cleaned up version: Code:
#!/bin/bash It also eliminates the HTML errors. I believe the piped sequence of sed commands can also be eliminated, but will admit the sequence is simpler to debug and read. I think there is a better way to handle the $varupt stuff. This just seems a bit awkward. But you can't beat what really works. BTW, if you are going to use variables to hold file names... it is clearer to put the entire path in the variable too. It would eliminate multiple substitutions later on. One final thing... This script is most likely being run as root. This means that the output file is USUALLY owned by root and with roots permissions, and security label. This shouldn't be a problem once the file is created and given the correct ownership/permissions/security label (RH and Fedora servers). The script preserves that when run by root as it only truncates the file at the beginning, then appends to it. |
Thanks. I like the lsb_release -a better also. Still learning this stuff.
The $webpg$ was a result of a copy from terminal error. I noticed the double body statements and fix that just before seeing your post. I am used to throwing things back upon them self in other languages I use, so did it here also. Bash is kind of like IBM assembler, only much more syntax prone. Thanks again. |
I kind of thought the $webpg$ was a copying error.
Bash is much higher level than IBM assembler. The usual problem is getting the quotes right - especially when doing multiple levels of substitution. Handling the substitions is much more like a macro processor, but with entire file manipulation as the underlying operations. |
I'm getting there. I have made an abbreviated notebook and am just now getting where I need to manipulate data.
|
All times are GMT -5. The time now is 07:38 PM. |