Results 1 to 2 of 2
Hi
I'm trying to write a bash/shell script to ping a server and redirect part of the output to a file.
The following code does the job:
Code:
#!/bin/sh
date ...
- 09-08-2007 #1Just Joined!
- Join Date
- Oct 2004
- Posts
- 3
Bash script to log ping requests
Hi
I'm trying to write a bash/shell script to ping a server and redirect part of the output to a file.
The following code does the job:
But how do I put the output on a single line, e.g:Code:#!/bin/sh date >> /home/matt/ping.log echo ': ' >> /home/matt/ping.log ping -qc 5 example.com | grep '5 packets' >> /home/matt/ping.log exit 0
Code:Sat Sep 8 20:57:45 BST 2007: 5 packets transmitted, 5 received, 0% packet loss, time 4002ms
- 09-08-2007 #2Just Joined!
- Join Date
- Oct 2004
- Posts
- 3
I figured it out myself:
Code:#!/bin/sh NOW=$(date +"%T %m/%d/%Y") PING=$(ping -qc 5 example.com | grep '5 packets') echo $NOW: $PING >> /home/matt/ping.log exit 0


Reply With Quote