Archive for the ‘terminal’ Category

If you are a software developer, a sysadmin or a devops, all of us have do deal with log files to see what’s happening in our system and to find analyse its behaviour. Going through normal log files (log4j) and analysing them is a bit painful since all the lines are printed in same colour.

There are some better log tools such as Multitail. However if you are  looged into a remote server via “ssh” , then you don’t have the luxury of using these tools. However Linux “awk” utility comes to help. AWK is a Linux text processing tool, text in files and streams. It matches a specified pattern and execute some action on it. If a pattern is not specified, it applies the action on all lines.

Print  with  colours

Below script reads the WSO2 ELB log file and matches all INFO s and print them in green, ERROR s in red, FATALs in red, WARN s in yellow.

tail -f /opt/wso2elb-2.0.4/repository/logs/wso2carbon.log | awk '
/INFO/ {print "\033[32m" $0 "\033[39m"}
/ERROR/ {print "\033[31m" $0 "\033[39m"}
/FATAL/ {print "\033[31m" $0 "\033[39m"}
/WARN/ {print "\033[33m" $0 "\033[39m"}
'
Log with colour

Log with colour

Filter with colours

In addition to above script, below script matches the log messages with the word “joined” and shows them in blue colour.


tail -f /opt/wso2elb-2.0.4/repository/logs/wso2carbon.log | awk '
/INFO/ {print "\033[32m" $0 "\033[39m"}
/ERROR/ {print "\033[31m" $0 "\033[39m"}
/FATAL/ {print "\033[31m" $0 "\033[39m"}
/WARN/ {print "\033[33m" $0 "\033[39m"}
/joined/ {print "\033[34m" $0 "\033[39m"}
'

Note : Some Linux systems such as Ubuntu has output buffer enabled by default for awk. Sometime it may result in some content at the end of the log file not showing in the console. To avoid it you can use gawk which is the GnuAWK implementation or turn off the standard output as below.


tail -f /opt/wso2elb-2.0.4/repository/logs/wso2carbon.log | stdbuf -o0 awk <awk_parameters>'

As you know Linux terminal is a very powerful tool which allows the user to perform almost everything on your Linux machine. It is the best tool a developer should get used to. Most developers use Google services such as email, blogger, youtube, docs, calender, picasa and finance. In order to consume these services users have to use a web browser like Firefox or Chrome. But can’t we use our best tool, Linux terminal for it.

googlecl allows above services to be accessed via Linux commandline. You can

  • Create blog posts
  • Add calendar events
  • View your google docs
  • Add calendar events
  • Upload images to Picasa
  • Upload videos to Youtube

Step 1 – Install

sudo apt-get install googlecl

The syntax for any command is
google  SERICE TASK
services include blogger, docs, contacts, youtube, picaza and finance

Create a blog post

google blogger post --title "Terminal Blogging" "This post is created via Linux terminal"

List your contacts

google contacts list

List your google docs

google docs list

Upload images to Picasa

<tt>google picasa create "Terminal images" ~/photos/*.jpg</tt>



Upload videos to Youtube

<tt>google youtube post --category my_video.mp4</tt>

More examples can be found from the example page.