Posted by: Joey on: April 12, 2007
Here’s a small bash script that will allow you to unzip a directory full of zip files. Each file will be unzipped into a directory named for itself (e.g. the contents of foo.zip will be extracted to a directory called foo). To run the script, enter the directory where the zip files are stored and create a file with the following contents:
#!/bin/sh for i in *.zip do mkdir `basename $i .zip` unzip $i -d `basename $i .zip` done
You can name the file whatever you wish. I’ll use unzip_script as an example. We then need to make the file executable. You can do this with the following command:
chmod 755 unzip_script
And now we can run the file with the following command:
./unzip_script
You should now have a directory for each zip file full of it’s contents. You can also modify the script to suit your needs. The following script will delete the zip files once they are extracted:
#!/bin/sh for i in *.zip do mkdir `basename $i .zip` unzip $i -d `basename $i .zip` rm $i done
And here’s another version that moves the zip files to another directory once they are extracted:
#!/bin/sh mkdir zip_files for i in *.zip do mkdir `basename $i .zip` unzip $i -d `basename $i .zip` mv $i zip_files done
Be sure to make a backup copy of the data to be extracted. These scripts were tested, but I can’t anticipate every possibility. Always take precautions to preserve your data.
Posted by: Joey on: December 19, 2006
I’m sure by now all you Firefox aficionados have heard of a little addon extension called Greasemonkey. I’ve also seen some frustration associated with the installation and use of Greasemonkey. Since I also shared this frustration, I decided to put together this little tutorial. Leave feedback in the comments section.
We’re assuming you have a functioning copy of Firefox 1.5 or better. If not go download it here. Next you will need to install the Greasemonkey extension. Restart Firefox to complete the installation. In Firefox 2.0 there should be a button in the installation dialog box that will automagically restart Firefox and restore your session as if Firefox had never been closed. Once installed properly there will be a small Greasemonkey icon in your status bar and there will also be a menu option under the Tools menu.
Pretty neat and simple so far! However, I have a sneaking suspicion most of you have made it this far already.
Once installed properly there is still one more important piece of setup to do. You have to set the text editor. There are a couple of ways to do this.
The nerdy way to set the text editor is to open a new tab and navigate to your about:config page. In the about:config page there will be an entry called greasemonkey.editor. Right click on this entry and select Modify. Enter the path to your favorite text editor here. In Ubuntu Linux this path is /usr/bin/gedit and for Windows losers… I mean users, the path is c:\windows\notepad.exe or whatever the path is to your favorite text editor.
The mouse clicky way to do this only works if you’ve never set the text editor before (either intentionally or unintentionally). On your freshly installed Greasemonkey, right click on the status bar icon or click on Tools > Greasemonkey > New User Script. This will open a dialog box that will allow you to select your text editor.
Note: New User Script is for WRITING scripts, NOT installing them. Unless you write your own Greasemonkey scripts, you’ll probably never click on New User Script again. If you’ve previously tried to install a .js file using New User Script, it has set that .js file as your default editor. You’ll have to use the nerdy text editor setting method mentioned above to correct this. Once you have a properly configured text editor option, clicking on New User Script will simply open the text editor. Personally I think they should rename that option Script Editor or Text Editor to avoid a lot of confusion.
Installing of scripts in Greasemonkey is easy, but non-intuitive. First, remember that all Greasemonkey script filenames must end in user.js and typically they are named <script-function>.user.js. You have to surf to the script to install it. Once you do that, Greasemonkey will go ahead and install it automatically. If a file is stored on your local computer, go to File > Open File… to select and open the file. Again, Greasemonkey will automatically install the script once you’ve done this. Surf to http://userscripts.org/ to find a comprehensive and searchable list of millions of scripts.
Once you have scripts installed, you be able to enable, disable, uninstall, and edit them from the Manage User Scripts dialog. To get to the Manage User Scripts dialog, right click on the Greasemonkey icon in the status bar and select Manage User Scripts…, or go to Tools > Greasemonkey > Manage User Scripts…. Once inside you can turn the scripts on and off and uninstall or edit them. You can also select an include or exlcude list for each script. To make the script apply to all websites, click on the script in the left hand column and put a * in the includes list. To make a script only work for one website, for example Google, select the script in the left hand column and put http://google.com/* in the includes list. Use the same method for the excludes list if you don’t want the script to run on certain web pages.
I hope that this little tutorial helps some of you out. Greasemonkey is a neat feature and sometimes and invaluable tool. Let me know if you have any suggestions for this tutorial. Have a lot of fun!
Posted by: Joey on: December 13, 2006
Here is an Ubuntu 6.10 Samba setup guide blatantly ripped from this blog. If you have more than one computer and a mixture of Linux and Windows, Samba is essential for sharing files and printers. Enjoy!
sudo apt-get install samba smbfs
System > Administration > Users and Groups > Add User
Enter the username as samba
Enter the password
In the "User Priviliges" tab, deselect all.
In the "Advanced" tab, choose "/bin/false" as shell, and "users" as the Main Group.
sudo smbpasswd -a samba
Enter the password desire
*This is the username and password that will be require when you are connecting to your ubuntu guest through windows box.
gksudo gedit /etc/samba/smbusers
Enter this in the file
samba = "network username"
Save the file and exit gedit
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.default
gksudo gedit /etc/samba/smb.conf
# Change this to the workgroup/NT-domain name your Samba server will part of
workgroup = YOUR_WORKGROUP_NAME
; security = user
Change into
security = user
username map = /etc/samba/smbusers
System > Administration > Shared Folders
Enter information for your desired shared
sudo testparm
sudo /etc/init.d/samba restartThat’s it!
Posted by: Joey on: November 20, 2006
I recently upgraded to Ubuntu 6.10, Edgy Eft. Overall, the differences were minor, but there were a few things that have caused me some major grief. There were also a couple of nice additions. Here’s my view.
Overall, I could probably have done without this upgrade. The issues with Flash have really hurt usability since so many sites these days rely on it. As you can see from this list, my cons outweigh the pros 2 to 1. I find myself needing to use my Windows laptop more often than I did before the upgrade and I don’t care for that. If you have some insights on the problems I listed or want to share your opinion, leave a comment.
Posted by: Joey on: August 30, 2006
Here is a little bash script I wrote that takes your Firefox bookmarks and uploads them to your web space.
For this project you will be using the bash shell and various command line operations. And of course you will need Firefox! Bash is usually the default Linux shell. This will probably work with other shells besides bash with little or no modification.
Buyer beware! Whenever you create a script or use one from another source, always test it in a non-production environment to insure it will do no harm. Create some test files on which to run the script and break up complex commands so that you can test each part individually. When you feel confident that you are ready to implement the script, backup all data beforehand. And if you insist on running things as root or sudo, check out this horrid tale.
The first thing to do is to find your bookmarks.html file. This is usually stored in your home directory structure. On my Ubuntu system it is stored at
/home/username/.mozilla/firefox/xxxxxxxx.default/bookmarks.html
where xxxxxxxx is a random set of letters and numbers that is different for each user.
Our next task is to create some directories. I like to store my scripts in /home/username/scripts, but you can store them where ever you wish. For this script we need to create two directories, backups and logs. You can create these directories anywhere you wish, but I created mine like so.
mkdir /home/username/logs mkdir /home/username/.mozilla/firefox/xxxxxxxx.default/backups
Now we are ready to create the script.
1 #!/bin/sh
2 #move to bookmark directory
3 cd /home/username/.mozilla/firefox/xxxxxxxx.default/
4 #create backup file just in case, backups directory must already exist
5 cp bookmarks.html backups/bookmarks.`date +%m-%d-%y_%H%M`.html
6 #append date to bottom of file
7 echo "`date`" >> bookmarks.html
8 #up the results
9 ftp -in <<EOF
10 open yoursite.com
11 user username password
12 bin
13 cd public_html
14 cd files
15 put bookmarks.html
16 bye
17 EOF
18 #remove date line from end of file
19 echo "`sed '$d' bookmarks.html`" > bookmarks.html
20 #remove old backup files
21 find backups -type f -mtime +8 -exec rm {} ;
22 #move to log file directory
23 cd /home/username/logs/
24 #create log file
25 echo "Your bookmarks were last updated on `date`" > bookmark_backup.log
I’ve commented the file, but I’ll go through the script line by line and talk about what is going on. Bash comments start with the # symbol. I recommend that you comment every script or document you write. Comments not only help other people who are looking at your work, they also help you. Sometimes what seems so clear now, may not seem clear three years down the road. I have also added line numbers for clarity of discussion and will include a non-numbered copy at the bottom of this post.
You should now be able to access the results by going to http://yoursite.com/files/bookmarks.html (or where ever you put it).
For true scripty goodness, create a cron job that automagically runs this script. I run mine twice a day at 9:53 and 21:53. Here is my crontab -l for your reference.
53 9,21 * * * sh /home/username/scripts/bookmark_backup.script
Now as promised, the script with no numbers.
#!/bin/sh
#move to bookmark directory
cd /home/username/.mozilla/firefox/xxxxxxxx.default/
#create backup file just in case, backups directory must already exist
cp bookmarks.html backups/bookmarks.`date +%m-%d-%y_%H%M`.html
#append date to bottom of file
echo "`date`" >> bookmarks.html
#up the results
ftp -in <<EOF
open yoursite.com
user username password
bin
cd public_html
cd files
put bookmarks.html
bye
EOF
#remove date line from end of file
echo "`sed '$d' bookmarks.html`" > bookmarks.html
#remove old backup files
find backups -type f -mtime +8 -exec rm {} ;
#move to log file directory
cd /home/username/logs/
#create log file
echo "Your bookmarks were last updated on `date`" > bookmark_backup.log
Posted by: Joey on: August 30, 2006
It seems that several people have had trouble creating cron jobs in Ubuntu. Here is a method I found that works for me. It requires sudo access.
The only thing you’ll need is cron and a good text editor (like nano), both of which are in the default Ubuntu install.
Create a file with your job(s) in it and save it with any filename (e.g. crontab_file). Put each job on it’s own line like so:
* * * * * sh /home/userbob/script1 * * * * * sh /home/userbob/script2
Next run crontab with sudo on the file you just created. Be sure to select your username with the -u option:
sudo crontab -u userbob crontab_file
And that’s it. Pretty simple, huh? I hope this helps you out. Check out the crontab page at Wikipedia for help with formatting your own cron jobs.
Just to clarify, you need to check out the proper notation for crontab to determine how to write your own cron jobs and make them run when you want them to.
Another clarification. You must create a file with each cron job on a separate line and then run crontab on it to make it work. You should do this as a user using the sudo command. Don’t be running scripts as root. Don’t be doing work as root. Don’t do anything as root unless you have no other choice. Just forget that root even exists. Your life will be better.
Posted by: Joey on: August 30, 2006
Hello truth seekers! Here is my definitive guide to converting DVD audio to ogg encoded audio files in Ubuntu Linux. This method was used in Dapper and Breezy.
I used a combination of acidrip, ffmpeg, and oggenc to do the ripping. All are available through apt.
sudo aptitude install acidrip sudo aptitude install ffmpeg sudo aptitude install vorbis-tools
First I extracted each chapter to an avi file using Acidrip. On the Video tab I set the Codec to “copy”. On the General tab I set the audio codec to “pcm” and the gain to 18 (this can be any number, experiment to see what works for you). Then I used the preview tab to check the audio levels. Then I queued up all the chapters and started ripping.
Once the avi files were made I used the following ffmpeg command to extract the audio to a wav file.
ffmpeg -i filename.avi filename.wav
You can create a bash script to do this for you, but don’t bother because I’ve already done it.
#!/bin/sh for i in *.avi do ffmpeg -i $i `basename $i .avi`.wav done
Once I had done this, I used oggenc to make ogg files.
oggenc -q6 filename.wav -o filename.ogg
The -q6 option sets the ogg quality to 6. Most people use 4 or 5 which are a little more lossy. I prefer a setting of 6 to give me a higher quality with a file size that is still reasonable. Here is another bash script that takes care of this step for you.
#!/bin/sh for i in *.wav do oggenc -q6 $i -o `basename $i .wav`.ogg done
Now you have ogg files created from you DVD that you can edit or listen to on your ogg player. This method can also be used to create mp3 files using lame.
Posted by: Joey on: February 3, 2006
Now I remember why Linux can be a bit frustrating at times. I tried using Ubuntu, Kubuntu, and Opensuse today. Ubuntu and Kubuntu work well right from the get go. Opensuse had a few problems.
Pros
Cons
Ubuntu is a relatively new distro based on Debian and financed by some rich dude from Africa. The objective of Ubuntu is to provide a simple, free, and easy-to-use operating system for all the peoples of the world. I installed the i386 version 5.10 from a CD. Installation was very easy and took less than 15 minutes. Everything was automagically detected and installed. There was no package selection although you can do a base “server” install at boot time. Ubuntu does not create a root account. Instead it creates an “admin” account which is also the default user account. It also defaults to the Gnome desktop although KDE can be installed after the initial system installation. It comes with a limited selection of packages, with usually just one tool to do a job. The default web browser is Firefox 1.0.7. I was a bit disappointed that Firefox 1.5 was not included and that there are currently no 1.5 packages available. Firefox can still be downloaded from the Mozilla website and installed manually. The default mail client was Evolution, but since I use Gmail, I did not evaluate it. Package management seemed to be fairly easy although I am faily ignorant of the process. The default package manager seemed to work well and had a simple, intuitive interface. A nifty auto-update feature is also included in the OS.
Pros
Cons
Kubuntu is an offshoot of Ubuntu that installs the KDE desktop by default. It is not a fork of Ubuntu and is an actively developed part of the project. Gnome can be installed if needed after the initial system installation. Although Kubuntu is part of the Ubuntu project, it is easy to tell that it is not as well integrated as the original and has a smaller user base. Most of the packages are the same as in Ubuntu. Konquerer is installed as the default web browser and Firefox is not included. Version 1.0.7 can be installed via the package manager, or 1.5 can be manually installed. Kontact was the default email client, but once again I did not evaluate it because I use Gmail. The package manager was somewhat disappointing. To be honest the interface was so confusing, I never figured out how to use it. More work is needed on this from in Kubuntu.
Pros
Cons
Opensuse is the free community project for Suse Linux sponsered by Novell. Opensuse is a desktop Linux system, but can be configured to do almost anything. The heart of Opensuse is Novell’s YaST administration program. I installed the amd64 version 10.0 from 5 CDs. A net install is also available, but I could not get it to work. I selected all of the defaults including all of the default packages. I was disappointed to see that all 5 discs were necessary in the default install although most of the packages came off the first two discs. The install also hung while attempting to get updates. I had to shell out and kill the install. Luckily it was nearly complete and produced a bootable system, but no users were created and my sound card was not configured or even detected. When I rebooted the installation did not complete. I logged in as root and created a user account. On a happy note, my Windows partitions were auto-mounted at boot, although my Grub install was corrupted and would not boot to Windows. Once logged in as a user, the system seemed to work fairly well. Both Konquerer and Firefox were installed, although Firefox was only version 1.0.6. I also noticed some connectivity issues in Konquerer although I could not determine their cause. Email was not evaluated. Package management was handle by YaST. It seemed to work well and with a little learning effort might be easy to use. Auto-update is also available although it is turned off by default and I could not determine if it really worked.
It was clear to me that all three distros I evaluated worked and could be made to function for anyone willing to learn. Ubuntu seemed to be the most polished of the systems, and Opensuse seemed to be the most robust. Kubuntu seemed to need the most work from a usability standpoint although it was just as stable as Ubuntu. I think I will reinstall Ubuntu and evaluate it on a more detailed level. It seems to be the one that could most likely be used as a primary OS.