Posts Tagged Linux Command of the Day

LCOD – 6.6.07 – Simple SSH remote command execution

ssh -X -C -f HOSTNAME PROGRAM

Of course you need to be running an X server (Linux/*BSD Desktop) on your client, and you need to have
ForwardX11 yes
or
ForwardX11Trusted yes

in your CLIENT’s /etc/ssh/ssh_config file
and
X11Forwarding yes
in /etc/ssh/sshd_config
on the SERVER.

, , , , ,

No Comments

LCOD – 5.9.07 – Updating CPAN in Perl

Perl rocks, it’s easily my favorite programming language. One of the nice things about Perl is the CPAN (Comprehensive Perl Archive Network). Your Linux box has CPAN installed already, and to begin using it you should first update it. To do so run the commands just below. The first time you invoke CPAN it’ll launch the configuration module, just hit enter until it gets into the part about which mirrors you want to use, it’ll have you pick geographic areas first, and then tell you to enter servers by number, separated by spaces. I usually put in about 20 servers, which looks like kinda this

30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10

#invoke perl’s CPAN shell (and first time configuration with)
bash$ perl -MCPAN -e shell
#once configuration is done, update CPAN, and then reload
CPAN> install Bundle::CPAN
CPAN> reload cpan

Now, head on over to CPAN and search for some cool new Perl modules to play with!

A great place to dive into the world of Perl is Perl.org

Also the Perl Monks is a good Perl site, and Use Perl is as well.

Make sure you have a correct build environment setup, on Ubuntu/Debian you need to install the build-essential package (sudo apt-get install build-essential)

, , , ,

No Comments

LCOD – 5.9.07 – Find out what Perl DBI drivers are installed

A perl one liner for you.

Say you’re installing something that is DBI and it’s giving errors or having problems,

or anything, and you want to know if it’s because you don’t have the correct perl DBI

driver installed? This is a simple, one liner, which will tell you a list of all the perl DBI drivers.

Run from the command line

perl -e ‘use DBI;@driver_names = DBI->available_drivers; print “@driver_names\n”;’

You should get output like

DBM ExampleP File Proxy SQLite2 Sponge mysql

enjoy

, , ,

No Comments

LCOD – 5.6.07 – Recovering pictures from flash disks

Ever have a corrupted flash memory card? Plug it into Linux and you’ll see tons of FAT corrupt or unreadable errors in dmesg output. Plug it into Windows and you’ll see a ton of files and folders with crazy corrupt names.

First thing you do, whenever you’re faced with any type of file recovery situation, is STOP USING THE DISK! Do not write ANYTHING to the disk.

Then, install PhotoRec (In Ubuntu 7.0.4 I ran, apt-get install testdisk).

http://www.cgsecurity.org/wiki/PhotoRec

I won’t attempt to write better PhotoRec instructions than you’ll find here

http://www.pcstats.com/articleview.cfm?articleid=1869&page=6

I used this recently on 2 8GB cards each with about 600 pictures in Canon RAW format, and it seems to have recovered all of them, except 1 which seems to be corrupt. Compared to the 160 or so that showed up in Windows, this is really a life saver.

, , , , ,

No Comments

LCOD – 3.19.07 – finding shared folders in vmware

Not sure where to find files in your Linux vmware host when you’ve shared them as a vmware shared folder?

“In a Linux virtual machine, shared folders appear under /mnt/hgfs. So the shared folder in this example would appear as /mnt/hgfs/Test files.”

So if you share it as drive I it will show up as /mnt/hgfs/drive I
Which you would need to access with a \ to escape out that space in the path…

cd /mnt/hgfs/drive\ I

I finally found this info here, after searching all over…

http://www.vmware.com/support/ws45/doc/running_sharefold_ws.html

, ,

No Comments

LCOD – 3.12.07 – Speeding up your DNS queries

I did some testing and OpenDNS is fast.

To change to use OpenDNS instead of your own, or worse! your ISP’s crappy, poorly maintained dns server, you can follow the instructions here.

http://opendns.com/start/

The basic info is to put in these 2 IP’s as your dns servers

208.67.222.222
208.67.220.220

On Linux/*BSD you’d put them in your /etc/resolv.conf file like this

nameserver 208.67.222.222
nameserver 208.67.220.220

If you’d like to double whammy your performance run a local cache, I use DJB’s djbdns dnscache in forwarding only mode, as described here.

http://cr.yp.to/djbdns/run-cache-x-home.html

With the above IP’s in the @ file.

Installing DJB’s stuff is cake, you can pretty much cut & paste his instructions found here

http://cr.yp.to/djbdns/install.html

Of course you’ll need Daemontools, and ucspi, install instructions (cut & pasteable) here

http://cr.yp.to/daemontools/install.html
http://cr.yp.to/ucspi-tcp/install.html

If you get compilation errors cuz DJB hasn’t fixed a bug in his code and some systems (lots of recent Linux systems), run these commands.
(run after you’ve extracted the archive, and cd’d into it’s directory, and run for EACH install.) You may get a no such file for the src one on some, but he mixes software locations, so just run em both.

perl -pi -e ‘s/extern int errno\;/\#include <errno.h>/’ *
perl -pi -e ‘s/extern int errno\;/\#include <errno.h>/’ src/*

Enjoy!

, , , ,

No Comments

LCOD – 2.18.07 – Simple command line perl substitutions

Ever have a list of things that you want to change all the same? Say you have an image directory and you want to make an html list of all the images in your directory? Perl to the rescue!

first, make a file that lists all the images (we’re using *jpg, but you could do *gif, or *coolimages*, or just * for all files in the dir – note: all files in dir * with a redirect will catch the file you are redirecting to, and it will likely need to be removed)

From the shell / command line, run:

/bin/ls *jpg > ourfiles

Now the fun part! This will take a line like this

picture1.jpg

And make it look like this
<a href=”picture1.jpg”><img src=”picture1.jpg” border=”0″></a>

From the shell run / command line, run:

perl -pi -e ‘s/^(.*)$/<a href=\”$1\”><img src=\”picture1.jpg\” border=\”0\”><\/a>/’ ourfiles

The basic pattern of this command is

‘s/SEARCH PATTERN REGEX/REPLACEMENT PATTERN/’

The search pattern is a Regular Expression, and the Replacement Pattern needs to have any special characters escaped (including / $ # @ “) with a \

The Search Pattern we’re using is a simple one ^ for start of line, (.*) for . anything and * any number of times, with paranthesis around it to put it into the perl variable $1, and $ for end of line.

, , , , ,

No Comments

LCOD – 2.5.07 – Debian package management

This is all over the web, but for some inane reason I can never find it when I need it.

List all packages installed in a Debian system, piped to more for readability

dpkg -l | more

(dpkg dash lower case L pipe more)

Seach installed packages for ones containing the word foobar

dpkg -P /*foobar/*

This info from this site
http://electron.mit.edu/~gsteele/debian/

, , , , ,

No Comments

LCOD – 9/13/06 – Howto import PRIVATE KEYS Java Keystore

Yes folks, now you too can enjoy the wonder of importing private keys into Java keystores.

There are actually several ways this can be done, none of which are by using the Java keytool program that absolutely should support this natively, and it’s laughable that Sun hasn’t made it able to.

Google for other ways, I’m going to tell you how I just did it for tomcat using IBM’s KeyMan.


First, get IBM’s KeyMan

http://www.alphaworks.ibm.com/tech/keyman

To import your key and cert you’ll need to convert them to something like DER format, with openssl commands like this:

openssl pkcs8 -topk8 -nocrypt -in ORIGINALKEY.PEM -inform PEM -out NEWKEY.DER -outform DER
openssl x509 -in ORIGNALCERT.PEM -inform PEM -out NEWCERT.DER -outform DER

Then just make a blank keystore with something like this:
~/sivox/ssl/java/bin/keytool -genkey -alias dummy -keyalg RSA -keystore keystore


Then run the KeyMan binary and when it pops up the error about bad resource, click the back button, browse for your keystore, and open it.

Then click File->Import and import your key and then your cert
You may want to rename them to tomcat if you’re using this for tomcat.. To do that double click on the cert, click the little wrench thing, and just type a new name.

You can delete the original dummy key, just be careful, KeyMan isn’t like most applications, for some reason it keeps items clicked until they are manually unclicked.

, , , ,

No Comments

LCOD – 12.6.05 – finding what programs are on what ports

So, you’ve run netstat -an and found something listening on a port you’re not sure what it is?

Not to worry, you can always run this command to find out;
Substitue $PORT with your actual port.

lsof -i | grep $PORT

So, say you’d run
netstat -an | grep LIST |grep tcp
and found this process
tcp 0 0 0.0.0.0:32803 0.0.0.0:* LISTEN
Not sure what 32803 was you checked /etc/services
grep 32803 /etc/services
and got nothing!

So, now you run
lsof -i | grep 32803
and you see

skype 18160 mdxdoug 22u IPv4 101807497 TCP *:32803 (LISTEN)
skype 18160 mdxdoug 23u IPv4 101807498 UDP *:32803

So it’s SKYPE! and not backdoor.pl or something. Good to know.

Enjoy!

NOTE:
If you’re using this to find a service that IS in /etc/services, you should grep for the service by name instead of port.

grep 143 /etc/services

imap 143/tcp imap2 imap4 #Interim Mail Access Protocol v2

lsof -L | grep imap

, , , ,

No Comments