Andrew's Sprocket

a gear for all facets of life

This is a useful packet grabber using tcpdump.
You don’t get as many details as wireshark or ethereal but running this on a remote server is easier.

First find out what network interface you want to capture.

$ ifconfig

Then start capturing and write to a file with -w

$ tcpdump -i eth0 -w eth0-dump.log

You can then read the file with the -r switch

$ tcpdump -r eth0-dump.log
Google Buzz
  • Share/Bookmark

To change the system date/time in Linux create a symlink to /etc/localtime for the correct time zone.

Verify the new time with “date” then update the hardware clock with “hwclock”

$ ln -sf /usr/share/zoneinfo/America/Denver /etc/localtime
$ date
$ hwclock --systohc

You can also use ntpdate for NTP (Network Time Protocol)

$ ntpdate pool.ntp.org
$ hwclock --systohc

You will need to restart httpd to see this change reflected in your webserver.

Other Time Links
http://www.time.gov
Network Time Protocol

Google Buzz
  • Share/Bookmark

It is always useful to be able to automate backups. I found some of this out there in the ether and use it often.

#!/bin/bash
dir="/var/www";
# what directory or file to back up
cd ${dir}
 
if [[ $? != 0 ]]; then
   #cd failed, we'll exit with an error message
   echo "Error: could not cd to ${dir}. No backup was created."
   exit 1;
fi;
 
# path to back up folder
tar -zcf /var/www/backups/backup-$(date +%Y%m%d).tar.gz .
Google Buzz
  • Share/Bookmark

Go To: http://ftp.gnu.org/pub/gnu/
Browse for the app you are in need of, say wget, since this did not come on Mac OSX.

Download the tarball then unzip and install

1
2
3
4
5
tar -xvzf wget-1.11.4.tar.gz
cd wget-1.11.4
./configure
make
sudo make install

p.s. you may need tar also, if not, Stuffit will unzip, and make is included in the Apple XCode (~1.1GB)

Google Buzz
  • Share/Bookmark

I found this very useful, thanks to David Jameson and others.

http://www.sshkeychain.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
 
# create ssh connections without giving a password - found on the net
# Modified by DHJ to correct several bugs and missing commands
 
if [ $# -lt 1 ]; then
echo Usage: $0 username@remotehost
exit
fi
remote="$1" # 1st command-line argument is the user@remotehost address
this=$HOST # name of client host
 
# first check if we need to run ssh-keygen for generating
# $HOME/.ssh with public and private keys:
if [ ! -d $HOME/.ssh ]; then
echo "just type RETURN for each question:" # no passphrase - unsecure!!
# generate DSA keys only:
echo; echo; echo
#This will generate the .ssh directory and put the keys in it
ssh-keygen -t dsa
else
# we have $HOME/.ssh, but check that we have
# key (DSA):
if [ ! -f $HOME/.ssh/id_dsa ]; then
# generate DSA keys:
echo "just type RETURN for each question:" # no passphrase - unsecure!!
ssh-keygen -t dsa
fi
fi
 
echo "You will be asked for your remote password several times during this phase"
 
cd $HOME/.ssh
 
if [ ! -f config ]; then
# make ssh try ssh -2 (DSA keys)
echo "Protocol 2" > config
chmod 600 config
fi
 
#Make sure private key cannot be read by anyone else
chmod 600 $HOME/.ssh/id_dsa
 
# copy public keys to the destination host:
 
echo; echo; echo
# create .ssh on remote host if it's not there:
echo "Connecting to remote host to create .ssh directory…"
ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
# copy DSA key:
echo "Copying public DSA key to remote host…"
scp id_dsa.pub ${remote}:.ssh/${this}_dsa.pub
# make authorized_keys(2) files on remote host:
 
echo; echo; echo
# this one copies DSA key:
echo "Configuring authorized_keys2 file on remote host…"
ssh $remote "cd .ssh; touch authorized_keys2; cat ${this}_dsa.pub >> authorized_keys2;"
echo "Configuring directory permissions on remote host…"
ssh $remote "cd .ssh; rm ${this}_dsa.pub; chmod 600 *; cd ..; chmod go-rwx .ssh;"
echo; echo; echo
echo "You should now be able to ssh to the remote host without a password"
echo "try ssh $remote"
Google Buzz
  • Share/Bookmark