LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 02-25-2013, 04:59 AM   #1
moses0404
LQ Newbie
 
Registered: Feb 2013
Location: Algeria
Posts: 5

Rep: Reputation: Disabled
Setting crontab to ping gateway every minute


im new in Linux and i need help about crontab

i want to plan pinging my gateway every 1 minute but i also want to display a message containing time and redirect the whole result to a file

here is what i typed:
* * * * * ping -c2 192.168.66.1;echo " Done at $(date) " >> ~/pin

but this one gives me only the time and date without ping details


thnx in advance

Last edited by moses0404; 02-25-2013 at 06:07 AM.
 
Old 02-25-2013, 05:17 AM   #2
Kamael
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Rep: Reputation: Disabled
Hi,

Try this:

* * * * * ping -c2 google.co.in >> pingoogle;echo "Done at $(/bin/date)" >> pingoogle

Regards
 
1 members found this post helpful.
Old 02-25-2013, 05:22 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Which OS? Crontab entries may vary depending upon the operating system.
For a linux based system, make entry like:
Code:
*/1 * * * * ping -c2 192.168.66.1; echo "Done at $(date)" >> /path/to/output
Let's know if you're facing any pb or stuck at some point.
 
Old 02-25-2013, 05:30 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909Reputation: 1909
Please use a descriptive title for your thread excluding words like 'urgent' or 'help'. Using a proper title makes it easier for members to help you. This thread has been reported for title modification. Please do not add replies that address the thread title.
 
Old 02-25-2013, 06:21 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,519
Blog Entries: 51

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
Code:
*/1 * * * * /bin/ping -qn -W4 -c2 192.168.66.1 2>&1|xargs -iX /bin/date +"%Y-%m-%d %H:%M:%S X" >> "${HOME}/ping.log" 2>&1
 
1 members found this post helpful.
Old 02-25-2013, 06:38 AM   #6
moses0404
LQ Newbie
 
Registered: Feb 2013
Location: Algeria
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thnx Kamael it is working perfectly

Last edited by moses0404; 02-25-2013 at 06:42 AM.
 
Old 02-25-2013, 06:40 AM   #7
moses0404
LQ Newbie
 
Registered: Feb 2013
Location: Algeria
Posts: 5

Original Poster
Rep: Reputation: Disabled
thnx shivaa am using rhel 6, sorry but ur command gave the exact result as mine
 
Old 02-25-2013, 07:25 AM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by moses0404 View Post
thnx shivaa am using rhel 6, sorry but ur command gave the exact result as mine
I didn't actually modify your command, but crontab entry only. But you can customize command according to your convenience.

Also you can:
Code:
*/1 * * * * ping -c2 www.dummy.com >> /path/to/output && echo "Done at $(date)" >> /path/to/output
 
Old 02-25-2013, 07:56 AM   #9
moses0404
LQ Newbie
 
Registered: Feb 2013
Location: Algeria
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
I didn't actually modify your command, but crontab entry only. But you can customize command according to your convenience.

Also you can:
Code:
*/1 * * * * ping -c2 www.dummy.com >> /path/to/output && echo "Done at $(date)" >> /path/to/output
is it possible to combine these 2 commands with tee i mean: ping>>file|tee file|echo>>file
 
Old 02-25-2013, 09:05 AM   #10
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,778
Blog Entries: 4

Rep: Reputation: 282Reputation: 282Reputation: 282
Yes, tee reads from standard input and writes to standard output and files (as per manual, see here)

But command you've mentioned is not correct. It's a useless use of tee cmd. You can use tee cmd to write/append output of some operation in one or more files simultaneously, like:
Code:
~$ ping www.dummy.com | tee -a file1 file2
In your case, it's not writing output to two or more files, but writing output of two commands to a single file. So tee isn't useful here.

Also once check:
Code:
~$ man tee
~$ info tee

Last edited by shivaa; 02-25-2013 at 09:07 AM.
 
Old 02-25-2013, 09:29 AM   #11
moses0404
LQ Newbie
 
Registered: Feb 2013
Location: Algeria
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Yes, tee reads from standard input and writes to standard output and files (as per manual, see here)

But command you've mentioned is not correct. It's a useless use of tee cmd. You can use tee cmd to write/append output of some operation in one or more files simultaneously, like:
Code:
~$ ping www.dummy.com | tee -a file1 file2
In your case, it's not writing output to two or more files, but writing output of two commands to a single file. So tee isn't useful here.

Also once check:
Code:
~$ man tee
~$ info tee
Je vs remercie pour ttes ces infos
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Crontab in the 3rd minute of the hour px87 Linux - Newbie 2 10-31-2012 05:38 PM
crontab - schedule job to run every minute Hi_This_is_Dev Linux - General 18 04-28-2010 12:52 PM
crontab running twice in a minute saurabhrh Red Hat 4 01-30-2007 07:21 PM
crontab running twice in a minute saurabhrh Linux - General 1 01-30-2007 06:43 PM
want to run program every minute, crontab???? poj Linux - General 4 09-19-2005 04:29 PM


All times are GMT -5. The time now is 08:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration