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 04-27-2010, 12:05 PM   #16
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195

Quote:
Originally Posted by mrgreaper View Post
true, it just frustrates me i can see what i want it to do is possible, but cant figure it out

i spent an entire shift at work then 3 hours at home yeasterday and since i got up 5 hours ago today, looking for the solution and im no where close to finding it.

[snip]

seems so simple and would save me a lot of time
It is a relatively simple task but nothing is simple when you are starting out and the task is anyway not small, only simple! I suggest you do not rush it and risk burning yourself out and getting frustrated; better settle down to enjoy a learning adventure and lean on the help available here. You are off to a good start with the high level pseudo-code and first draft script.

Now for your specific questions. I'll try one per post, hoping to keep the question/answer dialogue flowing more easily.

Q: (how to) check the smb share is on the network and exit if its not.

As EricTRA wrote, SMB is not the best choice for an all-Linux installation but that's what you have so ...

I used The Official Samba 3.5.x HOWTO and Reference Guide for information to explore and develop this code, working initially at the command line to familiarise myself with the commands and their output and then put it in a script. Took quite a while (maybe 2 hours). Already knew that smbclient -L could be used to list shares but had problems around authentication/passwords lanman/ntlmv2 until found smbclient's -N option (don't prompt for password).

Wondered about testing whether the share's host was on the network (using nmlookup and ping) but decided against - all you need to know is whether the share is online.

So -- here is a script snippet to do the job
Code:
#!/bin/bash

# Configuration
smb_server_name=CW8
smb_share_name=WXPsoftlib

# Test share availability
case $( smbclient -L "$smb_server_name" -N 2>/dev/null ) in
    *"$smb_share_name"* )
        ;;
    * )
        echo "//$smb_server_name/$smb_share_name not found" >&2
esac
Notes:
  1. $( <some command> ) is replaced by what it writes to standard output.
  2. 2>/dev/null sends standard error to the void, in this case a couple of headers we are not interested in.
  3. This is not robust code -- it would fail if the share name matched another string in smbclient's output -- but I wanted to keep it simple.
 
Old 04-27-2010, 01:59 PM   #17
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
I believe NFS is the way to go here and it will then just appear as part of your system, once mounted of course

here is a link from a quick search which seems to lay out what you will need:

http://mybeni.rootzilla.de/mybeNi/20..._ubuntu_linux/

Let me know how you get on

fantastic little guide, i gave it a fast try before work and the mounted folder had a permission error but im sure i can fix that with some reading of the mount manual(once im back home) and this has solved the first problem of the script

im bad at explaining but i can see how i can use the mount command to fix the detection part thusly;
Code:
#!/bin/sh

#this section will check to see if the netbook is connected to the network and if it is then it will continue if not it will exit

#first mount the folder
sudo mount 192.168.1.116:/mrgreaper2004/Tv /home/mrgreaper2004/testfold/

#now in the folder on the netbook will be a folder called unlock, if the mount was succesful that folder would exist in the mountpoint yes? so if we check and find it then that means its mounted and available, dont find it and that means the mount has failed(proberly due to a couple of miles between me and the network)

folder=/home/mrgreaper2004/testfold/unlock/
 
if [ -d $folder ];
then
   echo "script says $folder exists success"
else
   echo "$folder cant be found..fail" | exit
fi
have i got that right? cant really test it but it seems sound logic to me... if the mount succeded there would be an unlock folder in the mount folder if not then there wouldnt be.
the array looks like what i was trying to do with out knowing i was trying it lol and i can get my head round that easier then loops
if im not doing a loop 3a is not relevent
3b and 4 completely lose me

the help is greatly appreciated
 
Old 04-27-2010, 07:48 PM   #18
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
ok script failure 2.0 lol

Code:
#!/bin/sh

