#! /bin/bash
LOCKFILE="/tmp/seedbox.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents/seedbox/
TMST=$SRC.timestamp
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
for f in `ssh $RMT "find "$SRC"* -type d -newer $TMST && \
find "$SRC"* -type f -maxdepth 0 -newer $TMST && \
find "$SRC2"* -type d -newer $TMST && \
find "$SRC2"* -type f -maxdepth 0 -newer $TMST"`
do
scp -r $RMT:$f $DST
done
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
for d in `$FIND "$DST"* -type d`
do
for r in `$FIND $d -name "*.rar*"`
do
unrar e -r -inul $r $d
done
done
for d in `$FIND "$DST"* -type d`
do
for r in `$FIND $d -name "*.rar*"`
do
unrar e -r $r $d;rm "$d"/*.r??; mv $d "$DST"Done
done
done
./seedbox.sh: line 23: /tank/nas/dump/torrents/seedbox/Caprica.S01E06.720p.HDTV.x264-CTU: cannot execute [Is a directory]
#! /bin/sh
LOCKFILE="/tmp/seedbox.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents/seedbox/
TMST=$SRC.timestamp
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
for f in `ssh $RMT "find "$SRC"* -type d -newer $TMST && \
find "$SRC"* -type f -maxdepth 0 -newer $TMST && \
find "$SRC2"* -type d -newer $TMST && \
find "$SRC2"* -type f -maxdepth 0 -newer $TMST"`
do
scp -r $RMT:$f $DST
done
for d in `$FIND "$DST"* -type d`
do
for r in `$FIND $d -name "*.rar*"`
do
unrar e -r $r $d;rm "$d"/*.r??; mv $d "$DST"Done
done
done
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
#! /bin/sh
LOCKFILE="/tmp/seedbox.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents/seedbox/
TMST=$SRC.timestamp
FIND=/usr/gnu/bin/find
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
for f in `ssh $RMT "find "$SRC"* -type d -newer $TMST && \
find "$SRC"* -type f -maxdepth 0 -newer $TMST && \
find "$SRC2"* -type d -newer $TMST && \
find "$SRC2"* -type f -maxdepth 0 -newer $TMST"`
do
scp -r $RMT:$f $DST
done
for d in `$FIND "$DST"* -type d`
do
for r in `$FIND $d -name "*.rar*"`
do
unrar e -r $r $d;rm "$d"/*.r??; mv $d "$DST"Done
done
done
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
IFS='
'
sixtydoses said:Try to add this in your script.
Code:IFS=' '
[od@meh ~/temp]$ ls -l
total 2
-rw-r--r-- 1 od od 0 Mar 7 21:51 white space
drwxr-xr-x 2 od od 512 Mar 7 21:52 white space dir
[od@meh ~/temp]$ srcf=`ls`
[od@meh ~/temp]$ echo $srcf
white space white space dir
[od@meh ~/temp]$ cp -vR $srcf ../dst/
cp: dir: No such file or directory
cp: space: No such file or directory
cp: white: No such file or directory
cp: space: No such file or directory
cp: white: No such file or directory
[od@meh ~/temp]$ IFS='
> '
[od@meh ~/temp]$ cp -vR $srcf ../dst/
white space dir -> ../dst/white space dir
white space -> ../dst/white space
[od@meh ~/temp]$ ls -l ../dst
total 2
-rw-r--r-- 1 od od 0 Mar 7 21:55 white space
drwxr-xr-x 2 od od 512 Mar 7 21:55 white space dir
sixtydoses said:Add it before you do the copying. Sorry, I can't make your script to work, but I've faced this white space problem before.
Example:
Code:[od@meh ~/temp]$ ls -l total 2 -rw-r--r-- 1 od od 0 Mar 7 21:51 white space drwxr-xr-x 2 od od 512 Mar 7 21:52 white space dir [od@meh ~/temp]$ srcf=`ls` [od@meh ~/temp]$ echo $srcf white space white space dir [od@meh ~/temp]$ cp -vR $srcf ../dst/ cp: dir: No such file or directory cp: space: No such file or directory cp: white: No such file or directory cp: space: No such file or directory cp: white: No such file or directory [od@meh ~/temp]$ IFS=' > ' [od@meh ~/temp]$ cp -vR $srcf ../dst/ white space dir -> ../dst/white space dir white space -> ../dst/white space [od@meh ~/temp]$ ls -l ../dst total 2 -rw-r--r-- 1 od od 0 Mar 7 21:55 white space drwxr-xr-x 2 od od 512 Mar 7 21:55 white space dir
DutchDaemon said:Use double quotes around variables to include whitespace literally.
So not $FILE, but "${FILE}". The curly braces prevent interaction with adjacent characters which may make the script not recognise a variable when it's called (e.g. PATH=/usr/ ; cd $PATHsrc -- this should be ${PATH}src)
scp -r ${RMT}:$f ${DST}
scp -r ${RMT}:"\"$f\"" ${DST}
#! /bin/sh
LOCKFILE="/tmp/seedbox.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents/seedbox/
TMST=$SRC.timestamp
FIND=/usr/gnu/bin/find
IFS='
'
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
for f in $(ssh $RMT "find ${SRC}* -type d -newer $TMST && \
find ${SRC}* -type f -maxdepth 0 -newer $TMST && \
find ${SRC2}* -type d -newer $TMST && \
find ${SRC2}* -type f -maxdepth 0 -newer $TMST")
do
scp -r ${RMT}:"\"$f\"" ${DST}
done
for d in $($FIND ${DST}* -type d)
do
for r in $($FIND $d -name "*.rar*")
do
unrar e -r $r $d;rm ${d}/*.r??; mv ${d} ${DST}Done
done
done
for m in $($FIND ${DST} -maxdepth 1 -name "*.avi" -o -name "*.mkv")
do
mv $m ${DST}Done
done
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
# store original IFS and assign a different value to it
OLDIFS=$IFS
IFS='
'
# do whatever you want here
# reset it back
IFS=$OLDIFS
wonslung said:to make it get paste the whitespace issue....but that breaks stuff with "'s in it.....i think the ultimate issue is that using the `'s are bad.
I tried to fix that by using this: $( ) but it didn't help much
sixtydoses said:Sorry I don't really understand.. you were saying you're having problems transfering files "'s" in it? Something like, "some movie's.rar"?
scp -r remoteserver:"\"file name with whilespace\"" Destination
for r in $($FIND $d -name "*.rar*")
LiMPiNg said:First, I would like to thank you wonslung for all the work you have put in this script already. I was looking for something similar to use on my FreeNAS server, without the copying from the seedbox - I just want it to automatically extract files from my download directory to another directory of extracted files. Being a FreeBSD/UNIX rookie, I stumbled my way through it and have it working how I want... almost!
What do you do for archives that have .partXX.rar filenames instead of .rXX? ie, xxxx.part01.rar, xxxx.part02.rar . I ran into such a torrent, which is not uncommon, and it threw the whole script off due to all the .rar files in the dir. I would love to figure this out on my own, but I know nothing about scripting and simply modified yours to fit my needs.
I know the following code is what needs to be worked on for this.
Code:for r in $($FIND $d -name "*.rar*")
I am guessing having it do an if search for a part01.rar and extract that if it exists and then do an else to process the single .rar if there is no part01.rar is the key, but how to implement that exactly is beyond my limited scripting abilities. Any help would be appreciated.
#! /bin/sh
LOCKFILE="/tmp/seedbox.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents/seedbox2/
TMST=$SRC.timestamp
LOG=/export/home/wonslung/log/rsync.log
IFS='
'
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
ssh $RMT "find ${SRC}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
rsync -aveL ssh ${RMT}:/home/wonslung/sync $DST >> $LOG
rsync -aveL ssh ${RMT}:/home/wonslung/sync $DST >> $LOG
rsync -aveL ssh ${RMT}:/home/wonslung/sync $DST >> $LOG
ssh $RMT "find /home/wonslung/sync -type l -exec rm '{}' \;
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
#! /bin/sh
LOCKFILE="/tmp/.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents2/
TMST=$SRC.timestamp
LOG=/home/wonslung/log/rsync.log
IFS='
'
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
ssh $RMT "find ${SRC}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
ssh $RMT "find /home/wonslung/sync -type l -exec rm '{}' \;"
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
#! /bin/sh
LOCKFILE="/tmp/.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents2/
TMST=$SRC.timestamp
LOG=/home/wonslung/log/rsync.log
IFS='
'
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
link() {
ssh $RMT "find ${SRC}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
}
link
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
link
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
ssh $RMT "find /home/wonslung/sync -type l -exec rm '{}' \;"
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"
#! /bin/bash
LOCKFILE="/tmp/.lockfile"
RMT=wonslung@seedbox.example.com
SRC=/home/wonslung/Complete/TV/
SRC2=/home/wonslung/Complete/Movies/
DST=/tank/nas/dump/torrents2/
TMST=$SRC.timestamp
FIND=/usr/gnu/bin/find
LOG=/home/wonslung/log/rsync.log
IFS='
'
if [ -f $LOCKFILE ]
then
echo "lockfile, exiting"
exit 0
else
touch $LOCKFILE
fi
link() {
ssh $RMT "find ${SRC}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type d -maxdepth 0 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
ssh $RMT "find ${SRC2}* -type f -maxdepth 1 -newer $TMST \
-exec ln -s '{}' /home/wonslung/sync \;"
}
link
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
link
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
link
rsync -Lave ssh ${RMT}:/home/wonslung/sync/ $DST >> $LOG
shopt -s extglob
for dir in ${DST}*/
do
cd "$dir" && $FIND . -type f -name '*.rar' \( ! -name 'part*.rar' -o -name 'part01.rar' \) -exec unrar e {} \;
done
for g in ${DST}*/
do
rm ${g}*.r?? ${g}*.sfv ${g}*.nfo
done
$FIND ${DST}* -maxdepth 0 -type d -exec mv {} /tank/nas/dump/Done \;
ssh $RMT "find /home/wonslung/sync -type l -exec rm '{}' \;"
rm -f $LOCKFILE ; ssh $RMT "touch $TMST"