Shell Noob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Noob
# 1  
Old 05-30-2007
Question Shell Noob

Hi all,

I am trying to write a shell script that will move files from one directory to another, the only thing is I want to to check loads of different source directory and move the files to loads of different directories.

I am totally new to shell scripts but not to UNIX (although I would still class myself as a newbie).

Any advice would be welcome, as I am sat looking at a rather empty page in vi and goggling like crazy but not coming up with much.
# 2  
Old 05-30-2007
You are kinda vague. If you need to move a whole tree try something like this:
Code:
cd /path/to/upper/level/of/source
tar -cvf - $(find . -print -type f) | (cd ../destination ; tar -xvf -)

find gets all of the files in the source tree, feeds the file to tar, the tar on the other end of the pipe then parks the file in a new directory tree with the same subdirectories. This is not deleting anything. This is a VERY general solution -
# 3  
Old 05-30-2007
Ok, being new to this I have drawn a pic to help me explain......

Image

ok hopefully this will help me explain what I'm trying to do.

I did ls | wc -l on /user and that gave 392, which sounds about right (give or take 15 random other directories and files that are in there).

So I am trying to move files from one private folder (under xxxx.old) to the other private folder, I need to do this somewhere in the region of 350 times on different folders.

Apologies for my naff explanation but hopefully my wonderful picture will give you a clue what I'm on about Smilie
# 4  
Old 05-30-2007
Sax,
See if this works for you.
Note that I commented the "cp" (copy) statement so that you can
make sure it does what you want first, before running it.
Code:
for mNewDir in `find /user/ -type d -name 'accu*'`
do
  mNewBase=`basename ${mNewDir}`
  mNewPriv=${mNewDir}"/private/"
  mOldPriv="/user/dotolds/"${mNewBase}".old/private/"
  echo "Now copying from "${mOldPriv}" to "${mNewPriv}
  #####cp ${mOldPriv} ${mNewPriv}
done


Last edited by Shell_Life; 05-30-2007 at 04:53 PM..
# 5  
Old 05-31-2007
Cheers, looks like just what i'm after, however I am getting a syntax error on line 5 (syntax error at line 5: `mNewPriv=$' unexpected), the only thing I have changed is the find (see below).

I have been through I a couple of time to check what I have typed in vi matches your solution, and I am sure I have typed it correctly.

Code:
for mNewDir in `find /user/ -type d -name 'accu*.old'`
do
  mNewBase=`basename ${mNewDir}`
  mNewPriv=${mNewDir}"/private/"
  mOldPriv="/user/dotolds/"${mNewBase}".old/private/"
  echo "Now copying from "${mOldPriv}" to "${mNewPriv}
  #####cp ${mOldPriv} ${mNewPriv}
done

# 6  
Old 05-31-2007
Sax,
The "find" statement is to loop through all the "accuNNN" directories,
NOT the "accu*old".
Display the "mNewDir" right after the "do" to see what value you are getting:
Code:
echo "mNewDir = <"${mNewDir}">"

Also, I wrote the shell in ksh -- are you using the same?
# 7  
Old 05-31-2007
I think I see how it's working now.
I changed the find back, and changed the script to ksh. I also added the line above.
When I run it I don't get any errors, but then I don't get anything else ? I left the copy command commented out and ran it, but I didn't get any output, I thought I would at least see the echo lines Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Noob trying to improve

Hi everyone! This is my first post here, I hope that I will not already be violating any rule! I also would like to apologize in advance as my post will definitely be a noob post... please have patience and faith :rolleyes:! Now that I have set the ground rules :D:D, my objective is trying... (39 Replies)
Discussion started by: Ardzii
39 Replies

2. UNIX for Beginners Questions & Answers

Noob. shell script with prompt?

Hey Guys and Gals, Im a complete Noob to Unix. But recently have started working on a unix system for my PET/CT scanner. My scanner comes with a MOD drive for backup. I would like to back up to USB (its alot cheaper). But the only way to do so is by manually enterin the unix commands. Id like to... (13 Replies)
Discussion started by: TorresGXL
13 Replies

3. Shell Programming and Scripting

Cron-Noob

Hi guys! Consider the following PERL script, #!/usr/bin/perl my $userID = `whoami`; open(TMP, ">user.txt"); print TMP "$userID"; close(TMP); Run on the command line it works no problem. Run using crontab it doesn't work. Where do I go to check errors from crontab? I've read things... (25 Replies)
Discussion started by: Jaymoney
25 Replies

4. Shell Programming and Scripting

Noob to Shell Scripting

Hello. I'm attempting to create a shell script to assist me by saving time with one of my hobbies. I am an Android Enthusiast and currently build a few roms for one of the devices. One of the roms I make is ported from a different device to mine (I get the original for the HTC Desire HD and... (3 Replies)
Discussion started by: JHutson456
3 Replies

5. HP-UX

Anybody wants to help a complete Noob?

Hello there, first post here so go easy on me! :D I just aquired an old HP 9000 Dclass d220 server, all I know is that it's running HP-UX, and it appears to boot fine (I see the modules loading, etc..) Now, I have been an MS guy all my life (yeah I know, make fun of me), so I really have no... (9 Replies)
Discussion started by: Marvio
9 Replies

6. UNIX for Dummies Questions & Answers

I'm a noob at Lynx...

So... I'm using lynx on a Mac... I didn't know that the whole dang thing is in Terminal? I rarely use terminal. I can't even figure out how to start the thing up. I type in lynx into it and press enter... And the cursor just goes down. Nothing happens like the FAQ websites describe. I feel so... (6 Replies)
Discussion started by: yennster
6 Replies

7. UNIX for Dummies Questions & Answers

Noob on Unix.

This may seem really easy to alot of you but i am a real noob on unix. I have been set the task to make a script which will answer a query. Basically I will have made files for people and i want to be able to search for a persons file and then select certain variables from the files. e.g... (7 Replies)
Discussion started by: bobtheb
7 Replies

8. Linux

noob help needed

i'm having trouble putting together a program :( any help would be much appreciated! Write a Shell Program to automate the process of collecting assignments from the directories of students of any specified class. The person running the program should be able to pass a parameter to the... (1 Reply)
Discussion started by: ace_face
1 Replies

9. UNIX for Dummies Questions & Answers

complete noob

Hi all, This is my first post. I am a complete noobie to the UNIX OS, I have an iMac G5 with the unix shell built in and am interested in learning how to use it to do things useful with it, but have no idea where to start. I have read over the basic commands but they haven't helped me much yet.... (3 Replies)
Discussion started by: avdrummerboy
3 Replies

10. UNIX for Dummies Questions & Answers

I am a unix noob

Hello i am new to this forum. I signed up here really to ask one question. I recentaly got a old unix server from my work and i never really understood what unix is or what is does. Dont get me wrong i and very smart with computers as long as its windows, mac, or linux i can use them all but i... (4 Replies)
Discussion started by: alt+f4
4 Replies
Login or Register to Ask a Question