#this section will check to see if the netbook is connected to the network and if it is then it will continue if not it will exit
#yeah i have no idea how to do it ...i know the exit command..its exit
# check smb://ickle/inbound if there goto next step if not then exit
folder=/home/mrgreaper2004/testfold/unlock
#the mount command REM`d out for now
#sudo mount ernie:/media/filehouse/Tv /home/mrgreaper2004/Tv
 
if [ -d $folder ];
then
   echo "script says $folder exists success"
else
   echo "$folder cant be found..fail"
fi
###

#here we set the local folder up
tv=/home/mrgreaper2004/Tv/

#now we create the current tv show list (all the avi`s in the folder sadly it doesnt give me a full path to each one which im sure would be 10 times more helpfull but this line is a butchered example that i cant figure out how it works
tv2="$(find $tv -type f -name "*.avi")"
echo ****the contents of tv2 variable****
echo $tv2
echo ************************************
#i then needed to load all the names from the old episode list (one created at the end of the script) after 2 hours of googling i finaly hit on SED which will aparently do just that...it says i dont have permission "./test.sh: 7: /home/mrgreaper2004/test2.txt: Permission denied" grrrrrr

old=sed /home/mrgreaper2004/test2.txt
echo ****the contents of old***
echo $old
echo **************************
#right next we compare the new list with the old list and place all the unique programes into another varriable..again it would be useful to have the full paths

new="$(echo -e "$tv2$old"|sort -d|uniq -u)"
echo ****the contents of new****
echo $new
echo ***************************

#next to copy the filed 
cp $new /home/mrgreaper2004/testfold/

#for testing purposes saves the current list
echo "$tv2" > /home/mrgreaper2004/test.txt

#now to create the list of old episodes for use with the next time the script is run
echo "$tv2" > /home/mrgreaper2004/test2.txt

exit
now here comes the strange thing

ok run it once and shell displays

Code:
mrgreaper2004@ickle:~$ ./test.sh 
script says /home/mrgreaper2004/testfold/unlock exists success
****the contents of tv2 variable****
/home/mrgreaper2004/Tv/loop2.avi /home/mrgreaper2004/Tv/test.avi /home/mrgreaper2004/Tv/test3.avi /home/mrgreaper2004/Tv/test2.avi

the contents of my whole home folder file by file was also listed here !
****the contents of old***

the contents of my whole home folder file by file was also listed here !

****the contents of new****
-e /home/mrgreaper2004/Tv/loop2.avi /home/mrgreaper2004/Tv/test2.avi /home/mrgreaper2004/Tv/test3.avi /home/mrgreaper2004/Tv/test.avi
the contents of my whole home folder file by file was also listed here !
cp: invalid option -- 'e'
Try `cp --help' for more information.
mrgreaper2004@ickle:~$
the contents of test.txt is empty before run and contains the folowing after
Code:
/home/mrgreaper2004/Tv/loop2.avi
/home/mrgreaper2004/Tv/test.avi
/home/mrgreaper2004/Tv/test3.avi
/home/mrgreaper2004/Tv/test2.avi
ok on the second run shell shows
Code:
mrgreaper2004@ickle:~$ ./test.sh 
script says /home/mrgreaper2004/testfold/unlock exists success
****the contents of tv2 variable****
/home/mrgreaper2004/Tv/loop2.avi /home/mrgreaper2004/Tv/test.avi /home/mrgreaper2004/Tv/test3.avi /home/mrgreaper2004/Tv/test2.avi
the contents of my whole home folder file by file was also listed here !

/home/mrgreaper2004/Tv/loop2.avi: 1: Syntax error: "(" unexpected
/home/mrgreaper2004/test2.txt: 2: /home/mrgreaper2004/Tv/test.avi: Permission denied
/home/mrgreaper2004/test2.txt: 3: /home/mrgreaper2004/Tv/test3.avi: Permission denied
/home/mrgreaper2004/test2.txt: 4: /home/mrgreaper2004/Tv/test2.avi: Permission denied
****the contents of old***

the contents of my whole home folder file by file was also listed here !

****the contents of new****
-e /home/mrgreaper2004/Tv/loop2.avi /home/mrgreaper2004/Tv/test2.avi /home/mrgreaper2004/Tv/test3.avi /home/mrgreaper2004/Tv/test.avi
the contents of my whole home folder file by file was also listed here !

cp: invalid option -- 'e'
Try `cp --help' for more information.
ok im officialy confused, why is it displaying all of my home folder hmmmm grrrrr

it all works in theory but as soon as i run the script it wont arghhhhhhhhhhh
 
Old 04-27-2010, 08:40 PM   #19
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Check out the "LinuxCommand" tutorial in my signature.

It has a great section on scripting.
 
Old 04-27-2010, 08:51 PM   #20
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by MTK358 View Post
Check out the "LinuxCommand" tutorial in my signature.

It has a great section on scripting.
will do ...2morro(i need a break from it or ill scream)
 
Old 04-27-2010, 10:28 PM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
OK ... not to be too harsh, but we need to go step by step (not sure if you are doing this, if you are I apologise)

Firstly i wanted to mention something about post #17 where you wrote:
Quote:
if the mount succeded
When any command is executed, along with the output you may require it also has an exit code/status represented by $?, ie
Code:
$>ls /home
clfs grail -- this is my output
$>echo $?
0 -- zero equals success, other possibilities are between 1 and 255
$>ls /homes -- this directory does not exist on my machine
ls: cannot access /homes: No such file or directory
$>echo $?
2
As you can see from the above you can test if the mount is successful by testing if $? = 0 (actually -eq in bash for = number)
then place rest of tests inside the if to continue on success
Quote:
3b. Now there are many tools but the simplest is probably to grep the above "line" from the file with the previous data and do an "if" on the
result. true ignore, false put it in ... or something like that
grep is a command that allows you to look into a text file and find matches to particular text and/or patterns:
Code:
grep loop2.avi test2.txt

or

grep "*.avi" test2.txt
The first will return any lines it finds in test2.txt that contain "loop2.avi" ( I would add that it also matches "thisloop2.avi", but we will get to that)
The second looks for all lines containing zero or more of any character followed by ".avi" and returns them.
So the "if" I was referring to was to test that the grep was successful or not, ie the exit code I mentioned above for mount.

Now back to recent posts of errors, as you have a few errors this would be why I suggest the step by step approach above.
Any error after the first cannot really be looked at until the prior ones are solved (I know this may be obvious, but i just thought I would put it out there)

So things to look at:

1.
Quote:
tv2="$(find $tv -type f -name "*.avi")"
This does not return an array but rather a string of all your avi files.
the issue with this from the testing point of view is it is one long string and so your "test2.txt" file would need to be in the same format
for the testing to work, which I am guessing it is not, but rather that you have one line per file name (please correct me if i am wrong here?)
This being said, the following line works as you expect due to it being a successfully printed string:
Quote:
echo $tv2
2.
Quote:
old=sed /home/mrgreaper2004/test2.txt
echo ****the contents of old***
Now this is one of those try it on the command line first and then stick it in the script type of things.
There a couple of problems here:
a. old=sed - from bashes point of view, this is where the first command ends as it is an assignment of the string sed to the variable old
b. /home/mrgreaper2004/test2.txt - execute this string of text as a command, which of course will not work
c. as a. & b. demonstrate the echo here is incorrect

To add to this point, this is where you would need to use either the grep or loop idea to check your file. sed is the wrong tool and will not work the way you have it even if you had placed it in command substitution characters like so:
Code:
old=$(sed /home/mrgreaper2004/test2.txt)
This will generate an error.

3.
Quote:
new="$(echo -e "$tv2$old"|sort -d|uniq -u)"
echo ****the contents of new****
echo $new
echo ***************************
As stated above, we cannot continue to this code with the prior errors in place as the next line then references "$old" which is not what we expect it to be.
However, I would again suggest writing the "echo" part piece by piece until you get to the "uniq" command to actually see what sort of output you will get.
For this test you will need to manually enter the values for "$tv" and "$old". I think you may be surprised at what it returns.

