Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script.sh - need to organize output data

Status
Not open for further replies.

dreamaz

Technical User
Dec 18, 2002
184
CA
Hello,

I have a script that outputs data i need for reporting:

#!/bin/csh
date >> /var/tmp/nat_table_output.out
/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s >> /var/tmp/nat_table_output.out

As per above i get the following output:

Fri Jul 6 22:00:00 EDT 2007
HOST NAME ID #VALS #PEAK #SLINKS
localhost fwx_alloc 8187 17666 30421 0

The first row is date ofcourse, row 2 and 3 are automatically formatted that way by the fw tab command i run for my firewall. Im trying to get the date/time stamp as part of the localhost entry instead of its own row at the top of each entry.. Not sure how this can be done, i have very new to this, but i'd like my outputed data to look like:


DATE HOST NAME ID #VALS #PEAK #SLINKS
Fri Jul 6 21:30:00 EDT 2007 localhost fwx_alloc 8187 17124 30421 0

DATE HOST NAME ID #VALS #PEAK #SLINKS
Fri Jul 6 21:45:01 EDT 2007 localhost fwx_alloc 8187 18880 30421 0

DATE HOST NAME ID #VALS #PEAK #SLINKS
Fri Jul 6 22:00:00 EDT 2007 localhost fwx_alloc 8187 17666 30421 0

SO basically, need to add the DATE title and column, and the date/time stamp under it appended to the table

Hope this makes sense, any help is appreciated.

Thanks,

dR
 
Hi

Code:
/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s [red]| awk 'NR==1{print"DATE",$0;next}{print strftime("%c"),$0}'[/red] >> /var/tmp/nat_table_output.out
You did not explained how would you like it and your sample was not posted with monospace font, so I did not played with the column spacing.

Feherke.
 
Hi

Oops. You are right. I remembered that only [tt]mktime()[/tt] is GNU extension. But seems that all date/time functions are [tt]gawk[/tt] only. Thanks for refreshing my memory.

Feherke.
 
Hi,

Thanks for the response.. I managed to figure out what i want to do and get the right output when i run it manually, but in cron it doesn't run. This is a Nokia box

My script:

#!/bin/csh
echo `date +%Y%m%d%n%H:%M:%S` `/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s | grep 8187` >> nat_table.out

Output of nat_table.out:

DATE TIME HOST TABLE ID CURR PEAK SLINKS
20070707 21:21:41 localhost fwx_alloc 8187 15527 30421 0
20070709 11:11:08 localhost fwx_alloc 8187 19558 30421 0
20070709 11:40:29 localhost fwx_alloc 8187 20485 30421 0

my Cron:

# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.17228 installed on Mon Jul 9 09:38:33 2007)
# (Cron version -- $Id: crontab.c,v 1.3 2001/08/08 17:31:21 ali Exp $)
0,15,30,45 * * * * /var/tmp/shownat.sh

Any ideas why it doens't run in cron?

Any help is appreciated.

Thanks

dR


 
Hi

In such situations most probably the [tt]PATH[/tt] environment variable was not set up the same way as it is when you work with an interactive shell.

Either set up the [tt]PATH[/tt] manually at the beginning of the script, or use absolute paths :
Code:
#!/bin/csh
[red]PATH=$PATH:/usr/bin/[/red]
echo `date +%Y%m%d%n%H:%M:%S` `/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s | grep 8187` >> nat_table.out

[gray]# or[/gray]

#!/bin/csh
echo `[red]/usr/bin/[/red]date +%Y%m%d%n%H:%M:%S` `/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s | [red]/usr/bin/[/red]grep 8187` >> nat_table.out
Assuming that the given binaries are in the /usr/bin/ directory.

Feherke.
 
I added the following which run's manually but not in cron (as per your recommend)

#!/bin/csh
echo `/image/IPSO-3.7.1-BUILD016-09.13.2004-195000-1288/bin/date +%Y%m%d%n%H:%M:%S` `/opt/CPfw1-R55p/bin/fw tab -t fwx_alloc -s | /image/IPSO-3.8.1-BUILD033-05.01.2005-224100-1519/usr/bin/grep 8187` >> nat_table.out

Any suggetions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top