Register
It is currently Tue Oct 21, 2014 10:45 am

Script - ping finally answers and cp


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Aug 05, 2009 1:56 pm   

Joined: Wed Aug 05, 2009 1:48 pm
Posts: 2
Hi and welcome (it's my first post),

I have a simple script:

#!/bin/bash
host="192.168.0.1"
ping -c 2 $host 1>/dev/null
num=$?
if [ $num -eq 0 ]; then
exit
else
cp /home/user/backup/test.odt /home/user/Desktop/
DISPLAY=:0.0 /usr/bin/xmessage "Please restart"
fi

Condition is: If ping returns no error exit, if there is error cp test.odt
Script above works.

If the situation will that ping will be with errors (else condition)
i would like to add another condition: if ping finally will be without error cp sth.txt.

Any help?

Regards,

Janusz


Top
 Profile  
 PostPosted: Thu Aug 06, 2009 1:36 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Hi Janusz, welcome to the forum!

It is difficult to understand what you are asking. Would you please explain "if ping finally will be without error"? Do you want to wait for the computer to be restarted and then try to ping again?


Top
 Profile  
 PostPosted: Thu Aug 06, 2009 2:25 am   

Joined: Wed Aug 05, 2009 1:48 pm
Posts: 2
Whata i need sctipt to do is:

In cron script will run every 2 minutes:

1) Check ip if it answers
2) If yes exit
3)if not:

- copy file1.txt
- xmessage notification

If ip finally answers copy file2.txt

Regards,

Janusz


Top
 Profile  
 PostPosted: Thu Aug 13, 2009 11:17 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Why don't you add this to your else:
Code:
else
  cp /home/user/backup/test.odt /home/user/Desktop/
  DISPLAY=:0.0 /usr/bin/xmessage "Please restart"

  sleep 90 s   # Sleep one and a half minutes

  ping -c 2 $host 1>/dev/null   # Try to ping again
  num=$?
  if [ $num -eq 0 ]
    cp /home/.../file2 /home/.../Destination  # Fill in with correct paths
  fi
fi

Since cron will run every two minutes, it doesn't make sense to wait any longer than 90 seconds or so, but any time shorter than that would work.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP