Create an archive without topdirs from your path

So the title might be misleading but picture this:

tar czvf lol.tgz /home/lol/omnom

When you run that, it will tar up that directory. It will also put leading directories up to the actual data in the directory you’ve specified.

So when you go to extract it to lets say /extract, you’ll get:

/home/extract/home/lol/omnom

Here is how to avoid that straight from one of my favorite sites: stackoverflow

tar -czvf lol.tgz -C /home/lol/omnom .

This tells tar to jump in that dir and then grab everything (including hidden files etc..) and throw that in the archive.

Schweet!@

Ohh and you want to untar to a specific directory that is not your current directory????

tar zxvf tarball.tar.gz -C destination_dir

Win.

Multi-line spacing in Bash

Multiple line spaces in your bash programming can come in handy. Here’s how straight from the awesome that is cyberciti!

#!/bin/bash
echo "Say Something"
<<COMMENT1
    your comment 1
    comment 2
    blah
COMMENT1
echo "Do something else"

passwd command problems with LDAP clients

So my users weren’t able to use the passwd command after I implemented LDAP auth on a specific client.

Here’s a quick fix to /etc/pam.d/common-password

password    [success=1 user_unknown=ignore default=die] pam_ldap.so use_authtok try_first_pass

Needs to become…..

password    [success=1 user_unknown=ignore default=die] pam_ldap.so try_first_pass

Basically, removing the useauthtok enables the tryfirstpass to successfully get processed (i believe, more) and therefore the passwd command can then properly check the first password you type unlike the error users got before:

$ passwd
Enter login(LDAP) password:
passwd: Authentication information cannot be recovered
passwd: password unchanged

The USB wake up problem

I recently moved into a house and have had to watch my power. So obviously standby mode is a big deal in these parts where college students pay the electric bill with the small amounts of nothing they seem to find themselves holding.

In linux, this is not hard to do at all especially since I have ubuntu 12.04 which seems to work great with my hardware.
However, I am not able to wake the computer back up with my wireless logitech keyboard or mouse!!

Google helped me out a bit:

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 041e:30dd Creative Technology, Ltd
Bus 005 Device 002: ID 046d:c525 Logitech, Inc. MX Revolution Cordless Mouse
Bus 005 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver <- THAT ONE
# nano /etc/udev/rules.d/90-keyboardwakeup.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"

Rebooted and wala!
I am able to push a single key on my keyboard to wake my machine from standby!

I know, right?

Thank you: http://ubuntuforums.org/showpost.php?p=11902254&postcount=5

A weird Scheme: sharing a server in a duplex housing unit

Challenge:

1 House (Duplex)
2 Sides
1 Hole in the Basement
2 Different Groups of College students
11 People wanting access
4 Network Ports
1 Server

So I live in a duplex and both sides of the house are friends with each other. We all need access to one central server to share certain files as well as stream content etc…

Here are some obstacles:
1) both have separate Charter internet connections
2) Both have their own router with a different network configured
3) There is no central DNS to serve both, just their router devices
4) Both have streaming boxes as well as need for individual download
5) The server must use the internet connection from its originating side
5) I’m hungry

So here is the solution:

I have 4 network ports on my server. Each streaming box on each side of the house would get one and the other would be used for normal data download via http/ftp/smb etc.. This will ensure consistent integrity of the connection when streaming (since we only have 100Mbps internally).
I will remove the default gateway added from the other side of the house as to ensure our internet connection is the only one used. As for DNS, ill explain that in a minute.

Here’s a outline of what i did:

a) I connected the server via two cables on our side of the house directly into our switch. I got an IP from our router (192.168.1.*) and statically set it in DHCP so it never changes. I logged which interface would be for serving the streaming media box and which would be for data moving from each user.

b) I then connected the other side of the house after running some cables through the basement (luckily there were holes) to their switch and again set static IP’s (192.168.0.*). At this point, the server had a default gateway set for both the 192.168.1. and 0. but the 0. had priority. This was unwanted. So a quick

route del default gw 192.168.0.1 dev eth2
route del default gw 192.168.0.1 dev eth1

took care of the issue. Note that there were four default gateways because of each connection to each router. Here, I removed the two to the other side of the house where the WAN connection is slower for obvious reasons.

c) Now for services. Here is a better breakdown of the IP’s so you can grasp how I’m doing this:

Our Side:
eth3 - 192.168.1.89 - nfs (streaming only) Boxee Box
eth4 - 192.168.1.253 - samba, http, ftp (download etc..)

Their Side:
eth2 - 192.168.0.108 - samba (streaming only) WDTV
eth1 - 192.168.0.104 - http,ftp (download etc...)

So first things first. Got NFS working and decided to just serve it out on 192.168.0.0/16 since it uses rpc and that uses tons of ports (tcp and udp). Since no one else except me even knows what nfs is, I decided it wouldn’t be an issue even though I could probably set interfaces to serve that out on as well.

For http, apache’s “Listen” configuration flag came in handy and I choose the interfaces I wanted it on.

