LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-26-2009, 10:15 AM   #1
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Rep: Reputation: 15
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?
 
Old 09-26-2009, 05:46 PM   #2
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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?
 
Old 09-26-2009, 06:14 PM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by mrgreaper View Post
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.
 
Old 09-27-2009, 08:26 AM   #4
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by lutusp View Post
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

Last edited by mrgreaper; 09-27-2009 at 09:18 AM.
 
Old 09-27-2009, 07:59 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,264

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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
 
Old 09-27-2009, 08:18 PM   #6
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
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?
 
Old 09-27-2009, 08:21 PM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,264

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM
[SOLVED] Bash Script to copy files to SAMBA Share bskrakes Linux - Newbie 4 07-03-2008 07:51 AM
Problems with script to mount network share snowman81 Programming 2 04-25-2008 09:58 PM
problems with script writing to network share neocookie Linux - Newbie 2 03-22-2007 05:44 AM
Script to move directories based on first letter to a new directory of that letter tworkemon Linux - Newbie 8 01-30-2007 07:18 PM


All times are GMT -5. The time now is 12:42 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration