Linux Blog

Perform an action when a host comes back

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:28 am on Sunday, October 24, 2010

Perform an action when host comes backI have in the past been lazy enough to not wait for a host to come back, yet need to do something when it comes back. Lets say starting up that service I never got around to creating startup scripts for, or uploading new firmware. Well, I found this little trick on NSLU2-linux.org

sudo arping -f && echo “True”

Obviously the echo “True” can be replaced with whatever you wish. A sleep may be good if you want some extra time before performing the action. Pair this with a SSH identity / key pair and you can perform the actions on the host remotely.

Freemind Vs. Kdissert

Filed under: Linux Software — TheLinuxBlog.com at 6:30 am on Wednesday, October 20, 2010

FreeMind vs kdissert

Mind mapping is a great way to get all of your thoughts out. There are two major competitors when it comes to mind mapping on Linux.

In the blue corner we have reigning champion FreeMind and in the red corner we have a new contender for the best mind mapping software kkkkkkkkkkkdissert.

FreeMind Vs kdissert…. Fight. (Read on …)

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.

Yum Messed Up

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 10:05 am on Monday, November 16, 2009

So, this morning, when I got to work and booted up, I noticed something was wrong. My machine was not running as usual. It turns out, packagekit was sitting there being a general pain. I just wanted to look busy, so I killed the process. Turns out that wasn’t such a good idea, since it didn’t finish doing whatever it was doing and caused an ugly error like this:

rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 – (-30975)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed

rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 – (-30975)

Naturally, I tried using rpm, do try and fix things, since it indicated something to do with a database I tried:

[owen@linuxblog ~]$ sudo rpm –justdb
rpm: –justdb may only be specified during package installation and erasure
[owen@linuxblog ~]$ sudo rpm –rebuilddb
rpmdb: Thread/process 28373/3077981888 failed: Thread died in Berkeley DB library
error: db4 error(-30975) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 – (-30975)

Well, it turns out that those options don’t work, and the rebuilddb gave an error about the db4 being corrupt. Well, I decided to go into /var/lib/rpm as the other error had that directory and found the db4 files. Running db45_recover sounded like it might work, so I gave it a shot.

[owen@linuxblog rpm]$ db45_recover -h /var/lib/rpm/
db45_recover: unlink: /var/lib/rpm/__db.003: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.004: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.000: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.002: Permission denied
db45_recover: unlink: /var/lib/rpm/__db.001: Permission denied
db45_recover: /var/lib/rpm/log.0000000001: log file unreadable: Permission denied
db45_recover: PANIC: Permission denied
db45_recover: DB_ENV->log_newfh: 1: DB_RUNRECOVERY: Fatal error, run database recovery
db45_recover: dbenv->close: DB_RUNRECOVERY: Fatal error, run database recovery

That’s right,you need to be root for this bad boy:

[owen@linuxblog rpm]$ sudo db45_recover -h /var/lib/rpm/

The above seemed to fix it for now. I guess next time I’ll think about it more before I start slaying processes on a Monday morning.

Daily vim, Easier Command Line Editing Hack

Filed under: Quick Linux Tutorials — TheLinuxBlog.com at 2:06 pm on Tuesday, July 7, 2009

I’m a fan of the Daily Vim. While reading, I came across the old long command line edit: http://dailyvim.blogspot.com/2009/06/easier-command-line-editing.html

Since I don’t have emacs installed (fire away) after Pressing CTRL-x CTRL-e to edit the command, this is what I got:

[owen@LinuxBlog ~]$
bash: /usr/bin/emacs: No such file or directory

There is a simple fix for this:

sudo ln -s vim /usr/bin/emacs

I’m sure there is a correct way to do this, but this is what I did and it has worked well for me so far.

Using Subversion with SSH & Custom Ports

Filed under: Linux Software,Quick Linux Tutorials — TheLinuxBlog.com at 9:09 am on Monday, September 15, 2008

Lets say you use subversion on your home PC to keep track of projects and you want to checkout or export your project from a remote location. Here’s the catch, sshd is running on a custom port or forwarded from another. For some reason the command line SVN client does not support a port parameter when using the defacto svn+ssh://

svn co svn+ssh://thelinuxblog.com/owen/svn/project1/trunk project1
ssh: connect to host thelinuxblog.com port 22: Connection refused

Well we know why the error above happens its because I happen to run SSH on port 1337. The following work around requires root privileges, and may mess with your system a bit but if you really need to check something out, then it will work.

As root, login and stop SSH if you run it. With SSH Forward port 22 with a local SSH forwarding connection to the remote host.

