LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need a script that will copy based on filename and then move to a network share when (https://www.linuxquestions.org/questions/linux-newbie-8/need-a-script-that-will-copy-based-on-filename-and-then-move-to-a-network-share-when-757927/)

mrgreaper 09-26-2009 10:15 AM

need a script that will copy based on filename and then move to a network share when
 
Those that have seen my prevouse posts will know im using sabnzbd instead of a vcr so i can use the resaulting files on my netbook at home or on my projector via mediatomb and a ps3.
now originly i was using an archos and the files were converted (thanks to a lot of help from you guys) it made it easy to see what was new what was old by simply looking at the date modified. no archos means no conversion, so i tried to symlink new files, sadly this is not possible due to sabnzbd doing a post processing script then moving the files to there final resting place.
I have hit on a new idea but have no idea where to start so im asking for help again
heres what i need it to do
1)in the post processing script search the $1 (the folder in which sabnzbd places that download to be postprocessed is always $1 i normaly start with dir = $1) using a text file of target names (say monk supernatural psych etc) and if the file has any of these in its name it then moves onto 2
2) copys the file (not move) to a holding folder
3) (this would have to be a script run from cronjob...which scares the hell out of me as i have used cronjob twice and had to reinstall ubuntu to fix it the first time!) then every 15 minutes i want it to see if my net book is connected on wifi ( the relevent folder will be shared ) i want the script to move all the files from the holding folder to the shared folder on the netbook

forceable problems,
3 could move a file thaat 2 is still copying
the netbook could be turned off during the move


ok so is what im asking doable?

mrgreaper 09-26-2009 05:46 PM

ok i have (as always) been googling to learn how to create this script, but i really cant get my head around linuz scripting and in lots of parts i have no idea where to even begin looking.

so far i can think off;

Code:

#!/bin/bash

dir=$1
cd "$dir"
for file in *.avi
do
 cp "$file" /home/mrgreaper/holding/"$file"
done

this would make a copy of all files ..not really perfect but i really have no idea how to get it to read a list of words and only cp the ones with one of those words inside

then the following script executed by cronjob every 30 minutes

Code:

mv /home/mrgreaper/holding/* /network/netbook/work/
im hoping if the network folder is not available then nothing hapens to my files and the script just errors out
oh and /network/netbook/work/ is not the real share as im at work and unable to find out what it would be lol

am i on the right track?
right syntexs?
anyone know a good newbie friendly cron job tutorial or better yet a cronjob gui?

lutusp 09-26-2009 06:14 PM

Quote:

Originally Posted by mrgreaper (Post 3698028)
this would make a copy of all files ..not really perfect but i really have no idea how to get it to read a list of words and only cp the ones with one of those words inside

Do it like this:

Code:

search="search-spec"
path="/path/of/interest"

find $path | grep -iP "\.html?$" | while read filepath
do
  count=$(grep -c "$search" < $filepath)
  if [ $count -gt 0 ]
  then
      echo "$count occurrence(s) of \"$search\" found in \"$filepath\""
      # do something here
  fi
done

1. Change the filename suffix filter (grep -iP "\.html?$") for your own needs.

2. Just add some commands at the location of the comment.

mrgreaper 09-27-2009 08:26 AM

Quote:

Originally Posted by lutusp (Post 3698042)
Do it like this:

Code:

search="search-spec"
path="/path/of/interest"

find $path | grep -iP "\.html?$" | while read filepath
do
  count=$(grep -c "$search" < $filepath)
  if [ $count -gt 0 ]
  then
      echo "$count occurrence(s) of \"$search\" found in \"$filepath\""
      # do something here
  fi
done

1. Change the filename suffix filter (grep -iP "\.html?$") for your own needs.

2. Just add some commands at the location of the comment.

do i just put all the keywords into a file called search-spec?
and replace # do something here eith cp "$file" /home/mrgreaper/holding/"$file"

i think i might need to just stick to having them all copyed, at least at first

if i go to the network share via places it shows the network folder address as smb://icklepc/tv%20programs/ not sure how to use that in my mv script ? i tried cd smb://icklepc/tv%20programs/ and it says it cant find it so im guessing its not treated like a folder damn this is getting complicated

*****************edit***********
i tried cp smb.conf smb://icklepc/tv%20programs/
and got
cp: cannot create regular file `smb://icklepc/tv%20programs/': No such file or directory

im really stuck

chrism01 09-27-2009 07:59 PM

A couple of things that may help:

1. a good cron howto: http://www.adminschoice.com/docs/cro...Crontab%20file
2. to deal with unfinished copies etc, try rsync instead of cp. It's a bit more learning, but it's designed to only copy differences, so it'll check the src & tgt dirs and just send the differences. Quicker and easier than trying to track them yourself and means you don't have to copy entire filesets every time.
HOWTO: http://www.cyberciti.biz/tips/linux-...rectories.html

mrgreaper 09-27-2009 08:18 PM

well after a lot of searching i have got a bit closer

first im going to let the post script copy all avis regardles of names to the holding folder and only enable it for certain tasks (no sense over complicating things)

now the bit im still having issue with the automaticly moving all files from the holding folder to a folder on my net book, i have so far found a sort of method

Code:

cd /home/mrgreaper/holding/
smbclient //icklepc/inbound mypassword
put filename
quit

the problems are multiple, for one i need to know the file name of each file i cant use * (wildcards)
two its only copying not moving

problem one i thought i gould fix with masks and the mput but mask * then mput did not work seems wildcards are nto aloud in masks grrrrrr

ok a possible solution im about to try (im posting before i try as it takes time to get replys and i want to get this fixed so i can sleep tonight and not wake up in the middle of the night with a bright idea that i try to make work for an hour then go back to bed in failure! (i dont just post and wait for a response)

my idea is an adaption of my post processing script and i can already see potential problems but it would serve to move the files

Code:

#!/bin/bash


cd /home/mrgreaper/holding/
for file in *.avi
do
  smbclient //icklepc/inbound mypassword
  put "$file"
  quit
  rm "$file"
done

potential problems include,
1)it attempting to copy a file while the file is being put in to the holding file so it wouldnt copy all of the file
2) this is a biggie, the share not being available so it doesnt copy the file but it still deletes it.

so how do i make it check for the share being in existence before it even trys to copy?

*note*
the rsync command(application) if i understand the page i read will only copy not move have i got that wrong?

chrism01 09-27-2009 08:21 PM

rsync default is to copy, so you'll still have the originals.
There are delete options avail as you'll read, but I'd skip those for now until you've got a solid method working.


All times are GMT -5. The time now is 04:54 PM.