Results 1 to 3 of 3
I use below bash script
Code:
#!/usr/bin/bash
top -n 1 -s | head -n 4 >> tmp.tmp
line=` cat tmp.tmp|wc -l `
echo $line
while [ $line -gt 0 ]
...
- 03-19-2010 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 44
strange character after ">>"
I use below bash script
I vi the tmp.tmp and tmp1.tmp file and get strange character ....Code:#!/usr/bin/bash top -n 1 -s | head -n 4 >> tmp.tmp line=` cat tmp.tmp|wc -l ` echo $line while [ $line -gt 0 ] do a=`cat tmp.tmp | head -n $line | tail -n 1 ` echo $a echo $a >> tmp1.tmp line=`expr $line - 1` done
how can I fix it ...
Code:^[[H^[[2J^[[m^[(Btop - 17:49:08 up 19 min, 2 users, load average: 0.09, 0.16, 0.28^[[m^[(B^[[39;49m^[[K Tasks:^[[m^[(B^[[39;49m^[[m^[(B 74 ^[[m^[(B^[[39;49mtotal,^[[m^[(B^[[39;49m^[[m^[(B 1 ^[[m^[(B^[[39;49mrunning,^[[m^[(B^[[39;49m^[[m^[(B 73 ^[[m^[(B^[[39;49msleeping,^[[m^[(B^[[39;49m^[[m^[(B 0 ^[[m^[(B^[[39;49mstopped,^[[m^[(B^[[39;49m^[[m^[(B 0 ^[[m^[(B^[[39;49mzombie^[[m^[(B^[[39;49m^[[K Cpu(s):^[[m^[(B^[[39;49m^[[m^[(B 0.6% ^[[m^[(B^[[39;49mus,^[[m^[(B^[[39;49m^[[m^[(B 10.8% ^[[m^[(B^[[39;49msy,^[[m^[(B^[[39;49m^[[m^[(B 0.0% ^[[m^[(B^[[39;49mni,^[[m^[(B^[[39;49m^[[m^[(B 81.1% ^[[m^[(B^[[39;49mid,^[[m^[(B^[[39;49m^[[m^[(B 7.3% ^[[m^[(B^[[39;49mwa,^[[m^[(B^[[39;49m^[[m^[(B 0.2% ^[[m^[(B^[[39;49mhi,^[[m^[(B^[[39;49m^[[m^[(B 0.0% ^[[m^[(B^[[39;49msi^[[m^[(B^[[39;49m^[[K Mem: ^[[m^[(B^[[39;49m^[[m^[(B 2567708k ^[[m^[(B^[[39;49mtotal,^[[m^[(B^[[39;49m^[[m^[(B 391228k ^[[m^[(B^[[39;49mused,^[[m^[(B^[[39;49m^[[m^[(B 2176480k ^[[m^[(B^[[39;49mfree,^[[m^[(B^[[39;49m^[[m^[(B 44964k ^[[m^[(B^[[39;49mbuffers^[[m^[(B^[[39;49m^[[K ~ ~ ~ ~ ~ ~ ~ ~ "tmp.tmp" 4L, 912C
- 03-19-2010 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
By 'strange character' I assume you mean the '^[[H^[[2J^[[m^[('. Those are escape sequences that do things like clear the screen, position the cursor, etc. If you want just the text then add the '-b' option (batch mode) to the top command.
- 03-19-2010 #3
Indeed. The problem is that "top" does a lot of weird things, like erasing characters and clearing the screen. If you run top in a terminal, you will see that it updates itself, it does this by printing control characters, which have special meanings to a terminal. However, when printed to a file, they don't have special meanings, so they just appear.
As lomcevak says, using top's "-b" option will fix this. If we check the man page for top:
Code:-b : Batch mode operation Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.DISTRO=Arch
Registered Linux User #388732


Reply With Quote