4.
Code:
#next to copy the filed 
cp $new /home/mrgreaper2004/testfold/

#for testing purposes saves the current list
echo "$tv2" > /home/mrgreaper2004/test.txt

#now to create the list of old episodes for use with the next time the script is run
echo "$tv2" > /home/mrgreaper2004/test2.txt

exit
Assuming all the previous corrections were made, these line will more than likely work.
Again I would urge you to test how the last two "echo"s would behave on the command line and i would stress not to use a file where you wish to keep the contents (hint)
 
Old 04-28-2010, 07:34 AM   #22
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
i must admit im concentrating on the file scaning portion

the bit the scans the tv folder then compares it to the last scan and copys the difference

on the test i have a folder with 3 test avis and a spare avi in the dest folder is nothing

the idea is the first run it should see there is nothing in the test2.txt ( the list from the prevouse scan (blank in the first instance))

then copy all avi`s in the tv folder to the dest
and propergate the test2.txt with a list of the files it encountered on the scan of the tv folder

on the second run
it would see that the scan of the folder matches the contents of test2.txt and not copy anything

IF i get that far i would drop a fourht test avi into the tv folder and run the script again

if the script works right it should realise that the scan of the tv folder matches the test2.txt with the exception of the new file which would be passed on to the $new and then onto the copy command
and then ammend the contents of test2.txt with the new file name

(having the scan of the folder written to the test2.txt is sloppy i know and that will be ammended with having the contents of $new added to the test2.txt before the copy starts so i dont get loads of duplicate lines and so if the script starts up again during the scripts copy procedure it wont find anything found before again)

a fourth run would then not copy anything

i added all the echos so i know what each variable is at aach stage in theory but im only working on one bit at a time and the mount portion im leaving out till i get the core of the script working lol (the folder it checks are local folders on my netbook for the test)


for now i gotta do something else else ill go insane and i shall do more to this when i get to work tonight (the joy of being a security guard i get more time at work to fiddle with this then at home lol)

i was quite chuffed with
Quote:
tv2="$(find $tv -type f -name "*.avi")"
as it seemed to be doing exactly what i wanted it to do especialy now its providing full paths

and test2.txt is displayed with one per line which i thought was good lol

one aproach i thought of was to have a loop (i would need to learn how)
outside the loop
;scan the number of lines in test2.avi and set the loop to go that many times
;scan the tv folder
;line=1
inside the loop
;read line $line of test2.txt
;compare it to the scan of the tv folder and
;;if it matches any of the avis then line=$line+1 and goto start of loop
;;if it doesnt match then continue
;copy it to the dest folder
;add it to the test2.txt
;goto the start of the loop

ignore that, it wouldnt work as its only looking at the old eps and would never pick up the new ones brain failed (i`d have to compare the ones in the scan of tv against the ones in the test2.txt not the other way round...muppet moment)

its certainly got my brain running lol

your help and posts are extremly helpful without them i would of given up as i didnt even know where to begin to look

Last edited by mrgreaper; 04-28-2010 at 07:41 AM. Reason: i was being a muppet
 
Old 04-28-2010, 08:55 AM   #23
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Let us see if i can give you a nudge for the loop side:

Code:
while read line
do
    echo "$line"
    <this is where your testing will go of the test2.txt file>
done< <(find $tv -type f -name "*.avi")
Try putting just this (without the line between <>) and see what echoes out for you.
Just to be sure, the last line with the word "done" it is very important to get the spacing correct.
No space after done and one space between the two "<" signs

Enjoy
 
Old 04-28-2010, 10:04 AM   #24
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
i gave it a quick go (im cooking at mo) it didnt work though
Code:
#!/bin/sh

