Posts Tagged Linux Command of the Day
LCOD – 6.6.07 – Simple SSH remote command execution
Posted by Jon Zobrist in Linux, Linux Command of the Day on June 6, 2007
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.
LCOD – 5.9.07 – Updating CPAN in Perl
Posted by Jon Zobrist in Linux, Linux Command of the Day, Perl, Programming on May 9, 2007
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)
LCOD – 5.9.07 – Find out what Perl DBI drivers are installed
Posted by Jon Zobrist in Linux, Linux Command of the Day, MySQL Server Support on May 9, 2007
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
LCOD – 5.6.07 – Recovering pictures from flash disks
Posted by Jon Zobrist in Linux, Linux Command of the Day on May 6, 2007
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.
LCOD – 3.19.07 – finding shared folders in vmware
Posted by Jon Zobrist in Linux, Linux Command of the Day on March 19, 2007
“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
LCOD – 3.12.07 – Speeding up your DNS queries
Posted by Jon Zobrist in Linux, Linux Command of the Day on March 12, 2007
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!
LCOD – 2.18.07 – Simple command line perl substitutions
Posted by Jon Zobrist in Linux, Linux Command of the Day, Perl, Programming on February 18, 2007
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.
LCOD – 2.5.07 – Debian package management
Posted by Jon Zobrist in Linux, Linux Command of the Day on February 5, 2007
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/
LCOD – 9/13/06 – Howto import PRIVATE KEYS Java Keystore
Posted by Jon Zobrist in Linux, Linux Command of the Day on September 13, 2006
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.
LCOD – 12.6.05 – finding what programs are on what ports
Posted by Jon Zobrist in Linux, Linux Command of the Day on December 6, 2005
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