[owen@thelinuxblog.com]$ sudo su -
[root@thelinuxblog.com]$ /sbin/service sshd stop
[root@thelinuxblog.com]$ ssh -p 1337 owen@thelinuxblog.com-L 22:<internal ip>:1337

Once this is done, your localhost:22 now forwards to your remote host. With another session (on your local machine) you can verify the connection by using ssh localhost. You will probably get warnings about the hosts identity being changed, or not verifying it, but you can ignore then. Once you’ve tested it, just use SVN as normal. When finished, remember to logout of the SSH session, and start SSH back up again if you run it.

Linux ipconfig

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 7:32 am on Thursday, December 13, 2007

I’m both proud and annoyed that there is no Linux ipconfig command:

owen@linux-blog:~$ ipconfig
-bash: ipconfig: command not found

I’m proud to be different but it annoys me because I like to see standards between operating systems. Luckily the Linux ipconfig utility is easy to remember. On most Linux distributions it is ifconfig. I’m not exactly sure why its called ifconfig but I remember it as the word “if” or “InterFace”. If you try to execute the command from your shell you might get this error:

owen@linux-blog:~$ ifconfig
-bash: ifconfig: command not found

If this happens don’t be alarmed the problem is probably that you are logged into your regular user account and not root. To run as root I would use sudo, or su to switch to the root user and try again. There is a trick to get ifconfig to work with a regular user but no changes to the configuration will be able to be made. The path to ifconfig and trick success rate varies by distribution, some high security distributions will not let you do this trick:

owen@linux-blog:~$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:10:B5:70:B0:79
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1609257 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1640883 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:236511428 (225.5 Mb)  TX bytes:422972120 (403.3 Mb)
          Interrupt:11 Base address:0xee00

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:34516 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34516 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:13210707 (12.5 Mb)  TX bytes:13210707 (12.5 Mb)

For an IPConfig that is a lot of data. If you know the interface that you want the data for, you can just specify the name with the command like so:

owen@linux-blog:~$ /sbin/ifconfig eth1

There is a lot more to this command then first meets the eye. I’ll go into detail about networking and the Linux ipconfig utility in another blog post. Thanks for reading, show me some love by leaving me a comment!

Slackware MPlayer Setup

Filed under: General Linux,Linux Software,The Linux Blog News — TheLinuxBlog.com at 12:03 am on Tuesday, December 4, 2007

I’ve updated the MPlayer Installer and uploaded it.

Instructions:

1. Download The MPlayer Installer that I made (Right click Save Link As).

2. Change to root user and run the MPlayer Installer OR run the MPlayer Installer with sudo as followed:

bash-3.1$ su root

Password:

bash-3.1# sh mplayer_setup.sh

OR

sudo sh mplayer_setup.sh

Changes to this version:
mplayer-1.0rc1try3-i486-2kjz.tgz is now being used as mplayer-1.0rc1-i486-1goa.tgz is no longer available.
Instead of using the essential codecs pack I am now using the all-20071007.tar.bz2 package. This includes so many more codecs. Even apple.com trailers work for me now.
A bunch of dependencies / libraries are now being downloaded and installed here is the list:

a52dec-0.7.4-i486-1kjz.tgz
libmpcdec-1.2.6-i486-1gds.tgz
libmpeg3-1.7-i486-1gds.tgz
avifile-20071003-i486-1gds.tgz
mpeg2dec-0.4.1-i486-1gds.tgz
faac-1.25-i486-1gds.tgz
faad2-2.6.1-i486-1wim.tgz
speex-1.2beta2-i486-1kjz.tgz
ffmpeg-20070622-i486-1kjz.tgz
twolame-0.3.10-i486-1kjz.tgz
jack-0.103.0-i486-1kjz.tgz
x264-20070722-i686-1mfb.tgz
lame-3.97-i486-1kjz.tgz
xmms-1.2.11-i486-1McD.tgz
libdv-1.0.0-i486-1gds.tgz
xvidcore-1.1.3-i486-1kjz.tgz
mplayerplug-in-3.45-i486-1kjz.tgz
libdc1394-1.2.2-i486-1gds.tgz

Notes:
The following error is caused because samba is not installed:

mplayer: error while loading shared libraries: libsmbclient.so.0: cannot open shared object file: No such file or directory

If you run into any other problems, as always you can e-mail me (owen @ thelinuxblog.com) for help.
Because of all the changes the line by line breakdown of the installer from: Slackware 12 – MPlayer Setup in 3 Easy Steps post is no longer accurate.

