LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
  Search this Thread
Old 05-23-2010, 11:00 AM   #1
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 233

Rep: Reputation: 30
time script without using crontab


hey guys I want to write a ping script that ping a ip after every 60 sec and log output to a file.

but I don want to use crontab for that. pls suggest
 
Old 05-23-2010, 11:19 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
sounds like homework - read the man page for the ping command, it is all there.

man ping
 
1 members found this post helpful.
Old 05-23-2010, 11:35 AM   #3
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 173Reputation: 173
while true
do
sleep 60
ping www.google.com
done

add output loging and run in background

Last edited by yooy; 05-23-2010 at 11:41 AM.
 
0 members found this post helpful.
Old 05-23-2010, 02:48 PM   #4
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 233

Original Poster
Rep: Reputation: 30
hi below script giving error

./keep.sh: line 7: [: missing `]'


[root@localhost sun]# vi keep.sh
HOSTS=192.5.14.1
COUNT=4
while true
do
sleep 60
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [$count -eq 0]; then
echo "Host : $myHost is down (ping failed) at $(date)" >> /var/sun/status
fi
done

what i want is pinging this ip in every 60 secs n recording output to status file
 
Old 05-23-2010, 03:24 PM   #5
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
That is not the answer you want - read through the manual page carefully and consider what the words "interval" and "count" mean in that document. Use a pipe to send the output to a file. It can be done in a single line.

@yooy: you can help people with their homework, but don't do it for them. The idea is they are supposed to learn by working it out themselves as much as possible. You should also check out the solution suggested in the manual and try piping the output to see what happens. See if you cannot do it in one line too.

Last edited by Simon Bridge; 05-23-2010 at 03:25 PM.
 
Old 05-23-2010, 04:10 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by sunlinux View Post
[$count -eq 0]
Put a space between the "0" and "]". BASH understands them as strings, not numbers.

The [ command is an alias for the test command, that expects a "]" as the last argument.
 
Old 05-23-2010, 07:23 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Just FYI, double brackets ie [[ ]] is preferred http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS
 
Old 05-25-2010, 07:19 AM   #8
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Now I'm feeling suspicious. Surely this is a trivial homework problem and you guys are just pulling his leg?

He wants to execute ping 192.5.14.1, a count of four times, at 1min intervals, and pipe the output to a text file. Surely that is just a one-liner off the man page - what's with the while loop? Doesn't ping have an option for that?
 
Old 05-26-2010, 01:45 PM   #9
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 233

Original Poster
Rep: Reputation: 30
Guru,

u got me.. pls give solution also
 
Old 05-26-2010, 02:26 PM   #10
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
you're right Simon, it could be done on just one line :laugh:
OP: man ping :maniacal laugh:
 
Old 05-28-2010, 02:18 AM   #11
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
u got me... pls give solution also
open a terminal and enter:

man ping

read through the options.

I got to be a guru because the people who helped me out here did not spoon-feed me answers. I am paying that favour forward. Note: I know how you feel - it is frustrating. However, it is the only way you will learn.

I am happy to provide the actual answer though, if you can demonstrate that you have read the manual page and are still stuck. Reading the manual is the most fundamental skill for you to learn. In addition, I have all-but spelled it out in post #8.

Have a look at the words I used there and compare with the words used in the manual. Seriously, if you are unable to figure this out, then you have a bad problem.

BTW: It is "you" not "u" and "please" not "pls". Are you really posting from a cell phone? This sort of writing just makes you look lazy - and your continued refusal to look at the manual only confirms this. If you can't be bothered even to write whole words, why would you expect anyone else to bother to write whole answers?

Last edited by Simon Bridge; 05-28-2010 at 02:26 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 07:19 PM
Crontab Time Differs From Server Time Through Date onesikgypo Linux - Newbie 2 06-08-2009 10:36 AM
Crontab time question thetawaverider Linux - Newbie 3 05-24-2007 11:30 PM
Crontab time afbase Linux - Newbie 5 12-31-2006 10:34 PM
crontab 24-hour time cleopard Linux - General 2 05-09-2006 08:24 AM


All times are GMT -5. The time now is 04:28 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration