LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-01-2012, 10:46 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
Bash alternative to rsync?


Hi,

Under live, busybox, ... in a limited distro, it helps. Here a beginning of code.

Code:
#!/bin/sh  


echo "#############################################"
echo "SHELL : $SHELL"
echo "BASH : $BASH"
echo "TERM : $TERM"
DATENOW=`date +%Y%m%d-%H%M%S` 
# last argument
LASTARG=`echo "$@" | awk ' { print $NF  }  '`
# penultimate argument
num_args=$# 
num_args_max=$num_args
let num_args=$num_args-1 
PENUARG=` echo "$@" | awk -v vk=$num_args ' { print $vk  }  ' `
TRG="$LASTARG"
echo "#############################################"







ProcedureStartCopyOneFile() {
  echo "*** COPY ***"
  echo "File not exists : $FILETRG" >> ~/.config/bashmv/bashmv.log
  echo -en "\r Copying ($i) (...)"
  echo "$i" | cpio -pvdmu "$TRG"
  echo -en "\r Copied ($i)."
  TRSS=` du -hs "$FILETRG" --apparent-size | cut -f 1 `
  SRSS=` du -hs "$i" --apparent-size | cut -f 1 ` 
  if  [ ! -d  "$i" ] &&  [ "$SRSS" != "$TRSS" ] ; then 
    echo "Different size: $FILETRG"
    echo "** WARNING **"
    echo "Different size: $FILETRG" >> ~/.config/bashmv/bashmv.log
    echo "** WARNING **" >> ~/.config/bashmv/bashmv.log
    exit
  else
    echo -en "\r Copied ($i) [OK]"
  fi
  echo "*** COPY OK ***"
  echo ".*.*"
}







ProcedureCopying() {

 echo "> Parameters: Source: $SRC  => Target: $TRG"


if [ -f "$SRC" ] || [  -d "$SRC" ] ; then 
  echo "Source: $SRC"
else
  echo "Directory or file source $SRC not found."
  exit
fi

if [ "$TRG" = "" ] ; then 
  exit
fi





if [ "$BASH" != "/bin/bash" ] ; then
  echo "Warning: You should use BASH : /bin/bash !"
  exit
else 
  echo "Intpreter BASH: $BASH [OK] "
fi




echo "** START ** "
[ ! -d ~/.config/bashmv ] && mkdir -p ~/.config/bashmv




[ ! -d  "$TRG" ] && mkdir -p "$TRG"
if [ "$LASTARG" = "--debug" ] ; then
  find "$SRC" -print
  exit
fi

find "$SRC" -print | grep -v "^$\|^#" | while read -r i ; do 
# echo "Processing $i"

FILETRG="${TRG}/${i}"
DATENOW=`date +%Y%m%d-%H%M%S` 
echo "> Start: .*.* ($i)"
if [ !  -f "$FILETRG" ] && [ ! -d  "$i"  ] ; then 
  echo ".*.*"
  echo "*** COPY ***"
  echo "File not exists : $FILETRG" >> ~/.config/bashmv/bashmv.log
  echo "$i" | cpio -pvdmu "$TRG"
  TRSS=` du -hs "$FILETRG" --apparent-size | cut -f 1 `
  SRSS=` du -hs "$i" --apparent-size | cut -f 1 ` 
  if  [ ! -d  "$i" ] &&  [ "$SRSS" != "$TRSS" ] ; then 
    echo "Different size: $FILETRG"
    echo "** WARNING **"
    echo "Different size: $FILETRG" >> ~/.config/bashmv/bashmv.log
    echo "** WARNING **" >> ~/.config/bashmv/bashmv.log
    exit
  else
    echo "Copied ($i) [OK]"
  fi
  echo "*** COPY OK ***"
  echo ".*.*"


elif [  -d "$i" ] ; then
  mkdir -p "$FILETRG"
  echo "Creating $FILETRG"

elif [ ! -d "$i" ] ; then
  TRSS=` du -hs "$FILETRG" --apparent-size | cut -f 1 `
  SRSS=` du -hs "$i" --apparent-size | cut -f 1 ` 
  # echo "Source: $SRSS vs $TRSS"


  if  [ -d  "$i" ] ; then
    echo "Directory."
  fi

  if  [ ! -d  "$i" ] ; then
    if [ -f "$FILETRG" ] && [ "$SRSS" = "$TRSS" ] ; then 
      echo "file $FILETRG exists. [Same size]"
    fi

    if   [ "$SRSS111kkk" = "$TRSS" ] ; then 
      echo "Different size: $FILETRG"
      echo "** WARNING **"
      echo "Different size: $FILETRG" >> ~/.config/bashmv/bashmv.log
      echo "** WARNING **" >> ~/.config/bashmv/bashmv.log
      FILETRGERROR="${TRG}/Error/${i}"
      [ ! -d  "$TRG/Error" ] && mkdir -p "$TRG/Error"
      echo "$TRSS" | cpio -pvdmu   "$TRG/Error/${DATENOW}-${i}"
    fi
  fi
fi



done

echo "Finished!"


if [ "$LASTARG" = "--rm" ] ; then 
  echo "Delete the directory: $SRC [y/n] ? "
  read inpud
  [ "$inpud" = "n" ] && exit
  rm -rf "$SRC"
fi


exit
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux remote backups, alternative to rsync? Alize Linux - Server 10 01-02-2018 06:02 PM
Bash alternative to wget -r? Xeratul Programming 9 12-01-2012 10:02 AM
An alternative to rsync? Skaperen Linux - Software 4 11-04-2012 10:20 AM
Using Alternative (non-Bash) Shells Completely Clueless Linux - General 2 07-16-2009 10:07 AM
rsync using alternative ssh port va1damar Linux - Networking 5 01-29-2007 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration