Converting a Relative Path to an Absolute Path in Bash
September 29, 2007
This really shouldn’t have taken me as long as it did to figure this out, but it was a big enough of an annoyance that I decided to share it.
How to convert a relative path to an absolute path in linux/unix/bash script:
#!/bin/bash
# Assume parameter passed in is an absolute path to a directory.
# For brevity, we won't do argument type or length checking.
echo "Absolute path: `cd $1; pwd`"
For those unaware, you don’t have to ‘cd -’ because the backticks perform command substitution and don’t modify the working directory of the script.
I like to think of snippets like this as an ingredient when cooking with technology. Individual ingredients may be good, but combining them with a recipe yields something far better :)
Windows Server 2003
May 8, 2007
Reinstalling Windows Server 2003 isn’t necessarily difficult. However, when you introduce 3rd party disk controllers and no floppy drive, things get tricky.
The question here is simple: Why Microsoft, WHY!? Requiring a floppy drive is ridiculous, especially on newer servers! Please allow, at the very least, a usb flash drive to be used instead. Thank you.
Changing Root Mail Recipient in Debian
October 11, 2006
Short and sweet tonight. To change the root and postmaster mail recipient in Debian, modify the /etc/aliases (use sudo). Modify the line that says “root: username” to “root: newUsername” and save. That is it!
Back To School: Terminal Tips
September 30, 2006
Over the past week I’ve been doing a lot of tweaking to my shell environment, and helping others do the same. I’ve come across a few fixes and common things that people might find useful, so here we go!
The first is a script snippet to change your shell to bash on login. It only works in some environments, but for those of you who are desparate, throw this in your .cshrc:
if ($?prompt != 0 ) then
setenv SHELL_NAME /bin/bash
if ($SHELL != $SHELL_NAME ) then
set shell = $SHELL_NAME
setenv SHELL $SHELL_NAME
exec $SHELL
endif
endif
One of the more frequent questions I answer is how to get around having to type ‘./’ to run programs in your current directory. The answer is in editing your PATH variable. Throw the following in your shell’s rc file:
export PATH=.:${PATH}
In order to make use of colors in your terminal, you first need to be using a terminal that supports them, and then tell the tty so. To do this, you need to change your SHELL variable to something that supports colors:
export TERM=xterm-color
To make full use of your color supporting terminal, we can make use of newer versions of grep and ls to make output use colors. While we are doing this, we might as well make things more human friendly, so let’s make du and df print out human friendly data. Aliasing automatically replaces words you’ve specified in your .bashrc with the strings they’ve been aliased to, and allows us to do all of these things at once. Here are some examples:
# Aliases for making the command line human friendly alias df='df - h' alias du='du -h' # Make du and df always report human readable data alias ls='ls --color' # If your version of ls supports it, use colors alias grep='grep --color' # If your version of grep supports it, use colors
Finally, some misceallaneous tips. The first clears the *extremely* annoying issue of having a command line that doesn’t support backspaces or other common keys. Put this in your shell’s rc file:
stty sane
Some environments allow other users logged into the same machine as you to send messages to your terminal. This is annoying if your peers think it is funny to disrupt your debugging. To turn it off, just issue the following at the command line (to disable it for that session) or in your shell’s rc file as a permanent fix:
mesg n
And if you want to be one of those kids that interrupts someone else, don’t just write them stupid messages and giggle about it. It is much more entertaining to send an endless amount of gibberish to their screen. The following script will pipe data from /dev/random to another user’s terminal until you kill it:
#!/bin/bash echo "Enter a username: " read user dd if =/dev/random | hd -c | write $user
Remote Desktop From Linux to Windows
September 21, 2006
We have a couple windows servers here in the SE department to run WSUS and AD. I set up the WSUS server and am responsible for maintaining it, but since I run Debian Linux and the machine is in the server room, I previously had to go to the server room to work on it. Being lazy, I did some searching and found rdesktop, a linux friendly implementation of the RDP protocol. Installation is easy if you are running Debian, Ubuntu, or one of the many flavors of linux based on Debian:
sudo apt-get install rdesktop
To use the client, pop open a terminal and issue:
rdesktop -u -p -
This will, after prompting you for your password, (the -p – part) attempt to start a remote desktop session with using and the password you supply.
Then again, you could skip a lot of this nonsense (and get around Microsoft’s ridiculously restrictive and expensive terminal licensing…) if you just installed an OpenSSH server on your windows machine via Cygwin, but that is for another post :)
Fixing Perl Locale Complaints in Debian
September 19, 2006
On a new print server I am setting up for the Software Engineering Department at RIT, I did an apt-get upgrade and was met with the following messages for all following package operations:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_JP:en",
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
I really don’t like having my terminals filled with junk (read below for another example in Ruby), and I doubt anyone else does either. The messages can be cleared simply by issuing the following and choosing the correct locale:
dpkg-reconfigure locales
As far as I am aware, this fix will also work for Ubuntu users affected by the same issue.
