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 |
sounds like homework - read the man page for the ping command, it is all there.
man ping |
|
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 |
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. |
Quote:
The [ command is an alias for the test command, that expects a "]" as the last argument. |
Just FYI, double brackets ie [[ ]] is preferred http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS
|
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? |
Guru,
u got me.. pls give solution also |
you're right Simon, it could be done on just one line :laugh:
OP: man ping :maniacal laugh: |
Quote:
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? |
All times are GMT -5. The time now is 03:10 AM. |