#this section will check to see if the netbook is connected to the network and if it is then it will continue if not it will exit
#yeah i have no idea how to do it ...i know the exit command..its exit
# check smb://ickle/inbound if there goto next step if not then exit
folder=/home/mrgreaper2004/testfold/unlock
#the mount command REM`d out for now
#sudo mount ernie:/media/filehouse/Tv /home/mrgreaper2004/Tv
 
if [ -d $folder ];
then
   echo "script says $folder exists success"
else
   echo "$folder cant be found..fail"
fi
###

#here we set the local folder up
tv=/home/mrgreaper2004/Tv/


#now we create the current tv show list (all the avi`s in the folder sadly it doesnt give me a full path to each one which im sure would be 10 times more helpfull but this line is a butchered example that i cant figure out how it works

while read line
do
    echo "$line"
done< <(find $tv -type f -name "*.avi")
rest of the script is entirely REM`d out

Quote:
mrgreaper2004@ickle:~$ ./test.sh
script says /home/mrgreaper2004/testfold/unlock exists success
./test.sh: 27: Syntax error: redirection unexpected
what i do wrong lol
(will look more when at work tonight)
 
Old 04-28-2010, 10:48 AM   #25
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Well you have stumped me

I copied your script and changed only the "tv" variable to be the one I have with avi files in it and this is the output:

Code:
grail@wetworks:~/Documents/programming/bash$ ./temp.sh 
/home/mrgreaper2004/testfold/unlock cant be found..fail
t2/three.avi
t2/one.avi
t2/two.avi
As you can see it even correctly picks up that your other folder is not on my computer.

Just to check, can i get you to run the following to make sure which version of bash you have:
Code:
bash --version
Other than that ....

HOLD THE PHONE ... just noticed the top of your script, please change the following and see how we go:

Code:
#!/bin/sh

to

#!/bin/bash
Now run again and see how you go.
I just realized that I only copied your text and not the top line (assuming incorrectly as it were) thinking we were both running bash.
 
Old 04-28-2010, 11:25 AM   #26
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
just a quick one as im rushing about getting ready for work,

i changed the top line as suggested and it works

Quote:
mrgreaper2004@ickle:~$ ./test.sh
script says /home/mrgreaper2004/testfold/unlock exists success
/home/mrgreaper2004/Tv/loop2.avi
/home/mrgreaper2004/Tv/test.avi
/home/mrgreaper2004/Tv/test3.avi
/home/mrgreaper2004/Tv/test2.avi
makes me wonder if any of my other parts of the script messed up due to the top line

the top line i thought was REM`d out cos of the # ,i have been assuming that #is the same as the old REM command oops lol
 
Old 04-28-2010, 11:28 AM   #27
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Quote:
Originally Posted by grail View Post
I believe NFS is the way to go here and it will then just appear as part of your system, once mounted of course

here is a link from a quick search which seems to lay out what you will need:

http://mybeni.rootzilla.de/mybeNi/20..._ubuntu_linux/

Let me know how you get on
i agree, i also like sshfs
...
sorry i'm late to the party (so i havent read it all yet) but here are a few notes i assembled:
Code:
1) man test
if [ -e /mnt/share/current.txt ]
then
 ...
fi

2) man find
find ~/tv -name "*.avi" > /mnt/share/current.txt 
# i personally like exec'ing file inside of find because some file extensions may be mislabelled:
# find ~/tv -exec file '{}' \; | grep RIFF.*AVI | cut -d " " -f 1

3) man grep
grep -v -f /mnt/share/old.txt /mnt/share/current.txt > /mnt/share/tobecopied.txt

4) man cp
cp `cat /mnt/share/tobecopied.txt` /mnt/share # backticks not single-quotes

5) man rm
rm /mnt/share/old.txt /mnt/share/tobecopied.txt # not really necessary since the redirection overwrites.

6) man mv
mv current.txt old.txt

7) man mail
egrep -i "(failed|ipod|mp4|mkv|wmv|password)" > errors.txt # not sure what the purpose of this is ?
cat errors.txt | mail -s "errors" user@host.com # you can save a step by piping the output of egrep to mail unless you really want a backup of errors.txt

8) man sleep
sleep 1800 # 1800 seconds/ half-hour

9) profit
so whats left would be wrapping it in a while loop.
this is slightly related:
http://www.linuxquestions.org/questi...4/#post3508846

Last edited by schneidz; 04-28-2010 at 12:36 PM.
 
Old 04-28-2010, 12:15 PM   #28
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Quote:
the top line i thought was REM`d out cos of the # ,i have been assuming that #is the same as the old REM command oops lol
You are generally correct but the first line of any script is a special place and identifies the interpreter, in our case, bash.
You will also notice that the next character after the # is a ! (called a bang or in english an exclamation mark) and it too is required on this
line to also help in identifying that the line relates to the interpreter.
To give you an example, if assume all our interpreters are in /bin (this is generally not the case but serves for our example), we could have:
Code:
#!/bin/bash

#!/bin/sh

#!/bin/ksh  -- this is the korn shell

#!/bin/awk  -- so here we can write an awk script and this will be used to interpret
Other than this first line written in this fashion, all other # marks in your code are equivalent to the REM statement you remember.
There are a few minor exceptions, but that is better left for another day
 
Old 04-28-2010, 12:21 PM   #29
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi all,

This thread is great, congratulations to grail for such a good job. I'm only sorry I couldn't participate more. My boss just gave me 13 IBM servers, so I'm playing with them a lot right now. But still checking in from time to time to pick up something new. Also congrats to mrgreaper for hanging in there and doing it. You're doing great! Did you think two days ago that you would encounter yourself at this point already?

Kind regards,

Eric
 
Old 04-28-2010, 05:49 PM   #30
mrgreaper
Member
 
Registered: May 2006
Posts: 167

Original Poster
Rep: Reputation: 15
to schneidz
thank you i edited it a bit to suit my needs and to aim it at my test folders and it worked a treat

then because im a bit test mad i moved test3.avi into a folder and it worked once i added -r to it lol (i did read the man pages, i didnt understand them all but i read them)

then i added a avi file with spaces and it failed so i just need to figure out how to add " to the front and back of any file listed in the tobe copied txt with spaces in (wouldnt hurt to add them to all lol)

bugger

Code:
#!/bin/bash

#1) man test
if [ -e /home/mrgreaper2004/Tv/current.txt ]
then
 ...
fi

#2) man find
find ~/Tv -name "*.avi" > /home/mrgreaper2004/Tv/current.txt 
# i personally like exec'ing file inside of find because some file extensions may be mislabelled:
# find ~/tv -exec file '{}' \; | grep RIFF.*AVI | cut -d " " -f 1

#3) man grep
grep -v -r -f /home/mrgreaper2004/Tv/old.txt /home/mrgreaper2004/Tv/current.txt > /home/mrgreaper2004/Tv/tobecopied.txt

#4) man cp
cp -v `cat /home/mrgreaper2004/Tv/tobecopied.txt` /home/mrgreaper2004/testfold # backticks not single-quotes

#5) man rm
#rm /home/mrgreaper2004/Tv/old.txt /home/mrgreaper2004/Tv/tobecopied.txt # not really necessary since the redirection overwrites.

#6) man mv
mv /home/mrgreaper2004/Tv/current.txt /home/mrgreaper2004/Tv/old.txt
 
  


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
OS related questions burtonboarder230 Linux - Newbie 14 12-08-2008 03:45 PM
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 12:50 PM
LXer: Configuration Automation & Centralized Management With Puppet on Ubuntu LXer Syndicated Linux News 0 03-04-2007 02:46 PM
Multiple Problems, gtk+ related? kryptobs2000 Linux - Software 0 10-31-2006 04:28 PM
3 non-related questions Rognon Slackware 5 02-06-2004 05:45 PM


All times are GMT -5. The time now is 12:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration