0

I am trying to write a script which will copy a range of files. The range values are picked up from two different files using grep,awk, and cut commands.

The file names that I want to copy are in the range like this: MYSQLTEST_binlog.000001 to MYSQLTEST_binlog.001536.

I pickup the first range as follows:

XX=`head -30 /data/backup.sql | grep -w 'MYSQLTEST_binlog.*' | awk -F "." '{ print $2 }' | cut -f1 -d "'"`

XX value is, let's say 000055.

I pickup the range value in an another variable as follows:

YY=$(ls -l /data/mysql_data_dir/MYSQLTEST_binlog.* | grep -v index | tail -n 1 | awk -F "." '{ print $2 }')

YY value is, let's say 001536. These values are being picked up correctly.

Now I am trying to pass these values to the cp command as follows:

cp -ar /data/mysql_data_dir/MYSQLTEST_binlog.{$XX..$$YY} /data/binlog

And I receive cp cannot stat /data/mysql_data_dir/MYSQLTEST_binlog.{000050..001536}.

It doesn't consider these values to be a range.

Following is my script:

#!/bin/bash

XX=$(head -30 /data/mysql_data_dir/backup.sql | grep -w 'MYSQLTEST_binlog.*' | awk -F "'" '{ print $2 }') ; echo $XX

YY=$(ls -l /data/mysql_data_dir/MYSQLTEST_binlog.* | grep -v index | tail -n 1 | awk -F "." '{ print $2 }') ; echo $YY

cp -ar /data/mysql_data_dir/MYSQLTEST_binlog.{$XX..$YY} /data/binlog