YUM fails with 404

[problem]

If you (like me) was well keen, to get your shiny new fedora core 5 system up and running. Then you run yum and think, hang on that ain’t right – 404. Linux is better than this!! 🙁

[/problem]

[solution]

Don’t bother searching the news groups, for posts that go nowhere (like I did for close on 2 hours – that I’ll never get back!! 🙂 ), here is the answer –

www.fedorafaq.org Do a search for yum – follow the prompts and you’re in.

[/solution]

[example]

Nothing to see here, check out the solution tab.

[/example]

[reference]

[tags]Linux YUM, YUM fails, YUM problems, Unix Coding School[/tags]

[/reference]

Linux iptables blocking IP address

[problem]

You do a netstat -an and see a raft of connections to your apache host, coming in at 10 – 20 a second.

It shows ::ffff:10.0.0.10:80 ::ffff:212.248.1.1:1403 in netstat output. These are IPV6 connections AFAIK.

Also you see ::1 – – [DD/MMM… in apache log. Restarting apache does nothing, the connections just reappear.

[/problem]

[solution]

You need to block all connections from this IP address using iptables. See example tab.

[/solution]

[example]


cp -i /etc/sysconfig/iptabes /etc/sysconfig/iptables.$(date +%j).bu
vi /etc/sysconfig/iptables

Add a line like the one below:

#block
-A INPUT -s 212.248.225.12 -j DROP

Then restart iptables like this: /etc/init.d/iptables restart as root.

Finally check your rules like this: /etc/init.d/iptables status as root.

[/example]

[reference]

[tags]Linux Security, Linux iptables, Fedora Core iptables, Linux Firewall, Unix Coding School[/tags]

[/reference]

UNIX Lesson Six

[problem]

You want to write elegant code, which integrates well (pipes) with other UNIX commands.

[/problem]

[solution]

Learn these UNIX Laws, from the inventor of UNIX pipes.

[/solution]

[example]

No examples – see the reference tab.

[/example]

[reference]

1. Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.

2. Expect the output of every program to become the input to another, as yet unknown, program. Don’t clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don’t insist on interactive input.

3. Design and build software, even operating systems, to be tried early, ideally within weeks. Don’t hesitate to throw away the clumsy parts and rebuild them.

4. Use tools in preference to unskilled help to lighten a programming task, even if you have to detour to build the tools and expect to throw some of them out after you’ve finished using them.

Doug McIlroy, the inventor of Unix pipes and one of the founders of the Unix tradition.

[tags]UNIX Law, UNIX pipes, Unix Coding School[/tags]

[/reference]

UNIX Lesson Five

[problem]

Coding in UNIX is an art form, where certain philosophies prevail.

[/problem]

[solution]

To really excel at UNIX coding and produce elegant, efficient, low maintenance code – you need to learn UNIX philosophy.

[/solution]

[example]

No examples – just see the reference tab.

[/example]

[reference]

1. Rule of Modularity: Write simple parts connected by clean interfaces.

2. Rule of Clarity: Clarity is better than cleverness.

3. Rule of Composition: Design programs to be connected to other programs.

4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.

5. Rule of Simplicity: Design for simplicity; add complexity only where you must.

6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.

7. Rule of Transparency: Design for visibility to make inspection and debugging.easier.

8. Rule of Robustness: Robustness is the child of transparency and simplicity.

9. Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.

10. Rule of Least Surprise: In interface design, always do the least surprising thing.

11. Rule of Silence: When a program has nothing surprising to say, it should say nothing.

12. Rule of Repair: When you must fail, fail noisily and as soon as possible.

13. Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.

14. Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.

15. Rule of Optimization: Prototype before polishing. Get it working before you optimize it.

16. Rule of Diversity: Distrust all claims for “one true way”.

17. Rule of Extensibility: Design for the future, because it will be here sooner than you think.

[tags]UNIX Laws, UNIX Philosophy, Unix Coding School[/tags]

[/reference]

UNIX Lesson One

[problem]

You are a complete beginner and keen to learn UNIX!

[/problem]

[solution]

Okay in the examples, I am going to start very basically.

From the outset, you need to understand some basic terms.

  • Firstly – what is UNIX. Unix is an operating system. Other operating systems including Windows, Apple Mac, Novell, etc. It is what turns the computer, from an over-sized paper weight – into a living, breathing machine. 🙂

  • The operating system, talks to all the hardware. Definition of hardware is that if you drop it on your foot, it hurts. 🙂 It talks to the CPU (brain chip) of the computer, the memory (RAM Chips) which is sort of like your desk space, a working area. The bigger your desk space the more you can work on at once. Why size does matter – how big is big. Well currently 256mb (256 megabyte) should be the minimum, ideally 1GB (1 gigabyte) should be plenty.

  • So how do we interface with UNIX? Through a terminal and shell generally. Yes you can use GUIs (Window) – but the real power of UNIX is in the shell.

  • What is a terminal and a shell for that matter? A terminal is just a program that runs, that allows you to connect to UNIX machines – including your own. If you have just installed your own Linux machine, or having to use one at work – you’ll generally start from a windows environment – not necessarily Microsofts either! 🙂 If your are running Linux, generally you can right click your mouse on the background of your desktop and select terminal. From MS Windows there is a terminal program you can run, or ideally look up putty SSH client at the reference tab.

  • more to follow shortly …

[/solution]

[example]

[/example]

[reference]

[tags]Free Linux Lessons, Lesson One, Unix Coding School[/tags]

[/reference]

Compare command output with file

[problem]

You want to run a command, save the output to a file – then compare the output at a later date with the file.

For example – you want to update your crontab: save a backup crontab -l > cronfile.$(date +%j), make your updates, then compare it with the backup file.

[/problem]

[solution]

Use diff with the hypen to represent read from stdin.

This saves keeping multiple copies.

[/solution]

[example]


crontab -l > cronfile.$(date +%j)
crontab -e # make your diffs
crontab -l | diff - cronfile.$(date +%j)

Also you can use cmp, which just reports the line number, etc


crontab -l > cronfile.$(date +%j)
crontab -e # make your diffs
crontab -l | cmp - cronfile.$(date +%j)

[/example]

[reference]

[tags]crontab, diff, cmp, comparing command output with file, UNIX Coding School[/tags]

[/reference]

Simple Basic UNIX Permission Denied

[problem]

You are quite happily editing away, then you come to save … oh dear, permission denied.

Either the file is set to readable, or it is owned by another user.

But you have write permission to the directory, either by user or group!

[/problem]

[solution]

If it is just a simple case of the file being unwritable and you own it, if in vi following the first example.

If you are not the owner, write the file to /tmp. Then follow the second example.

[/solution]

[example]

Allow write permission to a file you are currently vi editing – but the file is not writable.

:!chmod u+w %

If you are not the owner, no need to worry, even without root we can change the owner if you have write access to the directory! 🙂


:!zsh
mv -i your_filename /tmp/your_filename.mv
cp -i /tmp/your_filename.mv your_filename

Obviously if not in vi, you’ll need to break out to a shell using the mechanism in your editor. Also you may not have zsh, so ksh – bash, etc will do.

I tend to do all this on the command line, with a semi-colon between the mv and cp – so I can use command line expansion (the move has not happened yet!).

mv -i thefile[tab] /tmp/thefileXXXX;cp -i /tmp/thefileXXXX . [return]

[/example]

[reference]

[tags]Unix permission denied, chown owner without root, Unix Coding School[/tags]

[/reference]

Network sniffing on Linux

[problem]

Just what the hell is your apache web server doing!! 🙂

Seeing how clients are connecting to servers and what data is passing between, can prove invaluable in finding the solutions to issues.

[/problem]

[solution]

Network trace it – showing the headers and content being sent and received.

[/solution]

[example]


tcpdump -vvv -A -XX host 10.0.0.8 and port 80

Just replace 10.0.0.8 with your client ip address.

tcpdump -c 50 port 80
tcpdump: listening on eth0
00:43:09.262942 10.0.0.8.1288 > bree.http: S 2445348839:2445348839(0) win 16384
00:43:09.263069 bree.http > 10.0.0.8.1288: S 3557400364:3557400364(0) ack 2445348840 win 5840 (DF)
00:43:09.265882 10.0.0.8.1288 > bree.http: . ack 1 win 17520
00:43:09.268591 10.0.0.8.1288 > bree.http: P 1:493(492) ack 1 win 17520

On AIX you can ordinarly use iptrace or tcpdump.

On Solaris, we simply use snoop.
snoop -x0 src hostname

Where source is the client and hostname is the server. Other options are port portnum, etc. snoop –help or man snoop for more options.

[/example]

[reference]

[tags]Network, Tracing, tcpdump, Linux[/tags]

[/reference]

Removing links to missing files

[problem]

You have many symbolic links that point to missing files.

I guess it is all just about good housekeeping! 🙂 Well and the fact your application might break, depending on something being there, that is not.

[/problem]

[solution]

This bit of shell under example tab, deals with them swiftly and sharply. 🙂

Effectively it just does a find from the current directory, then loops around looking for missing files.

[/solution]

[example]


for na in `find . -type l`
do
ls -lLd $na 2>&1 | grep "No such file" |
while read junk delme junk
do
rm ${delme%:}
done
done

[/example]

[reference]

[tags]symbolic links, find, rm, while, UNIX Coding School[/tags]

[/reference]

compressed using zip gzip bzip2

[problem]

You have been sent (or want to download) a zip file. But also want to verify the contents, before decompressing.

[/problem]

[solution]

Under UNIX there are a number of ways to compress files, or deal with those that have already been compressed.

See the examples tab.

[/solution]

[example]

  • Firstly dealing with files ending with .gz.

    To view the contents of a gzipped file, just use gzip -l filename.gz

    To unzip the file, use gzip -d filename.gz or gunzip filename.gz

    To view the contents of the gzipped file, without decompressing it: gzip -c -d filename.gz.

    To create a gzip – gzip –best filename – or gzip reads from stdin, in the best of UNIX traditions. 🙂 You can also pipe gzip output or redirect it.

  • Next unzip.

    To view the contents of a zipped file, just use zipinfo filename.zip

    To unzip the file, use unzip filename.zip.

    To view the contents of the gzipped file, without decompressing it: unzip -c filename.gz.

    To create a zip – zip filename – or zip reads from stdin.

  • Lastly bzip.

    To decompress the file, use bunzip2 filename.bz2.

    To view the contents of the bzipped file, without decompressing it: bzcat filename.bz2.

    To create a zip – bzip2 filename – or zip reads from stdin.

[/solution]

[reference]

[tags]gzip, zip, bzip2, UNIX Coding School[/tags]

[/reference]