By Rob Flickenger
Book Price: $24.95 USD
£17.50 GBP
PDF Price: $19.99
Cover | Table of Contents | Colophon
grep -v ^#
/etc/inetd.conf
or (more to the point)
netstat -lp
. The first command will show all
uncommented lines in your
inetd.conf,
while the second (when run as root) will show all of the sockets that
are in the LISTEN state, and the programs that are listening on each
port. Ideally, you should be able to reduce the output of a
ps ax to a page of information or less (barring
preforking servers like httpd, of course).
single to the
booting kernel. For example, from the LILO prompt:
LILO: linux single
Give root password for maintenance (or type Control-D for normal startup)
LILO: linux init=/bin/bash
init (with
the init=/bin/bash line) is just one of many
useful options that can be set at boot time. Here are more common
boot parameters:
root=/dev/sdc4
hda=3649,255,63 hdd=cdrom
console=ttyS0,19200n81
s1:12345:respawn:/sbin/agetty 19200 ttyS0 vt100
$ while : ; do echo "Run some code here..."; sleep 1; done
: simply makes the
while always execute (and is more efficient than
running /bin/true, as it
doesn't have to spawn an external command on each
iteration). Definitely do not run a background
process in place of the echo, unless you enjoy
filling up your process table (as the while will
then spawn your command as many times as it can, one every second).
But as far as cool hacks go, the while approach
is fairly lacking in functionality.
zz:12345:respawn:/usr/local/sbin/my_daemon
zz), followed by the runlevels that this program
should be run in, then the respawn keyword, and
finally the full path to the command. In the above example, as long
as my_daemon is configured to run in the
foreground, $ command 2> errfile
$ command | ...\ $ var=` command`
$ command 2>&1 | ... $ var=` command 2>&1`
less error_log, you
see that there are many "soft
errors" relating to missing (or badly linked)
graphics:
[Tue Aug 27 00:22:38 2002] [error] [client 17.136.12.171] File does not exist: /htdocs/images/spacer.gif [Tue Aug 27 00:31:14 2002] [error] [client 95.168.19.34] File does not exist: /htdocs/image/trans.gif [Tue Aug 27 00:36:57 2002] [error] [client 2.188.2.75] File does not exist: /htdocs/images/linux/arrows-linux-back.gif [Tue Aug 27 00:40:37 2002] [error] [client 2.188.2.75] File does not exist: /htdocs/images/linux/arrows-linux-back.gif [Tue Aug 27 00:41:43 2002] [error] [client 6.93.4.85] File does not exist: /htdocs/images/linux/hub-linux.jpg [Tue Aug 27 00:41:44 2002] [error] [client 6.93.4.85] File does not exist: /htdocs/images/xml/hub-xml.jpg [Tue Aug 27 00:42:13 2002] [error] [client 6.93.4.85] File does not exist: /htdocs/images/linux/hub-linux.jpg [Tue Aug 27 00:42:13 2002] [error] [client 6.93.4.85] File does not exist: /htdocs/images/xml/hub-xml.jpg
rob@catlin:~/Music$ ls Hallucinogen - The Lone Deranger Misc - Pure Disco rob@catlin:~/Music$ rm -rf Misc[TAB] rob@catlin:~/Music$ rm -rf Misc\ -\ Pure\ Disco/
[TAB] above replaces the
command line with the line below it, properly escaping any special
characters contained in the file. That's fine for
one file at a time, but what if we want to do a massive
transformation (say, renaming a bunch of mp3s to include an album
name)? Take a look at this:
rob@catlin:~/Music$ cd Hall[TAB] rob@catlin:~/Music$ cd Hallucinogen\ -\ The\ Lone\ Deranger/ rob@catlin:~/Music/Hallucinogen - The Lone Deranger$ ls Hallucinogen - 01 - Demention.mp3 Hallucinogen - 02 - Snakey Shaker.mp3 Hallucinogen - 03 - Trancespotter.mp3 Hallucinogen - 04 - Horrorgram.mp3 Hallucinogen - 05 - Snarling (Remix).mp3 Hallucinogen - 06 - Gamma Goblins Pt. 2.mp3 Hallucinogen - 07 - Deranger.mp3 Hallucinogen - 08 - Jiggle of the Sphinx.mp3 rob@catlin:~/Music/Hallucinogen - The Lone Deranger$
#!/bin/sh if [ -z "$ALBUM" ]; then echo 'You must set the ALBUM name first (eg. export ALBUM="Greatest Hits")' exit 1 fi for x in *; do echo -n $x; echo -ne '\000' echo -n `echo $x|cut -f 1 -d '-'` echo -n " - $ALBUM - " echo -n `echo $x|cut -f 2- -d '-'`; echo -ne '\000' done | xargs -0 -n2 mv
root@catlin:/tmp# rm -rf junk/ rm: cannot unlink `junk/stubborn.txt': Operation not permitted rm: cannot remove directory `junk': Directory not empty root@catlin:/tmp# cd junk/ root@catlin:/tmp/junk# ls -al total 40 drwxr-xr-x 2 root root 4096 Sep 4 14:45 ./ drwxrwxrwt 13 root root 4096 Sep 4 14:45 ../ -rw-r--r-- 1 root root 29798 Sep 4 14:43 stubborn.txt root@catlin:/tmp/junk# rm ./stubborn.txt rm: remove write-protected file `./stubborn.txt'? y rm: cannot unlink `./stubborn.txt': Operation not permitted
root@catlin:/tmp/junk# cp /dev/null stubborn.txt cp: cannot create regular file `stubborn.txt': Permission denied root@catlin:/tmp/junk# > stubborn.txt bash: stubborn.txt: Permission denied
root@catlin:/tmp/junk# ln stubborn.txt another.txt
ln: creating hard link `another.txt' to `stubborn.txt': Operation not permitted
root@catlin:/tmp/junk# lsattr
---i--------- ./stubborn.txt
rob@mouse:~/linux$ make -j4; make -j4 modules
time make bzImage:
real 7m1.640s
user 6m44.710s
sys 0m25.260s
time make -j2 bzImage:
real 3m43.126s
user 6m48.080s
sys 0m26.420s
time make -j4 bzImage:
real 3m37.687s
user 6m44.980s
sys 0m26.350s
time make -j10 bzImage:
real 3m46.060s
user 6m53.970s
sys 0m27.240s
export PS1=`echo -ne "\033[0;34m\u@\h:\033[0;36m\w\033[0;34m\$\033[0;37m "`
export PS1=`echo -ne "\033[0;34m\u@\h:\033[0;36m\w\033[0;34m\$\033[0;37m "`
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
root@catlin:~# find / -perm +6000 -type f -exec ls -ld {} \; > setuid.txt &
-rws--x--x 1 root bin 35248 May 30 2001 /usr/bin/at -rws--x--x 1 root bin 10592 May 30 2001 /usr/bin/crontab
# chmod a-s /usr/bin/{at,crontab}
root ALL=(ALL) ALL
root ALL=(ALL) ALL rob ALL=(ALL) ALL jim ALL=(ALL) ALL david ALL=(ALL) ALL
user machine=(effective user) command
peter beta.oreillynet.com=(ALL) ALL
peter lists.oreillynet.com=(mailman) ALL
david ns.oreillynet.com=(bind) /usr/sbin/rndc,/usr/sbin/named
M4= m4
CFDIR= /usr/src/sendmail-8.12.5/cf
CHMOD= chmod
ROMODE= 444
RM= rm -f
.SUFFIXES: .mc .cf
all: virtusers.db aliases.db access.db sendmail.cf
access.db: access.txt
makemap -v hash access < access.txt
aliases.db: aliases
newaliases
virtusers.db: virtusers.txt
makemap -v hash virtusers < virtusers.txt
.mc.cf:
$(RM) $@
$(M4) ${CFDIR}/m4/cf.m4 $*.mc > $@ || ( $(RM) $@ && exit 1 )
$(CHMOD) $(ROMODE) $@
make. Since make keeps track of
files that have been recently updated, it takes care of rebuilding
only what needs to be rebuilt.
# # Makefile to push *.conf to the slave, as needed. # SLAVE= www2.oreillynet.com APACHE= /usr/local/apache RM= /bin/rm TOUCH= /bin/touch SSH= /usr/local/bin/ssh SCP= /usr/local/bin/scp .SUFFIXES: .conf .ts all: test restart sites.ts globals.ts httpd.ts configtest: test test: @echo -n "Testing Apache configuration: " @$(APACHE)/bin/apachectl configtest restart: $(APACHE)/bin/apachectl restart .conf.ts: @$(RM) -f $@ @$(SCP) $*.conf $(SLAVE):$(APACHE)/conf @$(SSH) $(SLAVE) $(APACHE)/bin/apachectl restart @$(TOUCH) $@
cat /usr/share/dict/words | grep 'st$' | sed 's/st$/.st/' | \ while read i; do \ (whois $i | grep -q '^No entries found') && echo $i; sleep 60; \ done | tee list_of_st_domains.txt
rob@magic:~$ df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sda1 7040696 1813680 4863600 27% /
/dev/sda2 17496684 13197760 3410132 79% /home
/dev/sdb1 8388608 8360723 27885 100% /var/spool/mail
alias ducks='du -cks * |sort -rn |head -11'
rob@magic:~$ cd /var/spool/mail rob@magic:/var/spool/mail$ ducks 8388608 total 1537216 rob 55120 phil 48800 raw 43175 hagbard 36804 mal 30439 eris 30212 ferris 26042 nick 22464 rachael 22412 valis
;)
root@magic:/home# ducks
[ several seconds later ]
13197880 total
2266480 ferris
1877064 valis
1692660 hagbard
1338992 raw
1137024 nick
1001576 rob
925620 phil
870552 shared
607740 mal
564628 eris
root@catlin:/proc# ls
1/ 204/ 227/ 37/ bus/ hermes/ loadavg scsi/ version
1039/ 212/ 228/ 4/ cmdline ide/ locks self@
1064/ 217/ 229/ 5/ cpuinfo interrupts meminfo slabinfo
1078/ 220/ 230/ 6/ devices iomem misc stat
194/ 222/ 231/ 698/ dma ioports modules swaps
197/ 223/ 232/ 7/ driver/ irq/ mounts sys/
2/ 224/ 233/ 826/ execdomains kcore net/ sysvipc/
200/ 225/ 254/ 827/ filesystems kmsg partitions tty/
202/ 226/ 3/ apm fs/ ksyms pci uptime
root@catlin:/proc# cat version
Linux version 2.4.18 (root@catlin) (gcc version 2.95.3 20010315 (release))
#2 Sat Jun 22 19:01:17 PDT 2002ps awux |grep something just to find the PID of a
job you'd like to kill, then you should take a look
at some of the more modern process manipulation packages.
# skill -STOP pts/2
# skill -CONT pts/2
# snice +5 luser
# skill -KILL rob bash # pkill -KILL -u rob bash
$ pgrep httpd
3211
3212
3213
3214
3215
3216
rob@catlin:/tmp$ ulimit -f 100 rob@catlin:/tmp$ yes 'Spam spam spam spam SPAM!' > spam.txt File size limit exceeded rob@catlin:/tmp$ ls -l spam.txt -rw-r--r-- 1 rob users 102400 Sep 4 17:05 spam.txt rob@catlin:/tmp$
rob@catlin:/tmp$ ulimit -f unlimited
bash: ulimit: cannot modify limit: Operation not permitted
rob@catlin:~$ cat > lots-o-procs #!/bin/bash export RUN=$((RUN + 1)) echo $RUN... $0 ^D rob@catlin:~$ ulimit -u 10 rob@catlin:~$ ./lots-o-procs 1... 2... 3... 4... 5... 6... 7... 8... 9... ./lots-o-procs: fork: Resource temporarily unavailable rob@catlin:~$
passwd -l luser
chsh -s /bin/true luser
luser@evil:~$ ssh -f -N -L8000:private.intranet.server.com:80 old.server.com
up to 960MB: off up to 4GB: 4GB more than 4GB: 64GB
append="mem=2048M"
kernel /boot/vmlinuz-2.4.19 mem=2048M
c:\loadlin c:\kernel\vmlinuz root=/dev/hda3 ro mem=2048M
hdparm -Tt /dev/hda
/dev/hda: Timing buffer-cache reads: 128 MB in 1.34 seconds =95.52 MB/sec Timing buffered disk reads: 64 MB in 17.86 seconds = 3.58 MB/sec
-T means to test the
cache system (i.e., the memory, CPU, and buffer cache). The
-t means to report stats on the disk in question,
reading data not in the cache. The two together, run a couple of
times in a row in single-user mode, will give you an idea of the
performance of your disk I/O system. (These