Need assistance with simple shell script to organize files. [Code attached]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need assistance with simple shell script to organize files. [Code attached]
# 1  
Old 11-15-2009
Power Need assistance with simple shell script to organize files. [Code attached]

I need some help with this shell script for class. All it does is organize your files. It works, but in the log file, it needs to show the new filepaths of the moved files. Heres my log of my output:

Code:
Starting to organize...
movie2.wmv --> 
movie3.mov --> 
movie1.mpg --> 
song1.mp3 --> 
song2.mp3 --> 
file1.txt --> 
final.txt --> 
grades.txt --> 
secretfile.txt -->

Where the arrows are, I need to print the filepath of the new files. So it would look something like this:

Code:
movie2.wmv-->  movies/movie2.wmv

Thank You for any help!
-Ryan

Code:
#!/bin/sh

echo "Are you sure you want to reorganize your files?"
echo "Enter 'Y' or 'y' to continue, anything else to cancel:"

read ANSWER
echo "You answered $ANSWER"

if [ $ANSWER == "Y" ] || [ $ANSWER == "y" ]; then
echo "Organizing files!"

touch organize.log
echo "Starting to organize..." > organize.log

mkdir movies

for filename in *.wmv
do
  mv $filename movies
  echo "$filename --> " >> organize.log
done

for filename2 in *.mov
do
  mv $filename2 movies
  echo "$filename2 --> " >> organize.log
done
  
for filename3 in *.mpg
do  
  mv $filename3 movies
  echo "$filename3 --> " >> organize.log
done
  
mkdir songs

for filename4 in *.mp3
do
  mv $filename4 songs
  echo "$filename4 --> " >> organize.log
done
  
for filename5 in *.wma
do
  mv $filename5 songs
  echo "$filename5 --> " >> organize.log
done
   
mkdir textfiles
  
for filename6 in *.txt
do
  mv $filename6 textfiles
  echo "$filename6 --> " >> organize.log
done
  
echo "Finished organizing files!"
echo "Bye!"

else
  echo "User cancelled the process."
  exit
fi
  
exit

# 2  
Old 11-15-2009
Code:
for filename in *.wmv
do
  mv $filename movies
  echo "$filename --> movies/$filename" >> organize.log
done

or let mv work in verbose mode, and redirect it.

Code:
mv -v $finame movies >> organize.log

Example:
Code:
mv -v testfile testdir/
`testfile' -> `testdir/testfile'

# 3  
Old 11-15-2009
Thank You sir!

I appreciate it, this is due Monday night for class and has stumped me. I was proud of it with having only a lousy powerpoint file to work with.

Thanks Smilie
# 4  
Old 11-15-2009
Posting Homework in the main forums is not allowed. Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script assistance Urgent

write a script using shift and case to receive 11 argument and do the following --arg1 - print hello message and the current proccess id --arg2 - read and edit a file based on the value which came along with the arg2. --arg3 - validate whether all... (1 Reply)
Discussion started by: saku
1 Replies

2. Shell Programming and Scripting

Seeking assistance in Shell script

#!/bin/bash >error_log for s in `cat s.txt` do uptime $s >>error_log echo $s >>error_log done The above code produce output with server name and its uptime in 2 different lines .My requirement is to have the same in one line . Please assist (3 Replies)
Discussion started by: vinil
3 Replies

3. Shell Programming and Scripting

Assistance with an awk code to split files but keep the header

---------- Post updated at 11:48 AM ---------- Previous update was at 11:46 AM ---------- Hello all I have an awk code that successfully creates separate text files based on the first six letters of the second field. What it doesn't do is preserve the header into each resulting file. ... (6 Replies)
Discussion started by: colecandoo
6 Replies

4. UNIX and Linux Applications

Organize (pretty) code

I'm looking for terminal programs, which organize and pretty code like HTML or JavaScript. Thanks! ---------- Post updated at 07:01 AM ---------- Previous update was at 01:49 AM ---------- Found this Online javascript beautifier (1 Reply)
Discussion started by: borobudur
1 Replies

5. Shell Programming and Scripting

Need assistance with a simple script

I have a simple script. Do you know what I got this error? ./total_memory.ksh: line 5: ' Thanks #! /bin/bash setmem=30177660 totalMemory= grep MemTotal /proc/meminfo | awk '{print $2}' if ; then echo "Total memory $totalMemory is less than :$setmem" exit 1 ... (3 Replies)
Discussion started by: Beginer0705
3 Replies

6. Shell Programming and Scripting

Shell Script Assistance

I am looking for a shell script or command to automate a process of opening many files in a directory and changing a string of text. Example: I have a apache web server that uses virtual hosting. There are approximately 2300 vhost entries or files. So in the directory... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

looking for a simple way to organize envs on our unix box...

would like to standardize how we set envs on our unix box, so I thought a menu would be a great way to accomplish this. The problem I'm experiencing, is the value is set...but ONLY during the time the menu is initiated. please see below: > /home/is/bin/r12MENU.sh ... (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

shell script assistance please

When I run this command (showstatus <username> <dbname>) in the prompt, the following will be displayed in the screen: 1. Show processes 2. Start process 3. Stop process 4. Go back to prompt Once i choose/type Option "1" (which is Show processes), it will display the list of processes... (5 Replies)
Discussion started by: xinoo
5 Replies

9. Shell Programming and Scripting

Need a little assistance with a shell script

I need to modify a script to send an attatched file. I have researched and read the faq's but have not found a solution for my script. Here is a copy of the code I am using: #!/bin/sh mysqldump --opt --skip-add-locks --user=****** --password=******* databasename | gzip >... (3 Replies)
Discussion started by: rickou812
3 Replies
Login or Register to Ask a Question