0

Hello I am running a bash shell script to send to html page but the html page keeps putting this "[7l" character in with my shell command output from the bash script.

echo "<pre>"                                                 >> stats.html
echo "####### DISK Usage  ########" >> stats.html
/usr/bin/dstat --disk-util --disk --top-bio-adv 1 1   >> stats.html
echo "</pre>"                                                 >> stats.html

And the html page has this in it

####### DISK Usage  ########
[7lsda- -dsk/total- ----most-expensive-block-i/o-process----
util| read  writ|process              pid  read write cpu
0.04|  16k 8087B|systemd              1    8111B6247B0.0%
  • Have you tried the --nocolor option? – Rio6 Sep 11 at 0:45
  • 1
    That's not a color-code (looks like someone hard-coded something to attempt to ignore wrapping without bothering to notice that output's redirected). – Thomas Dickey Sep 11 at 0:52
3

Just filter the thing:

/usr/bin/dstat ... | sed 's/\x1b\[7l//' >> stats.html

Since dstat is a python script, you can also fix it by just editing it: take the sys.stdout.write line after the ### Disable line wrapping and move it (properly indented) after the if sys.stdout.isatty():

--- dstat~
+++ dstat
@@ -2267,10 +2267,10 @@
     hostname = os.uname()[1]

     ### Disable line-wrapping (does not work ?)
-    sys.stdout.write('\033[7l')

     ### Write term-title
     if sys.stdout.isatty():
+        sys.stdout.write('\033[7l')
         shell = os.getenv('XTERM_SHELL')
         term = os.getenv('TERM')
         if shell == '/bin/bash' and term and re.compile('(screen*|xterm*)').match(term):
  • The sed command helped thanks. – Andreas Magana Sep 11 at 18:37
  • @AndreasMagana Good! If this solves your issue, please consider "accepting" the answer. This is the best way to show gratitude on this site. Accepting an answer not only marks the question as resolved, but also signals to future readers that the accepted answer actually solved the issue. More information about this is available here: unix.stackexchange.com/help/someone-answers – Kusalananda Sep 11 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.