[olug] Unix Tip: SAYING PUT AND EXECUTING ELSEWHERE

Phil Brutsche phil at brutsche.us
Thu Jan 2 21:15:16 UTC 2003


A long time ago, in a galaxy far, far way, someone said...

> What if the program you were running generated a lot of output files you
> didn't want in the current directory?  This way you could run the
> program somewhere else without changing to the directory, running it,
> and then changing back.  The example they gave is almost too simplistic
> -- I have seen convoluted cron jobs that use the ()'s to execute a
> number of programs under a specific directory.

I have also seen (and used) subshells (which using the ()s does) used to
pipe the output of several different commands to a program.  This is a
script I use on firewalls that use DHCP on their WAN interfaces to tell me

1) When they've rebooted
2) What their IP number get's changed to

Beware wrapped lines!

#!/bin/bash
IFACES=`/sbin/ifconfig | awk '/Link encap/ { print $1 }'`
( echo "`hostname` has been rebooted.  Here is the interface
configuration:"
  for VAR in `echo ${IFACES}`; do
    IP=`/sbin/ifconfig ${VAR} | awk '/inet/ { print $2 }' | awk -F: '{
print $2 }'`
    echo "interface ${VAR} has ip ${IP}"
  done ) | mail -s "`hostname` rebooted" phil at giedi.obix.com

-- 

Phil Brutsche
phil at brutsche.us



More information about the OLUG mailing list