Snippet: Keeping SSH Running

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 12:53 am on Sunday, November 4, 2007

I wrote a post not so long back called Bringing The Internet Up After Failure that explained how I was restarting my network services after the internet went down.

Shortly after this I was remotely working when I thought it would be a good idea to restart my SSHD to enable X11 forwarding. After running the script that normally restarts the service I tried to reconnect. Unfortunately the service never restarted after being stopped. This is not a good situation for any one to be in so I added something like this to my cron along at the end of my network services script:

ps ax | grep \usr\/sbin\/sshd | grep Ss && echo “SSHD Running” || echo “Starting SSH”; sudo /etc/rc.d/rc.sshd start

The only difference between the version I am running and the version above is that I don’t echo anything out. All the command does is use the ps command and grep for usr/sbin/sshd then grep for the STAT field of sS. I do this because sshd shows up in the process list as shown below:

owen@the-linux-blog$ ps ax | grep sshd
3463 pts/0 R+ 0:00 grep sshd

The rest is self explanitory, it echo’s “SSHD Running” or sudo starts the SSHD.

If SSHD ever terminates on me or those of us who run this snippet we will be able to rightfully regain access to our systems, Hurray!

Bringing The Internet Up After Failure

Filed under: Shell Script Sundays — TheLinuxBlog.com at 9:58 pm on Sunday, September 9, 2007

This Shell Script Sunday is a short one but don’t let that fool you to the power of the shell. This script I wrote earlier in the week due to power spikes at the office. All of our equipment would stay powered on due to UPS’s but unfortunately something with the ISP was not staying on. Once the brownout occurred our router box would still have an IP and seem to be working but it wouldn’t. We had our suspicions about what piece of equipment it was but had no power to fix it. I would renew the IP from the ISP bring the public interface down by using eth0 down and then eth0 up but this was not successful. To fix it from the router I had to actually reset the network. This worked, but we have some services running at the office that I like to access from home. So to fix the problem I wrote a one liner to reset the network if the connection goes down.

ping -c 1 OurISP.com 2> /dev/null > /dev/null && echo > /dev/null || sudo /etc/rc.d/network restart

The techniques in this script are covered in Shell Scripting 101. All this does is ping OurISP.com one time and output the error & standard output to /dev/null. If the ping was successful it does nothing and if the ping failed then it restarts the network. To get it to repeat at an interval I just set it up as a cron job. This did the trick and I now do not have to worry about brownouts.

Slackware 12 – MPlayer Setup in 3 Easy Steps

Filed under: General Linux — TheLinuxBlog.com at 9:46 am on Thursday, September 6, 2007

I made a quick installer script that will install MPlayer 1.0rc1 with the essential codecs pack and the Firefox plugin on a new installation of Slackware 12. With this script you should be able to get MPlayer set up on Slackware 12 in 3 easy steps.

1. Download The MPlayer Installer that I made (Right click Save Link As).
2. Change to root user and run the MPlayer Installer OR run the MPlayer Installer with sudo as followed:

bash-3.1$ su root
Password:
bash-3.1# sh mplayer_setup.sh

OR

sudo sh mplayer_setup.sh

3. If everything installed smoothly you can remove the mplayer directory and all files inside it. If it failed then all you need to do is (as root) removepkg on all of the .tgz files and do a rm /usr/lib/codecs/*.

Firefox should be restarted after the script has run. Test Firefox by going to various media sites, one I like to use is Apple Trailers (Because of the quality and speed). If you could contact me and let me know if the installer worked or failed I would appreciate it.

Line by line breakdown of the installer:

mkdir mplayer; cd mplayer;

Creates the mplayer directory and moves into it.

wget http://www2.linuxpackages.net/packages/Slackware-12.0/X11/MPlayer/mplayer-1.0rc1-i486-1goa.tgz; installpkg mplayer-1.0rc1-i486-1goa.tgz

Gets the mplayer-1.0rc1-i486 package from linuxpackages.net then installs the package

wget http://www2.linuxpackages.net/packages/Slackware-12.0/Library/mplayerplug-in/mplayerplug-in-3.45-i686-1amg.tgz; installpkg mplayerplug-in-3.45-i686-1amg.tgz

Gets the mplayer plug-in for Firefox and installs it

wget http://www4.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2

Downloads the essential codecs pack from mplayerhq.hu

tar xvjf essential-20061022.tar.bz2; mv essential-20061022/* /usr/lib/codecs; rm -rf essential-20061022

extracts the essential codecs package to one of the directories MPlayer looks for codecs in and removes the directory.