For ftp, I used the “listen_address=xxx.xxx.xxx.xxx” flag in the vsftpd.conf which worked well. Except the fact that I can’t serve simultaneously on two interfaces with only one instance of vsftpd. No issue….since this is a simple anonymous connect, I just copied over my config to vsftpd2.conf, edited the listen address to the other ip address that needs access, and started another instance of the server in a screen session using that config file:

screen -S othervsftpd
vsftpd /etc/vsftpd2.conf
ctrl+a

Boom. Headshot!

For samba, all I needed to do was edit the smb.conf and add:

interfaces = eth2 eth4
bind interfaces only = yes
#for public anonymous access
security = share
#define public share
[pub]
comment = awesomeness
path = /pub
guest ok = yes
writable = no
browseable = yes
guest only = yes
public = yes

Obviously there are other global settings you would need to configure but with that, you would serve out your share successfully and serve on the necessary interfaces.

That’s all I needed to do for services. Quite nice actually.

d) DNS!!

So this required some thinking. I wanted people to be able to type in something short or a single word to get to the box but didn’t want to run a dns server.
Each router on both sides sets itself as the DNS provider when a client connects. With that in mind I went to work.

On our side:
Our router is an Asus rt-n66u which is a Beast. I enabled telnet, logged in, and set the /etc/hosts file with:

192.168.1.253 server

With that done, whenever someone on our side of the house types “server” for the hostname, it will resolve to the ip address I want them to use (non-streaming dedicated).
For the other side of the house I couldn’t do this because their router is..well cheaper. So I used a domain name I forgot I had and just set the ip to the internal ip I wanted them to use. I of course don’t plan to use this domain for anything else so it will work well. You could even use a subdomain for a domain you already own!

So I set the “hostname.com” to point to 192.168.0.104 in my dns settings at namecheap.com!!

=> The problem with using nmbd and not doing the weird stuff above???

Yes. I know. But nmbd only runs where I set samba to serve on those other interfaces remember? So that wouldn’t work very well. And even still, I would have to use “hostname.local” which is kinda lame because it would go to a random ip address being offered by the server and not any specific one I’d like users to go to.

I may be wrong about nmbd. It may be more flexible but I decided that this solution would work out great and since I’m a busy college student, I will leave it for the time being.


So far, so good. The boxee runs great on NFS and the WDTV in all its jenkyness is running pretty well on SMB. Everyone can access stuffs easily without auth and therefore, everyone seems to be happy.

As for the firewall, since I’ve specified the interfaces for my services to run on, I decided to do the following:

-A INPUT -s 192.168.0.0/16 -j ACCEPT

Boom. Done!

Sending email with exim4 from a gmail account

So I want my servers to email me when there’s problems or when I just need to feel like I matter and someone cares about emailing me.

Unfortunately, my university (MTU) blocks outgoing smtp on the default port (25) hence I need to use an external service like gmail to send email.

How do we do this?

1) setup a gmail account (or use a current one, whereever you want your emails to come from)

2) Tell exim4 (or sendmail, exim is already installed though and theres this nifty guide) to use gmail as a “smarthost”

3) use the “mail” command (or others) to send email to virtually anyone through the gmail account.

 

Here’s a little step by step on how to do this.

(In the following, “HOSTNAME” = whatever is in your /etc/hostname and “USER” = whatever user you want the email to appear from, usually root)

 

1) First lets reconfigure exim4 to our liking using dpkg

# dpkg-reconfigure exim4-config

Here’s the answers to the questions it asks:

  • Choose “mail sent by smarthost; received via SMTP or fetchmail”
  • Set to “localhost” for “System mail name:”.
  • Set to “127.0.0.1″ for “IP-addresses to listen on for incoming SMTP connections” to disable external connection.
  • Leave as empty for “Other destinations for which mail is accepted:”.
  • Leave as empty for “Machines to relay mail for:”.
  • Set to “smtp.gmail.com::587″ for “IP address or host name of the outgoing smarthost:”.
  • Choose “NO” for “Hide local mail name in outgoing mail?”.
  • Choose “NO” for “Keep number of DNS-queries minimal (Dial-on-Demand)?”.
  • Leave as empty for “”.
  • Choose “mbox format in /var/mail/” for “Delivery method for local mail”. (optional)
  • Choose “YES” for “Split configuration into small files?”. (optional)

2) Now lets configure the account details by opening /etc/exim4/passwd.client and adding the following:

*.google.com:accountname@gmail.com:password

where accountname is your gmail username and password is obviously the password.

3) Let’s setup the email addresses (/etc/email-addresses) to use for outgoing mail:

USER: accountname@gmail.com
USER@localhost: accountname@gmail.com
USER@HOSTNAME: accountname@gmail.com
USER@HOSTNAME.localdomain: accountname@gmail.com

4) Finally, lets finish up and tell exim4 what is going on:

# update-exim4.conf
# invoke-rc.d exim4 restart
# exim4 -qff

Ding. Setup is Done. You should now be able to do something like this:

mail -s "SUBJECT OF EMAIL" persontoemail@gmail.com < email.message

OR

cat email.message | mail -s "SUBJECT OF EMAIL" persontoemail@gmail.com

