Operating System - HP-UX
1847211 Members
2286 Online
110263 Solutions
New Discussion

please help interpret script

 
Chern Jian Leaw
Regular Advisor

please help interpret script

Hi,
I have the script attached which I found from some website. It does not have documentation on it and the comments are not very helpful.

It's basically suppose to rsync a group of filesystems from 1 host machine onto another host machine having the same filesytem structure.

Can someone please help me interpret the portions in the script which have comments in uppercases?

Thanks.
3 REPLIES 3
Wodisch_1
Honored Contributor

Re: please help interpret script

Hi,

the part you marked is only about options. That loop is entered if and only if the script was started with command-line parameters - some of them might be options, some might be data.
"getopt" is a useful function to parse the command-line (i.e. $* are the words of the command-line following your script's name) for options (i.e. starting with a "-" = minus).
The only options that script is interested in are the single-character options "d", and "h", and "n".
If one is found, a shell-variable is set appropriately and then it is deleted from the parameter-list (upon "-h" the script exits, of course).

As an example take the command-line like this:

script -d -n aaa bbb ccc

Then that loop turns it into:

script aaa bbb ccc

but now the shell-variables $RSYNC_DEBUG and $RSYNC_DRY_RUN are set (they were empty before).

So the rest of your script can use "$*" without having to care about options any more.

HTH,
Wodisch
Chern Jian Leaw
Regular Advisor

Re: please help interpret script

Wodish,

Thanks for the reply. I was wondering if you help interpret the block of code below, taken from the script.

I do not quite understand the statement about the combination of grep and sed.

### NEED HELP HERE TILL THE END !!!!! ################

my_exclude_options=`cat $RSYNC_DATA_DIR/$EXCLUDE_FILE|grep -v '^'#|grep $dirs|sed "s/^archive\/$dirs\///g"`


# If we want to use the switch "--exclude-from="
my_exclude_file="/var/tmp/${dirs}_excluded_file"
if [ -f $my_exclude_file -o -d $my_exclude_file ]; then
/bin/rm -fr $my_exclude_file
fi
touch $my_exclude_file
for file in $my_exclude_options
do
echo $file >> $my_exclude_file
done

EXCLUDE_OPTIONS="--exclude-from=$my_exclude_file"


Thanks.
Paula J Frazer-Campbell
Honored Contributor

Re: please help interpret script

Hi

The line :-

my_exclude_options=`cat $RSYNC_DATA_DIR/$EXCLUDE_FILE|grep -v '^'#|grep $dirs|sed "s/^archive\/$dirs\///g"`


The grep -v is excluding ('^'#|) see man grep and the attached will help with sed.

Paula
If you can spell SysAdmin then you is one - anon