Thanks for the leglug link. Great idea.
Do you plan on organising any "installfests" (people get together to install linux)? Or other similar events?
And it would be nice to add a link to lebgeeks.com in the links section, to support the development of the tech community in lebanon.
Hi,

you said you do your shell scripting in PHP. Good thing you deleted that ;)
don't let anyone hear you say it.

It's like trying to read the contents of a directory by implementing "ls" in assembly.
The thing is I have more than 2 years experience in PHP, and I really didn't feel like learning a new language as bizarre as bash from scratch, so I just went with PHP, and I'm actually pretty happy with it. Here I'll show you the code that I use to read the output of a command in PHP.
for example to know if host 1.2.3.4 is up and report unreachability in the syslog:
#!/usr/bin/php -q

$ip = 1.2.3.4;

exec("ping $ip -c 2 -W 2|grep "64 bytes"", $aOut);
if (count($aOut)!=2) {
            exec("logger Host $ip is down.");
        }
It is true that you have to write more code to process the output, but on the other hand I find PHP to be more readable and it has a lot of additional features, like tons of extensions, objects, etc... But I have to say reason n.1 is that I already know it inside out.

One PHP feature that I use for example is raw sockets. I use it to automatically log me into the GDS login page. This way I always stay connected and never see that annoying login page.
#!/usr/bin/php -q

$ip = 1.2.3.4;

exec("ping $ip -c 2 -W 2|grep "64 bytes"", $aOut);
if (count($aOut)!=2) {
            exec("logger Host $ip is down.");
        }
not only is this too much code, everything you need is already there, and you're adding the PHP syntactic sugar around it, here's the one line bash version:
$  (ping google.com -c 1 | grep "64 bytes") || logger "Host google.com is down.";
it's no point to use PHP since you're exec'ing the commands already.
rolf,
If you wanna become a *NIX system administrator, or apply advanced tasks on *NIX, then Bash/Perl are essential. Along with mastering regular expressions and tools (grep,awk, sed...)
Yeah, I am planning on starting perl.
I have already used regular expressions in PHP. I'll look into awk and sed, thanks!

megalomania, this is from the grep manpage:
Normally, exit status is 0 if selected lines are found and 1 otherwise.
But the exit status is 2 if an error occurred, unless the -q or --quiet
or --silent option is used and a selected line is found.


how does that map to true/false?
megalomania, this is from the grep manpage:
Normally, exit status is 0 if selected lines are found and 1 otherwise.
But the exit status is 2 if an error occurred, unless the -q or --quiet
or --silent option is used and a selected line is found.


how does that map to true/false?
0 is false, everything else is true.
(Update: in shell it's the opposite, 0 is success (so true) and everything else is not. So the above statement is wrong, the reverse is true.)

with that in mind, you only care to see if grep matched, which should return 0, otherwise, you consider a failure.

"2 if an error occurred" is not what you think it is. This is an error in "grep", and not in "ping", which does not mean that the host is down.

So in any case, you only care if you get a ping reply, which should match in grep, and which should return you a 0. Otherwise there may be a million reason why the ping didn't return, but since you don't account for these in your original code, I didn't account for them in mine.
Ok, I got it. And this would do the opposite:
(! ping 127.0.0.1 -c 1 | grep "64 bytes") || echo "Host is up.";
Ok, I got it. And this would do the opposite:
(! ping 127.0.0.1 -c 1 | grep "64 bytes") || echo "Host is up.";
umm.. no, the NOT (!) should be outside the parenthesis, although I'm no bash expert to know what that eventually should mean.

Sso the opposite should be:

(ping 127.0.0.1 -c 1 | grep "64 bytes") && echo "Host is up.";

Update: I have updated my previous post.
Ok, I got it. And this would do the opposite:
(! ping 127.0.0.1 -c 1 | grep "64 bytes") || echo "Host is up.";
umm.. no, the NOT (!) should be outside the parenthesis, although I'm no bash expert to know what that eventually should mean.
[root@summer root]# (! ping 127.0.0.1 -c 1 | grep "64 bytes") || echo "Host is up."
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.196 ms
Host is up.
[root@summer root]# !(ping 127.0.0.1 -c 1 | grep "64 bytes") || echo "Host is up."
-bash: !: event not found

Actually in the bash manpage, the ! is referenced 3 times:

In "Pipelines":
If the reserved word ! precedes a pipeline, the exit status of that
pipeline is the logical NOT of the exit status of the last command.

In "Expressions":
example: ! expression
True if expression is false.

In "Parameters":
! Expands to the process ID of the most recently executed back-
ground (asynchronous) command.

Now dont ask me how the shell chooses between the "expressions" context and the "parameters" context.