Script to capture snoop output

Hi Everyone :),
Need your advice as I'm new to UNIX scripting.. I'm trying to write a script to capture snoop output for 5 minutes for every hour for 24 hours. To stop snoop, I need to press Control-C to break it. This is what I got so far, but now I'm stuck! :confused:

The script:

# cat snoop.sh
#!/bin/ksh
file="/tmp/snoop.`date '+%m%d%y'`"
while true
do
  snoop -P > $file
  if [ -e $file ]
  then
    echo "File created"
    break
  fi
  echo "Snoop completed"
done

Debug:

# ksh -vx snoop.sh
#!/bin/ksh
file="/tmp/snoop.`date '+%m%d%y'`"
+ + date +%m%d%y
file=/tmp/snoop.032110
while true
do
  snoop -P > $file
  if [ -e $file ]
  then
    echo "File created"
    break
  fi
  echo "Snoop completed"
done
+ true
+ snoop -P
+ 1> /tmp/snoop.032110
Using device /dev/ce (non promiscuous)
^C#

Thank you.. :slight_smile:

I have a idea we send the snoop to back ground. Then we can have a separate pid for it.

After 5 mins kill that pid with INT signal ( same as CTRL+C).

#!/bin/bash -x
file=amit123
echo $file
nohup  snoop -P > $file &
sleep 300
echo $!
kill -INT $!

  if [ -e $file ]
  then
    echo "File created"
else
echo "some error occured"
  fi
  echo "Snoop completed"

hi amitranjansahu,
thanks for your help :slight_smile:

"kill -INT $!" is the one I'm looking for..