Title:Using backticks in PHPContributor: Randall Goguen (aka Ranman)
Last Update: Thusay June 22 02:00 EDT
Example 1:# Get just the uptime from the uptime command.
<?= `uptime | awk '{print $3;}'` ?>
Example 2:# Get your IP.
<?= `/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | \
awk '{print $2;}' | awk -F':' '{print $2;}'` ?>
Example 3:# Get all but just the httpd proccess.
<?= `ps -ef | grep httpd | awk '{print $2}'` ?>
Example 4:# List only files.
<pre><?= `ls -l | grep "^-"` ?></pre>
# or
<pre><?= `ls -l | grep "^-" | awk '{print $9;}'` ?></pre>
Example 5:# Count only files.
<?= `ls -la |grep "^-" |awk 'END {print "Number of files: " NR}'` ?>
Example 6:# List only directorys.
<pre><?= `ls -l | grep "^d"` ?></pre>
# or
<pre><?= `ls -l | grep "^d" | awk '{print $9;}'` ?></pre>
Example 7:# Count only directorys.
<?= `ls -la |grep "^d" |awk 'END {print "Number of directories: " NR}'` ?>
Example 8:# Find a file or directory.
<?
$file_name = "named.conf";
$directory_name = "/etc";
echo `find $directory_name -name $file_name -printf "Found file: %p "`
?>
Example 9:# Count how many lines in a file.
<?= `wc -l /etc/named.conf` ?>
Example 10:# Ping a IP twice.
<pre><?= `ping -c 2 127.0.0.1` ?></pre>
Anyone who wishes to make additions or changes to this
PHP Tip email them to webmaster@linuxguruz.org
This document is Copyright (c) 1999, 2000 by LinuxGuruz