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:

echo $(date +"%T %D")
ping -c1 google.com | while read replay
 echo $replay

and the corn job is:

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

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...