Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, August 22, 2012

Don't Forget, Bugs Can Be Environment-specific Too

Fun With Play Framework

I recently heard a lot of great stuff about the Play Framework so I decided to download it and play with it. The tutorial seemed rather simple, I figured I would just breeze through it. Nope. Not at all.

Running play on its own worked normally as it should; creating a new application via play new worked as it should. Running play in the app directory is where it failed.

error: error while loading , error in opening zip file [error] scala.tools.nsc.MissingRequirementError: object scala not found. [error] Use 'last' for the full log. Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

Interesting. I dug deeper and thought it was due to Play's bundled version of sbt. So, I installed a version of sbt. I tried a "hello world" test with it and got the same error. Aha! So it must be a bug with sbt. No, not really. I google'd and stumbled upon Howard Guo's blog and read that he too was running openSUSE. Ah, now that's where it all hit me! I loaded Play on my old Ubuntu box and bingo all is well! Sheesh.

The Bugzilla entry says this bug probably won't be fixed since it's in openjdk 1.6.0, but luckily the fix is easy enough!
That's quite unfortunate - please type
chmod 0644
/usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/lib/ext/gnome-java-bridge.jar
as a root as a workaround. I doubt we will release any new maintenance update
of openjdk6 in the future.

Tuesday, August 2, 2011

ffmpeg: Creating A Single Image Video With Audio via CLI

Here's a nice quickie for you command line junkies. So say you wanted to share an audio file, but for sites like Facebook or Google+ you only have an option to upload a video. Okay sure, just create a video with the audio embedded.

My friend left me a hilarious voicemail a while back that I wanted to share with friends. I also wanted to set an image to constantly display just for viewing pleasure. So, bake the image to loop add in the mp3 voicemail and voila!


ffmpeg -loop_input -i Downloads/P1010155.png -i Downloads/30ad00fa24c1dcdf7479271f290c82252216718a.mp3 -shortest tmp/output.mp4

Thursday, August 27, 2009

Quick Bash One-Liner

Well, I'm here trying to wrap up things for the day and just found a very useful technique to get a directory without the filename from the listing if using find.

So, I'm sure you were all thinking, "well why don't you just use `find` with `-type d`?" Well, for this specific task I will be using `find` to get a list of all files and then I need whatever that directory is for another script. So booyah, in your face! (hehe jk)

So, apparently if I have a directory structure string with a file at the end of it I can drop the end part like so:

