Linux Blog

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.

Creating Dialogs with Dialog

Filed under: Shell Script Sundays — TheLinuxBlog.com at 5:48 pm on Sunday, October 21, 2007

Have you ever seen those pretty dialogs used in Shell Scripts such as the Slackware installation, the slackpkg program or even the NVIDIA driver installer? Well, my friends to display dialog boxes from shell scripts is very easy with… you guessed it – Dialog.

First of all, there are many different types of dialogs that you can create they are as follows: calendar, checklist, fselect, gauge, infobox, inputbox, menu, msgbox (message), password, radiolist, tailbox, tailboxbg, textbox, timebox, and yesno (yes/no).

This blog post is intended to be a primer on using dialog. More examples will be posted in future blog posts in the Shell Script Sunday’s column.

The simplest form of a dialog in a shell script is probably the msgbox. All this really does is displays text. To display text in a dialog you would do the following:

owen@the-linux-blog:$ dialog –msgbox “Hello from the Linux Blog!” 5 50

The numbers after the text in quotes are the widths and heights of the box. The minimum height that I like to use is 5. The width doesn’t really matter as long as it is big enough. It is good to keep the box sizes standard across a whole script because it gets annoying with constantly resizing boxes.
If the text in a message box is too long it will auto wrap around and give you a type of scroll bar. As follows:

owen@the-linux-blog:$ dialog –msgbox “Hello from The Linux Blog. This text is so long it wraps it to a New Line” 5 50

Dialogs can be canceled. Clicking Ok or pressing enter/return returns “true” and pressing escape or Ctrl+C returns a false.
The simple shell scripting syntax shown in Shell Scripting 101

is used for this:

owen@the-linux-blog:$ dialog –msgbox “Dialog Exit Example” 5 50 && echo “ok” || echo “false”

Another simple dialog example is the Yes/No box. The syntax for this is exactly the same as the msgbox example except instead of using –msgbox, –yesno is used. The difference between a msgbox and a yesno box is that there a two buttons. It is pretty obvious as to what they are labeled, but for those in the back, I’ve included an example and some screen shots anyway.

owen@the-linux-blog:$ dialog –yesno “Are you learning anything from this blog” 5 50 && echo “Yes, thanks Owen.” || echo “No, Write some better Linux Related Posts”

The Linux Blog - Dialog Example - Yes / No

Thats about all I have time for this week. Check back next week!