Jump to content

scheduling a cron job to run a script that pings an IP address and save it to a log file


Recommended Posts

I wrote a linux shell script course that ping once an IP address and echoes the results of the ping with the addition of the date command. If I run the script by my self it works just fine and I can also save the script's results to a file with the >> operator like this: script.sh >> log_file. The problem starts when I scheduling it in the crontab editor then only the date command result is saved to a file without the ping result.

my script is:

#!/bin/zsh
echo $(date +"%T %D")
ping -c1 google.com | while read replay
do
 echo $replay
done

and the corn job is:

* * * * * ~/new_scrip.sh >> /tmp/plog

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...