Find the answer to your Linux question:
Results 1 to 4 of 4
Hi all, I searched to find out a few cp scripts that had progress bar, but did not compromise on performance, when my efforts were in vain i went ahead ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    20

    help needed in debugging a cp script!!urgent,pls

    Hi all,

    I searched to find out a few cp scripts that had progress bar, but did not compromise on performance, when my efforts were in vain i went ahead and wrote one of my own ,taking i/p frm other scripts...
    But this is causing some errors and am unable to debug it.....pls help
    Here is the code

    #!/bin/bash

    source=`stat -c %s $1`
    dest=`stat -c %s $2`

    while [ $source -ge $dest ];do
    cp -f $1 $2 &
    pct=$((( $dest * 100) / $source ))
    dest=`expr $dest+1`
    echo "$pct%"
    done

    bash3.2#./copy.sh <file1> <file2>

    Error:
    line 6:[0+1 interger expression expected ] ??
    (Then i get the prompt), bash 3.2#No space left on the device

    What does this mean???

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    can you please run your script as follows and post the output. so we will be able to track the error down.
    Code:
    bash -x ./your_script_name
    here you are trying to compare with the wrong operator. when we get the above output it will be clear.
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    20
    Code:
    + echo 'now starting'
    now starting
    + copy /solaris.zlib /tmp/solaris.zlib
    + '[' 2 = 2 ']'
    ++ /usr/bin/stat -c %s /solaris.zlib
    + source=561624064
    + dest=0
    + '[' 561624064 -gt 0 ']'
    + /usr/bin/cp -f /solaris.zlib /tmp/solaris.zlib
    ++ /usr/bin/stat -c %s /tmp/solaris.zlib
    + dest=0
    ++ /usr/bin/expr '0*100'
    + pct='0*100'
    ++ /usr/bin/expr '0*100/561624064'
    ++ /usr/bin/bc
    + pct1=0
    + echo '0%\c\r'
    0%\c\r
    ++ expr 0+1
    + dest=0+1
    + sleep 1
    + '[' 561624064 -gt 0+1 ']'
    cpy.sh: line 9: [: 0+1: integer expression expected
    This is what it says when i run with the -x opt...
    The error is with the while loop declaration...but i am not sure why?
    Could you pls help?

    However the cp is happenning correctly ..
    I checked it out by copying a audio file from one loc to another,and played the file in the destination...it was working properly

    Thanks

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    the problem is here in the following instruction
    Code:
    dest=`expr $dest+1`
    you did not put spaces around the + sign. so when you execute this bash will replace $dest by its value (0 in this case) and dest will be the string 0+1.
    so in the following comparison you get a compatibility error.
    Linux and me it's a love story

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...