Linux Blog

tee time!

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:19 pm on Sunday, June 10, 2012

This weekend was South East Linux Fest, although I’m bummed I couldn’t make it I did learn something new from taking an LPIC level 1 self assessment. What I learned about was the application tee.

The question was something like:

“What command outputs to stdout and also writes to a file”

My answer was “echo” but that was the wrong answer. The correct answer was tee.

I’d seen it before in either Slackware or Debian’s packages list but forgot totally about it. It’s a pretty handy utility to have in your arsenal if you ask me. Usage would be something like this:

date | tee date.txt

this will echo the current date out, and also write it to date.txt. Of course, there are plenty of useful options which can be viewed in the man page which is linked below.

Enjoy! Happy Shell Scripting!

Logging Sessions to Twitter

Filed under: Linux Software — TheLinuxBlog.com at 12:01 am on Wednesday, August 20, 2008

If you follow me on Twitter you would know I asked everyone if there was anything that they wanted me to write about. @Ben_Marvin responded and asked about logging the commands you type to Twitter.At first, I thought that this could be done with history, which it probably can be, but does everything you type really have to be echo’ed to Twitter? I don’t think that you’d have many friends, Twitter would probably hate you and you’d most likely hit your maximum requests per hour pretty quickly.The Script command is another option, and this works quite well for this purpose. Read the script man page to find out more about this program. It basically (when ran) takes the I/O from your terminal and logs it to a file. Its a very handy utility.So, how do we get this data into Twitter? First of all, Twitter doesn’t allow very long posts so echoing out the data that the commands you type is not really practical. The best way to do it is to use script to log the session, exit the session and grep for the “]0\;” string for stuff you typed & not the responses.Here is the code:

script; grep ]0\; typescript 

You can then copy and paste it to your favorite Twitter application or pipe it to a scrubbing script to remove the formatting and do the correct HTML stuff, then post it via the http interface. Either way, it can be done even though I don’t think it really should.