Advertisement
zerooone

Untitled

Mar 9th, 2011
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.26 KB | None | 0 0
  1. #!/bin/bash
  2. # By LoathingKernel
  3. # Needs sudo without interactive password for the dmesg command and clears dmesg.
  4. # Keeps a log of dmesg with conky color information, timestamps and text wrapping.
  5. # Colors can be easily cleared with sed.
  6. # At same point will be rewritten with diff
  7.  
  8. LOGFILE=$HOME/.conky/dmesg.log
  9. LOGNEWLINES=$(sudo dmesg -c | sed 's/.\{80\} /&\n\t/g')
  10.  
  11. ## Colors
  12. #RED="${color #EF2929}"
  13. #ORANGE="${color #FCAF3E}"
  14. #YELLOW="${color #FCE94F}"
  15. #GREEN="${color #8AE234}"
  16. #BLUE="${color #729FCF}"
  17. #PURPLE="${color #AD7FA8}"
  18.  
  19. if [ -n "$LOGNEWLINES" ]
  20.     then
  21.  
  22.     ## Read the date
  23.     TIMESTAMP=$(date +"%d-%m-%Y %T")
  24.  
  25.     ## Read the log
  26.     if [ -f $HOME/.conky/dmesg.log ]
  27.             then
  28.             LOGLASTLINE=$(cat $HOME/.conky/dmesg.log | tail -1)
  29.     else
  30.             LOGLASTLINE=""
  31.     fi
  32.  
  33.     ## Find the color of the last line and append the new lines
  34.     if [ $(echo "$LOGLASTLINE" | grep -c "EF2929") -eq 1 ]
  35.         then
  36.         echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #FCAF3E} /' >> $HOME/.conky/dmesg.log
  37.  
  38.     elif [ $(echo "$LOGLASTLINE" | grep -c "FCAF3E") -eq 1 ]
  39.             then
  40.             echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #FCE94F} /' >> $HOME/.conky/dmesg.log
  41.  
  42.     elif [ $(echo "$LOGLASTLINE" | grep -c "FCE94F") -eq 1 ]
  43.             then
  44.             echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #8AE234} /' >> $HOME/.conky/dmesg.log
  45.  
  46.     elif [ $(echo "$LOGLASTLINE" | grep -c "8AE234") -eq 1 ]
  47.             then
  48.             echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #729FCF} /' >> $HOME/.conky/dmesg.log
  49.  
  50.     elif [ $(echo "$LOGLASTLINE" | grep -c "729FCF") -eq 1 ]
  51.             then
  52.             echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #AD7FA8} /' >> $HOME/.conky/dmesg.log
  53.  
  54.         elif [ $(echo "$LOGLASTLINE" | grep -c "AD7FA8") -eq 1 ]
  55.                 then
  56.                 echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #EF2929} /' >> $HOME/.conky/dmesg.log
  57.  
  58.     else
  59.         echo "$LOGNEWLINES" | sed "1i\Timestamp: \\${TIMESTAMP}" | sed 's/^/${color #EF2929}/' >> $HOME/.conky/dmesg.log
  60.     fi
  61.  
  62. fi
  63.  
  64. if [ -f $HOME/.conky/dmesg.log ]
  65.         then
  66.         tail -40 $HOME/.conky/dmesg.log
  67. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement