Linux Blog

Mounting Remote shares with SSHFS

Filed under: General Linux,Quick Linux Tutorials — TheLinuxBlog.com at 4:47 pm on Wednesday, August 11, 2010

If you have ssh access to a remote machine and wish to browse the file system SSHFS is a great utility.
It can be easily installed by your favorite package manager, or compiled from scratch. It has been a dear friend of mine for at least a couple of years.

To mount a file system with SSH, it is almost simpler than making an SSH connection:

sshfs [user]@[host]: [mountpoint]

to unmount is just as simple. Either:

fusermount -u [mountpoint]

OR

sudo umount [mountpoint]

Once your remote file system is mounted, you may bask in its glory and take advantage of everything a local file system has to offer although you may notice a slight delay.

If you’re an mplayer user and wish to stream media, you can use the -cache option to give you a little bit of a buffer.

Multi Tail – Multi Tail!

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 6:28 pm on Wednesday, March 10, 2010

Multitail Gnome Terminal

A few weeks ago a new version of RSSTail came out. After reading the RSSTail page I found out that you can use RSSTail as a plugin to a fantastic application called multitaill. That is when I realized that multitail is actually written by the same person.

If you rely on tail, or have ever used tail you’ll probably enjoy this one. As the name implies it is a pager like tail except that it supports for more than one stream. Now, I know some of you have probably used some wizardry do get your favorite pager to show multiple streams, either in the same output or by using screen / splitvt but multitail really simplifies the process. It has all kinds of settings (such as color) and allows you to manage your tail’d files on the fly and even save the current view for later use. It does have a little bit of a learning curve but I think it is well worth it, especially if one of your hobbies includes log watching.

Last 50 Characters of Each line

Filed under: Shell Script Sundays — TheLinuxBlog.com at 4:18 pm on Sunday, May 24, 2009

I got a question from a user called Bastiaan. He had found my site while searching for ‘cut from end of line Linux’ and landed on the Using cut – shellscript string manipulation article. I haven’t received a lot of feedback on it, but am happy with the feedback I have and the amount of visits it gets. As I’ve said before if no one else reads The Linux Blog I still use it as a reference, so I am glad people are finding it useful. Anyways, Bastiaan’s problem was he works in a University and has a file with A LOT of DNA records in it. He needed to grab the last 50 characters of each line, regardless of the line length. After some correspondence we came up with a solution.

I have experience in doing this sort of thing in other languages such as PHP but not bash. Here is what I came up with for bash:

cat find.txt | while read i; do echo $i | \
cut -b $((`echo $i | wc -c` - 50))-; done;

While this was really quick to write it is not the most efficient way in the world. It has to read each line, echo it out, calculate the length of the line, subtract 50 from it. Again, does the job but not very gracefuly.

Bastiaan then had told me he reversed the whole file and then was processing that with cut. I have heard of tac, to reverse entire files, but not had never heard of rev. Using rev I assumed that he was running something like the following:

rev file.txt > rev_file.txt
cat rev_file.txt | cut -c -50 | rev

That will get you the last 50 characters from each line (well, really the first 50 of a reversed file) That works pretty good so the final solution was to try to stream line it a little bit so that it could be done in one step.

rev file.txt | cut -c -50 | rev > out.txt

So there you have it, if you’re looking to use cut to “cut” characters from the end of the line, the above will cut 50 characters off of the end. Obviously you can remove the last “> out.txt” to get the output on the screen.

Hope this helps some one, and thanks to Bastiaan for the question!

Getting a Hand With Bash

Filed under: General Linux — TheLinuxBlog.com at 8:27 am on Wednesday, October 1, 2008

If you use the bash shell, or as many know it the terminal on a regular basis then there is a package that you can install that will make your life a whole lot easier. Firstly I’ll tell you a little bit more about it.
When I first started using Linux a friend told me to install this package. I never really understood what it exactly did, but using the terminal was a whole lot easier then using the command prompt in Windows. I couldn’t explain it but things just worked. Features that were missing from Dos were there. There was awesome auto completion that knew what I wanted to type. Over the years I became more accustomed to using Linux and the Bash shell. I upgraded hardware, changed distributions and never really noticed what I was missing out on. The other day I was thinking, wouldn’t it be nice if I could press tab and this would auto complete. Then it hit me, the package my friend had told me to install when I first was starting out. The package happened to be exactly for this purpose. Since I was a novice and he was helping me out I didn’t really have the time to ask about the details of every single package, so here I am now letting you in on a little secret. (Read on …)

