• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Monday, November 2, 2009

Posted by venu k
2 comments | 4:21 AM
This script not replaces cp command. This is a sample script for practice purpose.
I am going to develop more elegant script, which fulfil most of the cp command strengths.
I will post complete version of the script as soon as possible,
I shall really appreciate all comments and suggestions to improve this script.

#!/bin/bash
#
# SCRIPT: ddcopy_progress.sh
# PURPOSE: This script is used to watch progress of copying.
#
# Note: I am using destination file as $$.temp .This is because,
# after testing you can easily delete temp files using
# rm -f *.temp

#############################################
# Arguments Checking #
#############################################

if [ $# -ne 1 ] # Look for exactly one parameter
then
echo "..............Usage Error........."
echo "Usage: $0 Sourcefil"
exit 1
fi

if [ ! -e $1 ] # Check source file exist or not
then
echo "File $1 not exist"
exit 1
fi

#############################################
# DEFINE VARIABLES HERE #
#############################################

Seek=0 # Skip BLOCKS bs-sized blocks at start of output
Skip=0 # Skip BLOCKS bs-sized blocks at start of input
Bsize=128000 # Block size
size=`stat -c %s $1`
blocks=$((size/Bsize)) # Total blocks of input file

lastblock=$((size%Bsize)) # Last block, which size < $Bsize

# If last block size is > 0 then add 1 block to existing blocks.

if [ $lastblock -gt 0 ]
then
let blocks++
fi

# I am dividing screen width 60 as 20 parts.Each part is filled with color
# after each iteration.

# Make blocks count dividable by 20.

addblocks=$((blocks%20))
if [ $addblocks -gt 0 ]
then
adjustblocks=$((20-addblocks))
blocks=$((blocks+adjustblocks))
fi

Count=$((blocks/20))

# Count variable contain number of blocks to be copied for each iteration

###############################################
# MAIN PROGRAM STARTS HERE #
###############################################

printf "\e[40m\e[43m%60s\n\e[A" " "

for ((i=1;i<=20;i++))
do

dd if=$1 of=$$.temp bs=128kB seek=$Seek skip=$Skip count=$Count 2>/dev/null
Skip=$((Skip+$Count))
Seek=$((Seek+$Count))
j=$((j+3)) # 60/20 each part is 3 chars length
printf "\e[40m\e[7m%${j}s\n\e[A" " "
# echo -e "\033[7m \c"
# sleep 1 # Uncomment it for small files

done
printf "\e[0m\n"
#echo -e "\033[0m"

Output:
Screen Shot1:

Screen Shot2:

Screen Shot3:

Screen Shot4:

Observation:
I tested above script with different block count.But I didn't get accurate result.
Some times less count script given good result, some times more block count given
good result.
I copied 1.8 GB Movie file with this script.With time command it has give bellow
result.

real 1m12.646s
user 0m0.043s
sys 0m7.854s

From my observation this script has taken less time compared with mouse copy and
paste method. Copy and paste has taken 1m14.02s averagely.

2 comments:

  1. You Could even compare it with ordinary CLI commands like cp and dd without block size as well to see the difference in time.

    Also you should allow usage of a target filename to make the script really usable.. Right now just copying to a filename.temp is useless and works only as a demo of progress bar feature..

    ------
    Tuxopia | Land of Opensource

    ReplyDelete
  2. Thank you Sam
    I mentioned at the beginning of the script, this is not a complete version.
    I will post it shortly. I posted this sample script because I didn't get much difference b/w increasing and decreasing blocks count. But there is a difference among block sizes. I think if anyone has any idea will suggest me.

    ReplyDelete