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

Wednesday, January 10, 2007

Get Linux/Unix command lines for Windows

Sometimes the windows command line just isn't good enough, and instead of dir you want ls, or you want to count the number of lines in a file with a wc -l or grep for something. Cygwin is great and all, but it is a bit of overkill for most of my situations. UnxUtils.zip contains all of the above and more, and all the tools are accessible from the windows command line!

The official site's download link is down at the time of posting, but I have found a number of unofficial mirrors:

ftp://81.30.199.66/pub/windows/unixutils/UnxUtils.zip
ftp://ftp.ufanet.ru/pub/windows/unixutils/UnxUtils.zip
ftp://193.40.239.25/pub/windows/msutils/UnxUtils.zip
ftp://194.226.230.170/pub/windows/devel/UnxUtils.zip
http://www.mirrorservice.org/sites/ftp.locustworld.com/UnxUtils.zip

Once you have downloaded and unzipped into a directory you need to add them to your windows path, so that when you type ls your computer knows where to find it.

  • Right click "My Computer" then click properties
  • In the "System Properties" window click the advanced tab
  • Click the "Environment Variables" button
  • Click the "PATH" variable and click edit
  • Add a semicolon to the end of the "Variable value" field and then type in the location you unzipped UnxUtils.zip to followed by \usr\local\wbin
To test your new utilities open up a command prompt (you can find it hiding in Start->Programs->Accessories->Command Prompt) and try one out! The standard UnxUtils contains the following tools:

(this list generated by typing ls *.exe | sed -e "s/\.exe//g" > utils.txt from within the wbin directory - from a windows command prompt!)


agrep
ansi2knr
basename
bc
bison
bunzip2
bzip2
bzip2recover
cat
chgrp
chmod
chown
cksum
cmp
comm
compress
cp
csplit
cut
date
dc
dd
df
diff
diff3
dircolors
dirname
du
echo
egrep
env
expand
expr
factor
fgrep
find
flex
fmt
fold
fsplit

gawk
gclip
gplay
grep
gsar
gunzip
gzip
head
id
indent
install
join
jwhois
less
lesskey
ln
logname
ls
m4
make
makedepend
makemsg
man
md5sum
mkdir
mkfifo
mknod
mv
mvdir
nl
od
paste
patch
pathchk
pclip
pr
printenv
printf
pwd


recode
rm
rman
rmdir
sdiff
sed
seq
shar
sleep
sort
split
stego
su
sum
sync
tac
tail
tar
tee
test
touch
tr
type
uname
unexpand
uniq
unrar
unshar
unzip
uudecode
uuencode
wc
wget
which
whoami
xargs
yes
zcat
zip

Tuesday, January 9, 2007

Run X11 Applications Remotely

Sometimes you want to run a graphical application on a Linux box that is headless, but you don't want to go to the bother of connecting up a keyboard, mouse and monitor. The Linux graphics system X11 is great for this as it doesn't care where you are, as long as it is knows where to connect and is authorised to do so. Here is how I run X11 applications locally on Mac OSX or Linux:

First off, I start the X server. On OSX that means installing and running the application; on Linux I'm usually already in a graphical mode so it is already running. On the local computer (the one I'm sitting at) I run:

$ xauth list
Ari.local/unix:0 MIT-MAGIC-COOKIE-1 7b246eec9fc9d493fc009dd4ea2b8b8a
10.0.0.9:0 MIT-MAGIC-COOKIE-1 7b246eec9fc9d493fc009dd4ea2b8b8a
localhost:0 MIT-MAGIC-COOKIE-1 7b246eec9fc9d493fc009dd4ea2b8b8a

The line in the middle is the one of interest; it is the inet domain line. Copy that line. On the remote computer (via ssh) I run

$ export DISPLAY=10.0.0.9:0
$ xauth add 10.0.0.9:0 MIT-MAGIC-COOKIE-1 7b246eec9fc9d493fc009dd4ea2b8b8a

That second line is mostly a copy-paste job. Once all this has been configured, X11 should now run lovely.

Friday, January 5, 2007

Howto: get Azureus to start at boot and run headless (ie without a gui) on Linux

Getting Azureus to start at boot headless saves system resources and means it will work away nicely in the background. This approach works great with a web front-end like the Azureus Swing UI. To get the most out of bittorrent, you also need to make sure that it shuts down properly. Here are the steps I used to set it up...

Install and configure Azureus
  • Download Azureus and decompress it into a directory
  • Download log4j.jar and commons-cli.jar and put them in the directory you uncompressed Azureus into
  • Run Azureus by opening a terminal, changing into the directory you put Azureus and typing
./azureus
  • Configure Azureus with the GUI tool
  • Exit Azureus
  • Create a file called headless.sh with the following in it:
#!/bin/bash
java -jar Azureus2.jar --ui=console >/dev/null 2>&1
  • Make that file executable by typing
chmod u+x headless.sh
  • Create a file called azureus_rcscript with the following in it: (you need to change the AZ_USER and DIR variables to represent the name of the user who will be running Azureus and the directory Azureus is installed to)
#! /bin/sh
#rc script for Azureus by Phill - http://phillstechstuff.blogspot.com
#Based on script from Azureus wiki - http://www.azureuswiki.com/index.php/HeadlessSwingUIAtBoot

#The user that will run Azureus
AZ_USER=user

#your path to the azureus directory, where Azureus2.jar is located
DIR=/home/user/azureus

#executable files in the following paths that are perhaps needed by the script
PATH=/bin:/usr/bin:/sbin:/usr/sbin

#Description
DESC="Azureus daemon"

case "$1" in
start)
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
then
echo "Azureus is already running!"
else
echo "Starting $DESC"
su $AZ_USER -c "cd $DIR; ./headless.sh"
fi
;;
stop)
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
then
echo -n "Stopping $DESC"
su $AZ_USER -c "kill `ps -ef | grep "java -jar Azureus2.jar" | grep -v grep | awk '{print $2}'`"
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;
restart)
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
then
echo -n "Stopping $DESC"
su $AZ_USER -c "kill `ps -ef | grep "java -jar Azureus2.jar" | grep -v grep | awk '{print $2}'`"
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
echo "Starting $DESC: $NAME"
su $AZ_USER -c "cd $DIR; ./headless.sh"
echo " ... done."
;;
status)
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
then
echo "Azureus is RUNNING"
else
echo "Azureus is DOWN"
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

exit 0

  • Put that file inside the startup for the runlevel your machine runs at. For my machine, that is runlevel 5, and it is probably the same for yours if it boots up to a graphical environment. I did this by typing
su
mv azureus_rcscript.sh /etc/rc5.d/S99azureus_rcscript.sh
cp /etc/rc5.d/S99azureus_rcscript.sh /etc/rc5.d/K01azureus_rcscript.sh
chmod 755 /etc/rc5.d/S99azureus_rcscript.sh /etc/rc5.d/S99azureus_rcscript.sh
  • The S99 makes it run this script after everything else has started up, which is good as it makes sure it won't try to run before things like network services have started. As the script also includes functionality to shut down Azureus, I copied it to have it run when we leave runlevel 5, which usually means shutdown time. The K01 means to run it before shutting down any other processes
That's it! If you reboot you should now have Azureus running in headless mode, and shutting down cleanly when you shutdown the system.

Please let me know if this works for you, and if you have any questions!