where email.message is a text file with the body of the email you are sending

 

To send a message written in html:

cat email.message | mail -a "MIME-Version: 1.0" -a "Content-Type: text/html" -s "SUBJECT OF EMAIL" persontoemail@gmail.com

Obviously make sure your message uses html formatting (like your writing a web site)…

Most of the instructions here are from the great guide at the debian wiki: http://wiki.debian.org/GmailAndExim4

UPDATE – Just found another interesting program called ssmtp which supports gmail and other services…check it out here: http://www.howtogeek.com/51819/how-to-setup-email-alerts-on-linux-using-gmail/

Test out your server sent emails..

So I setup some automated emails to my housemates to remind them to PAY THEIR RENT!

I ended up doing this via exim4 using this method by using a gmail account to send the mail instead of sending it straight from the system itself. (MTU blocks outgoing smtp)

 

To ensure that the message wasn’t getting flagged as spam and html formatting was working correctly, I used a really great email test page by Brandon Checketts

 

=> http://www.brandonchecketts.com/emailtest.php

From the page, it does:

 

Upon browsing the site a little more, this dude seems like a legitimate linux admin who posts some really informational guides! Nice.

Why PS3 Media Server is seriously the most awesome piece of greatness to ever roam the media streaming suburbs

Ridiculously long titles are fun…Now on to other things…

One of the latest things I’ve done is look into streaming media to my newly bought PS3 and/or Xbox that I have lying around. Obviously, because of certain companies (cough MS and Sony cough), these “media” devices don’t support all the formats they should hence requiring users to at some cases find upnp serving applications that can remux and re-encode content on the fly if need be.

Enter PS3 Media Server – One of the easiest pieces of software I’ve ever had to setup, launch, and use. Literally took me longer to download this than get up and running!

Short install instructions:

1) Java. Java. Java. Make sure you have at least version 2 installed.

2) Download for your platform. If your using ubuntu linux 10.04 and up…you can use their ppa to install.

3) Launch it, setup your settings (most can stay default, obviously you will have to modify the share directories)

4) Save and Restart Server (big buttons on the top, they can’t get any bigger, seriously the developer made this grandma proof.)

5) Browse to the awesome through your LAN connected device under the Video section. 

 

Notes/Recommendations:

a) It may take a while for the video files to show up in the listing (at least on PS3)..just wait a sec, they should show themselves.

b) To make this a daemon on linux, edit the /etc/defaults/ps3mediaserver file with the explanatory configuration flags (more under the How to run PS3 Media Server in headless mode as service / daemon (easy guide))

c) On linux, I ran into an issue with a an h.264 running at High@L5.1 because of tsmuxer vs mencoder.. Basically, tsmuxer can remux and is the default manager for making sure your video files are streamed properly for your media devices. Since the PS3 doesn’t support High@L5.1 (of course), tsmuxer can change the header of the file to make it look like a L4.1 file. This however will not work in all cases. In my case, I needed to make Mencoder the main program for dealing with and transcoding video files of this type so I moved it up on the “Video Files Engines” list under “Transcoding Settings” (there’s a little up arrow) and ensured that “Remux videos with tsMuxeR when possible instead of transcoding” check box was selected. Save the settings and you should be good to go. More here.

 

Other than that, this thing is a beast. I personally have WDTV box as well that plays anything ever but it’s nice to be able to use my consoles. I do hope you have a powerful computer system if your doing this. In the case where do you do have to re-encode on the fly, it can be somewhat intensive. But even on my Q6600 from 2007, I was able to transcode fairly smoothly. 

belowmenu-left.jpg (625×202)

Blogging from not wp-admin

So there’s no way I’m going to blog if I have to log into wp-admin everytime. Luckily you have a few alternatives thanks to WordPress and its awesomeness..

 

1) Email blogging…Send an email to an account watched by your wordpress install. When it sees a new email, it will post the contents as a new post. 

This is already built into WordPress but its in a minimal manner. I suggest the WordPress plugin, Postie which allows more fine grained options supporting categories and specific address filtering!

2) Enable the XMLRPC function in your wp-admin to unlock a slew of ways to update: Linux, Windows, and Mac apps, browser plug-ins (ScribeFire is what I’m using right now) or your smartphone using something like WordPress for Android

You can view more on how to do this from WordPress themselves: http://codex.wordpress.org/Weblog_Client

 

Yay!

Fixing VMware on newer kernels (most notably, 3.2.x and up)

 

So yeah VMware is not liking the new kernel versions Linus and company are pushing. As a result, it has become necessary to patch your installs of 7.1.5 and 8.0.2 of Vmware workstation, a piece of software I can’t live without.

Luckily a very sweet person named Weltall has this handy dandy blog that provides patches for this! I have tested on latest ubuntu 12.04 with 8.0.2 and all is well..

 

1) Install VMware Workstation as root

2) Go here and download the patches, untaring if necessary.

3) apply the patches by running the script file (e.x. patch_stuffs.sh) – You may need to chmod +x the file first.

4) Run VMware

5) Smile

6) Profit.