Like this article? We recommend
Automatically Updating the filesync(1) Files
If your laptop receives a new DHCP address, use the following script to modify the .packingrules file and the .filesync-base file.
CODE EXAMPLE 1 DHCP Script
#! /bin/sh #set -fx # Uncomment this line if you would like to debug this script. # # Filename: changeip.sh # # Availability: Sun only because filesync is a Solaris OE only feature # # Description: This Borne shell script changes the host name in the # two files that the "filesync" command uses. NOTE: The # packing.rules file and the filesync-base file are # created by the filesync command and should not be # edited manually. # # Usage: changeip.sh # # Rev. Programmer Date Changes # ---- --------------- ---------------------------- ----------------------- # 1.0 John Rosander 06/08/2003 Original Implementation # # Known problems: There is no error checking for user input. ############################################################################## FILE1=$HOME/.packingrules FILE1DATE=$HOME/.packingrules.´date '+%m%d%y'´ FILE2=$HOME/.filesync-base FILE2DATE=$HOME/.filesync-base.´date '+%m%d%y'´ # # Remove the date stamped files if run more than once today. # if [ -f $FILE1DATE ] ; then rm $FILE1DATE fi if [ -f $FILE2DATE ] ; then rm $FILE2DATE fi # Backup the old files with a date stamp cp -p $FILE1 $FILE1DATE cp -p $FILE2 $FILE2DATE # # Get input from user # echo "Enter the old host name: " read OLDSTRING echo "Enter the new host name: " read NEWSTRING # # Create a temporary file for use by sed # FILE1TMP=$HOME/.packingrules.tmp FILE2TMP=$HOME/.filesync-base.tmp sed "s/$OLDSTRING/$NEWSTRING/g" $FILE1 > $FILE1TMP sed "s/$OLDSTRING/$NEWSTRING/g" $FILE2 > $FILE2TMP mv $FILE1TMP $FILE1 mv $FILE2TMP $FILE2
On a regular basis, you should delete old copies of the .packingrules and .filesync-base files. For example, if the month is July (that is, 07) and you want to delete the June files (that is, 06), use the following command:
user% rm -i .packingrules.06* .filesync-base.06*
CAUTION
Ensure that you do not delete the mandatory files (that is, .packingrules and .filesync-base) that do not have date extensions.