-2

In the shell script, I will have to access the binary logs stored in /usr/local/mysql/data. but when I do this,

STARTLOG=000002
ENDLOG=000222
file=`ls -d /usr/local/mysql/data/mysql-bin.{$STARTLOG..$ENDLOG}| sed 's/^.*\///'`
echo $file

I get the below error :

ls: cannot access /usr/local/mysql/data/mysql-bin.{000002..000222}: No such file or directory. 

But when I manually enter the numbers in the range the shell scripts runs normally without error.

Rudra
  • 199
  • 2
  • 6
  • 11
  • Which shell are you using in your console session? (i.e. echo $SHELL) in your script? (Usually the first line #!/xxx/xxx) – mdpc Feb 18 '13 at 06:48

1 Answers1

1

Try using seq(1):

file=`ls -d $(seq --format="/usr/local/mysql/data/mysql-bin.%06.0f" $STARTLOG $ENDLOG) | sed 's/^.*\///'`
vonbrand
  • 1,149
  • 2
  • 8
  • 16