LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 10:00 AM   #1
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

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, 10: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, 10:35 AM   #3
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
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 10:41 AM.
 
0 members found this post helpful.
Old 05-23-2010, 01:48 PM   #4
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

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, 02: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 02:25 PM.
 
Old 05-23-2010, 03:10 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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, 06:23 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Just FYI, double brackets ie [[ ]] is preferred http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS
 
Old 05-25-2010, 06: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, 12:45 PM   #9
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

Original Poster
Rep: Reputation: 30
Guru,

u got me.. pls give solution also
 
Old 05-26-2010, 01: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, 01: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 01:26 AM.
 
  


Reply



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 06:19 PM
Crontab Time Differs From Server Time Through Date onesikgypo Linux - Newbie 2 06-08-2009 09:36 AM
Crontab time question thetawaverider Linux - Newbie 3 05-24-2007 10:30 PM
Crontab time afbase Linux - Newbie 5 12-31-2006 09:34 PM
crontab 24-hour time cleopard Linux - General 2 05-09-2006 07:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:31 AM.

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
Open Source Consulting | Domain Registration