Top Nav

Archive | Bash Scripting

Get IP Address In A Script

Recently needed a good way to fetch the IP address of each interface within a script. Tried things like:

and

But this is fairly ugly. So I tried:

This gives a list of IP addresses but they are un-ordered so I can’t guarantee which address goes with which interface.  Here’s one using “ip addr”:

Still very messy.  Finally, found the “ifdata” command which is part of the “moreutils” package. First make sure “moreutils” is installed with:

Now you can query for a wide range of different information:

So here are some examples:

Overall this is much cleaner and more reliable then the earlier approaches.

0

maxclients.sh Script For Apache

This script attempts to look at Apache memory usage and recommend a stable setting for MaxClients.

 

0

getpass.sh Bash Script

Simple bash script for generating random passwords. We didn’t write this and don’t know exactly where it came from.

 

0