nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

If file modified execute a script

This is a discussion on If file modified execute a script within the Shell scripting forums, part of the Development/Scripting category; I have some server application running on FC6 but clients loose contact unless they restart client application after server ip ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 11-04-2006, 05:07 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default If file modified execute a script

I have some server application running on FC6 but clients loose contact unless they restart client application after server ip has changed. And it changes once a day I think. I have inadyn running since clients connect to dyndns address but they still can't reconnect unless they restart client tool or I restart server application.
So I was hoping there is a way to run something that would restart server when it notices that inadyn.log file was modified. Since file is modified when it updates to new ip.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-07-2006, 01:54 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Hmm

You need to store your inadyn.log log file current time somewhere. Then you can monitor current time and compare with stored location. If both differ restart the server.

Logic/script:
Code:
#!/bin/sh
file="/path/to/inadyn.log"
fileatime="/etc/current.time"
a=""
b=""
[ ! -f $fileatime ] && stat $file | grep Modify > $fileatime || :
[ -f $fileatime ] && a="$(cat $fileatime)" || exit 1
b="$(stat $file | grep Modify)"
if [ "$a" != "$b" ]; then
   echo "Restart server...."
   # update time
   stat $file | grep Modify > $fileatime 
fi
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 11-17-2006, 11:58 PM
Junior Member
User
 
Join Date: Jun 2006
Posts: 21
Rep Power: 0
karabaja
Default

Ok, thx a lot. I just managed to read reply since I kept getting page not found. But I am glad to see you guys sorted it out.
Reply With Quote
  #4 (permalink)  
Old 11-23-2006, 03:39 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Sorry for trouble. It is now sorted out and you should able to use fourm.
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
shell script for ftp the file vishal_titre Shell scripting 3 12-10-2007 09:40 AM
Make file script, need help understanding shaziluk Shell scripting 0 09-16-2007 04:30 AM
script finding file and sorting dementeddude Shell scripting 14 07-25-2006 06:30 PM
script on how to check if the file exists warren Shell scripting 4 04-14-2006 06:51 PM
#why following cannot be execute? ryan Shell scripting 7 03-16-2005 07:50 PM


All times are GMT +5.5. The time now is 07:06 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36