problem getting ipfw output

Hi

I'm in trouble, I want to get the output of [cmd=]ipfw show[/cmd] and write it to a plain file, I'm trying it with this:

Code:
#!/bin/sh
VAR=`ipfw show|grep count|grep in|awk '{print $3}'`
echo $VAR >> file

The strange thing is that if I run it manually ($ sh script) it works, but if I cron the script each minute my file just receives a blank line without the number that I need.
 
Keep in mind that cron uses a limited PATH. Use the fully qualified names for commands. Like /sbin/ipfw instead of just ipfw.
 
SirDice said:
Keep in mind that cron uses a limited PATH. Use the fully qualified names for commands. Like /sbin/ipfw instead of just ipfw.

I've done it, in my cron I have:

Code:
*/1 * * * * /bin/sh /usr/local/www/data/script

and in the sccript

Code:
#!/bin/sh
IPF=`which ipfw`
VAR=`$IPF show | grep count | grep in |awk '{print $3}'`
and the behaviour is the same.
 
The ipfw(8) command is writing its messages to stderr so you need to write your pipelines with redirections like this:
# ipfw show 2>&1 | grep ...
 
kpa said:
The ipfw(8) command is writing its messages to stderr so you need to write your pipelines with redirections like this:
# ipfw show 2>&1 | grep ...

It didn't work for me

My crontab:
Code:
*/1 * * * * /bin/sh /usr/local/www/data/script

My script:
Code:
#!/bin/sh
CMD=`which ipfw`
INDATA=`$CMD show 2>&1 | grep count | grep in | awk '{print $3}'`
echo "$INDATA" >> file

My /etc/crontab:
Code:
SHELL: /bin/sh
PATH:..:/bin:...

Any comment?
 
For sh(1)-based shells:
Code:
/sbin/ipfw show >> /path/to/file.txt 2>&1

>> sends standard output to /path/to/file.txt
2>&1 sends standard error (2) output to the same location as standard (1) output.
 
phoenix said:
For sh(1)-based shells:
Code:
/sbin/ipfw show >> /path/to/file.txt 2>&1

>> sends standard output to /path/to/file.txt
2>&1 sends standard error (2) output to the same location as standard (1) output.

heyyy, many thanks, you helped me a LOT !

but it was strange, because i didn't need to use 2>&1, but in your reply you posted a detail, the ".txt", so what I did is:

Code:
VAR=`/sbin/ipfw show | grep count | grep in | awk '{print $3}'`
echo "$VAR" >> /path/file.txt

and it worked fineeee

thanks !

PD: smallest details can made a difference
PPD: I formated my reply :D

-------------------------

sadly I have to edit

it works just for one single line

my idea is to do:
Code:
#!/bin/sh
CMD=`which ipfw`
INDATA=`$CMD show 2>&1 | grep count | grep in | awk '{print $3}'`
OUTDATA=`$CMD show 2>&1 | grep count | grep out | awk '{print $3}'`
echo "$INDATA" >> file 2>&1
echo "$OUTDATA" >> file 2>&1
 
Back
Top