Monday, August 14, 2006

altering the rm command

Anyone who uses the rm command with frequency will eventually make a mistake and erase a file or directory that had important files. To combat this problem I have written the following shell script:

From the command line type:

nano rmspecial

This will create a new file rmspecial and put you in editor mode
Then copy in the following code which I will explain below.

#!/bin/sh
for i in "$@"
do
var1=$(echo "$i" | sed 's/\///')
mv "$var1" "/$HOME/.Trash/$var1.`date '+%Y-%m-%d.%H.%M.%S'`"
echo "Moving $i to Trash"
done

Exit nano and save the new rmspecial script

Now change the permissions on rmspecial so that the script can be executed. (You can use chmod)

If you are using the bash shell find the bashrc file and add an alias:
alias rm="/Users/wferrell/.rmspecial"

Now when at the command line when one uses the rm command they are actually calling the .rmspecial script

Looking at the script we see that instead of erasing the files the script moves the files to the trashcan where they can be easily emptied.

The sed command exists to ensure that directories and files can be removed.

Note that the modifiers of the rm command, for example rm -r, no longer exist.

Saturday, August 05, 2006

linux notes august 5th 2006

Getting wake on lan or WOL working with ubuntu.

Here are the steps in most basic form

1) Make sure you have hardware that supports WOL. If you are unsure go to the website of your motherboard manufacturer and NIC manufacturer. It should say in their documentation if it is suupported or not.

2) Boot your computer and get the BIOS setup menu. Search for the wake on lan option and enable it. '

3) reboot and login to ubuntu
run this command
sudo su
input password

now we want to enable WOL inside ubuntu.
I personally am not sure this needs to be done but it didnt work for me until I ran the following code:
ethtool -s eth0 wol g

problem is this only works on a one time basis. This means we need to run the ethtool code everytime the computer starts. This way WOL will always work.

How do we do this?

become root
sudo su

now input your password

now change to the proper directory so that the code is run at startup
cd //etc/init.d

now create the file which will become the program
nano ethtool

now put the command in the file and then exit and save the file
ethtool -s eth0 wol g

now we need to set the permissions of the file ethtool
chmod a+x ethtool

now we need to update rc.d so that our code is run on startup
update-rc.d -f ethtool defaults

4. Now do a reboot and test it out by sending that magic packet from another computer.