f1=/mnt/www/tmpdrin/dir1/dir2/fileindir.txt
f2=${f1%/*};
## $f2 will now be /mnt/www/tmpdrin/dir1/dir2


Sweet as!


And if you were curious how I was using it as a one-liner, here ya go:

for f in `find /mnt/www/tmpdrin/ -type f`; do f2=`echo "$f" | sed -e 's!/mnt/!!g'`; f3=${f2%/*}; echo "$f3"; done


Obviously, I'm doing a lot more here than just echoing, but this is just an example mmmkay? ;)

Cheers!

Post Script: It's been a while for posts, but I've just been working on proprietary stuff lately and nothing would be too useful for ya'll. Sorry!

Tuesday, February 17, 2009

Don't Panic Filesystem, It'll Be Okay

"Ouch! My G1 isn't reading my microsd card! Nooooo! I need to listen to something on the train! Oh wait, let me just use iMeem for now."

That's not a good way to start off the first day back from a long weekend. But unfortunately, that's how I started it off. So now, as I'm finally having time to sit down and troubleshoot why my microsd card was not reading, I can tell you all about how I fixed it!

So, I plug in my G1 to my laptop here at work. Here's my dmesg output:

acruz@acruz:~$ dmesg | tail
[28938.531732] sd 6:0:0:0: [sdc] Attached SCSI removable disk
[28938.531824] sd 6:0:0:0: Attached scsi generic sg3 type 0
[28938.969366] FAT: Filesystem panic (dev sdc1)
[28938.969387] fat_get_cluster: invalid cluster chain (i_pos 0)
[28938.969392] File system has been set read-only
[28941.483468] FAT: Filesystem panic (dev sdc1)
[28941.483493] fat_get_cluster: invalid cluster chain (i_pos 0)
[29038.322352] FAT: Filesystem panic (dev sdc1)
[29038.322365] fat_get_cluster: invalid cluster chain (i_pos 0)
[29038.322372] File system has been set read-only


Whoa...a panic is never any good in linux. Hmmm...all of my data is intact. Okay, no problem then. All I need to run is a quick fsck.vfat -a.


acruz@acruz:~$ sudo fsck.vfat -a /dev/sdc1
dosfsck 2.11, 12 Mar 2005, FAT32, LFN
FATs differ but appear to be intact. Using first FAT.
/albumthumbs
Contains a free cluster (4). Assuming EOF.
/music/P/mp3/Pimsleur01.mp3
Contains a free cluster (43543). Assuming EOF.
Reclaimed 1552 unused clusters (50855936 bytes) in 17 chains.
Performing changes.
/dev/sdc1: 1105 files, 127709/244416 clusters


Well, seems like I had a few files that were probably corrupted when I transferred them last. Sheesh! Well, at least now fsck fixed it! Now, all I needed to do was umount/mount and then all looked better again!

Here's the healthy dmesg output:

acruz@acruz:~$ dmesg | tail
[30213.598301] sd 7:0:0:0: Attached scsi generic sg3 type 0
[30222.667142] sd 7:0:0:0: [sdc] 15659008 512-byte hardware sectors (8017 MB)
[30222.669098] sd 7:0:0:0: [sdc] Write Protect is off
[30222.669107] sd 7:0:0:0: [sdc] Mode Sense: 03 00 00 00
[30222.669112] sd 7:0:0:0: [sdc] Assuming drive cache: write through
[30222.673118] sd 7:0:0:0: [sdc] 15659008 512-byte hardware sectors (8017 MB)
[30222.675136] sd 7:0:0:0: [sdc] Write Protect is off
[30222.675147] sd 7:0:0:0: [sdc] Mode Sense: 03 00 00 00
[30222.675151] sd 7:0:0:0: [sdc] Assuming drive cache: write through
[30222.675164] sdc: sdc1


That looks much better! w00t!

Cheers!

Android Phone 2: HTC Magic

Finally, a second Android-based phone! You can read (and view photos!) CNet UK's first look at the phone here.

Well, right now I'm just curious if the battery life is better than the HTC Dream (G1). Other than that, well I could care less for a touchscreen-only phone. (One of the main reasons I didn't get an iPhone.) Other than that, the HTC Magic looks pretty slick and seems to be a nice addition to the Android family.

Cheers!

Monday, February 16, 2009

Rename Multiple Files With Perl

So here's the problem: I have a directory full of files that have special characters. In this particular case they were spaces and pounds. So of course, for some reason I can't find a working way to do a quick bash script. I was trying to do a for x in `ls` ; do ... but because of the special characters my filenames weren't being read properly. Wonderful!

So, after maybe a good 20 minutes of trying to find the right shell commands to use, I gave up and wrote this quick perl script.

So...anybody wanna give me a hint on how I'd be able to do this in a shell script?


#!/bin/perl
#
$dir="/home/drin/tmp/";
opendir(DIR, $dir) || die "Couldn't open $dir";
@files = grep {/.doc/ && -f "$dir/$_"} readdir(DIR);
closedir(DIR);

for $x (@files) {
$y = $x;
$y =~ s/\#//g;
$y =~ s/\ /_/g;
print "Renaming $x to $y\n";
rename ($x, $y);
}


Cheers!

Friday, February 13, 2009

Happy 1234567890 Epoch Time (EST)


"Wait for it... wait for it... come on... getting close... aha! There we go!"

Yay, we had an "epoch" of a time here on the east coast. hehehe

Cheers!

Tuesday, February 3, 2009

Helix3 2008R1

So, I recently was asked to get data off of a laptop for a friend. I took the laptop home with me and noticed that I left my old Helix CD at my parents' house. "Not a big deal, I can just download the latest iso!"

So first thing I noticed was the use of Gnome, but wait, look further, it's actually Ubuntu! Cool! But wait, I just want to recover some data and I don't need Gnome to be running, it costs too much overhead! Bah!

I was not even able to append a boot parameter to boot in console-only mode (or at least I wasn't able to find one). Fine, I got the files off anyway!

I also noticed an "install" option. That's cool! Maybe I'll be more curious and even test it out.

Cheers!

UPDATE
Ok, silly me! To go about booting into console-only mode the answer was really just in my face! If you hit F6 at the Helix menu, you can edit the boot parameters. Just delete splash and that's it! Though, Gnome still loads so you'll just have to do a Ctrl+Alt+[F1-F6] to get to one of those console screens.

Thursday, January 29, 2009

Winmail.dat Attachments For Linux Thunderbird

This is only going to be a rant and a link to Andrew Beacock's blog post solving that pesky winmail.dat attachment issue for linux users.

I never had this issue until this morning when a project manager sent over an email with an attachment.

Sheesh Microsoft, can we stop making the proprietary apps please!?

Wednesday, January 14, 2009

Hello, Android SDK


So in an attempt to stay on budget and yet keep myself entertained through this recession, I finally set up my Android SDK on one of my computers. I also finished up my first app! Ok, ok, so it's the generic "hello world" app that all newbies start off with, but hey I still haven't decided what I'd like to build. It's always just fun to tinker around a system anyway.
Let the fun begin!

Cheers!

Tuesday, January 13, 2009

Where's My Ubuntu Screensaver Admin?!

I think this will probably be more of a reminder for me, but in case anyone else has this curious issue with Ubuntu Gutsy Gibbon, then read on!

For whatever reason, I do not have "Screensaver" listed under System>Preferences. I'm using XScreenSaver since gnome-screensaver seemed to just freeze after any amount of time. Anyhow, if you need to configure your settings for XScreenSaver all you need to do is type in xscreensaver-demo in a shell. Tada!

Sheesh, I had to google that every time and then follow it up with a "doh!" once I read what to do!

Cheers!

Tuesday, January 6, 2009

It's 2009 and I Am Back!

Well, it has been over two months since my last post. I have been unfortunately out of ideas on what to blog about. So, perhaps I will slowly stray away from my usual format of blogging about technical recipes and code to bantering on about anything random. Hmmm...we'll see.

Anyhow, happy 2009! I was given an awesome present of a [t-mobile] G1. Yay! I've only had it for a little bit over a week now, but it is awesome. I've managed to get root thus far; but stay tuned for more updates.

Friday, October 24, 2008

Using a Script to Edit a conf File

Well, because I have been uber busy here at work, I haven't been able to write any blog posts. But, since I've been super productive at work, I get to write up a few posts about some more tools I've written to add to my arsenal. w00t!

So my latest task involved editing some of our web server's Apache confs. It consisted of adding a new alias so that we can call in some new app someone else wrote. Okay cool. Alias? Sure not a problem. Er...wait! The alias requires the site's directory name as part of the path! Oh no! That means I can't create one global alias!

Ah, see that's when I thought of writing this script that will look for a specific line in the vhost entries and will enter the new line after it. Pretty nifty eh? :)

So basically, what we have here is a list of all sites in a text file. Now we can use the site's directory name read in as a variable. It will then use awk to search for a specific line, and then print the new line you need right below it!

So if you take a look at the code, I want to add this line:
"Alias /newalias /mnt/www/$site" (where $site is the site directory name variable)
right after each line that fits the regex that searches for any line that has "Alias" and "reports" in one line followed by the site dir name at the end of the line. Obviously if you want to utilize this script you should edit the regex to your needs.

And that's it! Now think of all of the time saved rather than adding a new line manually to EACH vhost entry on EACH server! whoa....scary...


#!/bin/bash

exec < sites.txt
while read site ; do
echo "processing $site..."
awk '{print $0} '"/Alias.+reports.+\/$site"$/'{print " Alias /newalias /mnt/www/'"$site"'"}' httpd.conf > newhttpd.conf && mv newhttpd.conf httpd.conf
echo "done!"
done

Thursday, October 2, 2008

Shell Scripting to Read Data From a File

Okay, so here's your problem: you have a file that contains data that you'd like to parse through a script. It's a lot of data and you don't want to sit there and continuously do the same thing over and over!

The data can be set up as one long column of data or multiple columns of data. In this case for simplicity I'll only use one column of data.

So let's say your data file is as follows:

dog
cat
cow
...
...
(long list of data)


These represent parts of filenames that you need to clear out. You don't want to sit there typing cat /dev/null > dog
cat /dev/null > cat
...
So you come up with a master plan to script the process. The script will be short, sweet, and absolutely time saving!

You first need to read in the file; so this line does the work for you: exec < files.txt. Obviously, in this example my "files.txt" is the filename that contains the data I want to read. After you've opened up the file for reading, you can now parse through the file with a while loop:
while read file ; do
[do some work here]
done


Now note, "file" is the variable that we're assigning to the column. You can call the variable whatever you want. Also remember that I am being simple with this example and only have one column of data. If I wanted to do multiple columns of data, I would just assign more variables to each column. e.g. while read col01 col02 col03 ; do where $col01, $col02, and $col03 will be my new variables.

That's it! I'll leave the customization to you. Cheers!

Here is the full script example:
#!/usr/bin/bash

exec < files.txt

while read file ; do
if [ -s /mnt/$file ] ; then
cat /dev/null > /mnt/www/vdir/z/ec/$file
else
echo "/mnt/$file already empty!"
fi
done

Friday, September 26, 2008

xargs Is a Very Useful Tool

I was recently asked how to remove specific files of a specific extension (.tmp in this case). Well, of course you can find them by doing a find . -type f -name "*.tmp". Easy eh? But how to delete them if they span deep into the directory tree? Well, I suppose you can just append the output of your find command into a text file and then have a script do the rm'ing of the files. But, what if you can do all of that work in one command line?

So, I mentioned xargs and mentioned what it can do and gave a brief example and lo and behold, he saved a good 5 minutes of extra work. Awesome!

Now, to exemplify what I just said:
find . -type f -name "*.tmp" | xargs rm

Just think of all the possibilities now that you have all of this functionality! You can cp, tar, mv, etc. etc.

Enjoy! Cheers!