Wakoopa For Linux

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 12:01 am on Monday, March 31, 2008

I stumbled across Jakes blog post over at: http://blogs.howtogeek.com/jatecblog/posts/software-tracker-for-linux. Until this point I had never heard of the Wakoopa service. It seems like a really good idea. It is sort of the Alexa for software applications. Naturally I left a comment showing interest in an open source Wakoopa and shortly after received an e-mail from Jake.

Here it is:

Hello Owen, 

First I'd like to clarify that I don't actually have a need for the
application tracker... it would be purely for fun. That said, I would love if
you would be willing to create this. Here is the idea I have envisioned in
more detail but do not have the skills to create:

1) The process list is purged every so often to generate a log file.
2) The log file is periodically sent to a server. It is cleared after each
time it is uploaded.
3) The server then has an application which goes through and sorts out process
names and so forth and presents them as user reader data (much like Wakoopa) 

I think that this would be the easiest way, but I'd love to hear your
suggestions. If you were to make this I think it would be used and loved by many, as well as being useful.

Now that he has broken it down like that it seems like it would be pretty easy to implement. The only thing that I can see being a little bit complicated is determining what processes are running and how long they have been running for. I hopefully have a short shell script up for next Sundays column and have some sort of prototype. There should be nothing new in this script that I haven’t covered before on this blog, except possibly the sort command. Other commands I plan to know I will probably use are ps or top, cat and echo. There will probably be lots of loops and conditional if’s. The good thing about this idea is that if I write a shell script to do this some one will be able to translate it into another language. The real part where I would like to spend the majority of my time would be in the web interface. I expect that this will be written in PHP but I am unsure of the database technology that will be used since the recent happenings with MySQL.

So when this open source Wakoopa prototype is finished how many people do you think will use this service? Would you use it? What do you think an acceptable update time is? Any one have any other questions / input?

Using wc and How To Count Table Rows

Filed under: Shell Script Sundays — TheLinuxBlog.com at 1:07 pm on Sunday, March 9, 2008

I made this little script to check how many packages were available on the web from the Cygwin Package Repository located at http://www.cygwin.com/packages

Its a one liner but it does its job well.

CYGLIST=$(curl http://www.cygwin.com/packages/ | grep \<tr | grep ball | wc -l); echo $CYGLIST;

All the above is doing is creating a variable called CYGLIST that is the result of grabbing the cygwin.com/packages/ page, grepping all of the TR’s that also have the word “ball” in it (for the image) and then using the wc -l (L) command to count how many results are found. Then the list is echoed out.

wc is a very useful command for printing newline, word and byte counts. This is a good example of how to use wc to count lines in a shell script. wc can also be used to print all of these values in one line of a file.  The syntax is below:

bash-3.1# wc file.txt
9  20 184 file.txt

The above shows the number of lines in the file.txt, it shows how many words are in the file and also how many bytes. In my first example wc uses the -l switch to display the number of lines. This script can also be used with a little bit of bash math to calculate how many items are in an HTML list. I’m working on a script that automatically does this, when its finished I will be sure to post it here on The Linux Blog.

Graphical Shell Scripting

Filed under: Shell Script Sundays — TheLinuxBlog.com at 4:07 pm on Sunday, December 16, 2007

From all of my other previous shell scripting articles you can see that shell scripting is a very good way to get a task done or to automate. This is great but some times a little bit of that three letter acronym “GUI” is a nice touch. Well my friends, if you’ve been reading my articles and following my dialog examples then you are in luck. If not don’t worry, you can view all of the articles in the Shell Script section to the right.

The program to make your GUI’s for your shell scripts is the exact same thing as dialog except its graphical. Its called Xdialog. Once installed you basically use it the same way as dialog. If your thinking about upgrading a script thats written in dialog you might want to think twice because some window managers will display the windows differently.

Check out these Xdialog examples and corresponding screenshots:

Xdialog

Xdialog -yesno “Do you like Xdialog?” 5 50 && echo “Thats nice” || echo “Yea, some times its better to stick to CLI”

Xdialog ExampleXdialog Example