[SOLVED] help clean up file movement script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [SOLVED] help clean up file movement script
# 1  
Old 09-19-2012
[SOLVED] help clean up file movement script

Hello Group,

Once again another script hacked together from a few sources to try and suit my needs. This is to go through a /temp directory and for each ls entry ask which Dir of three I want it sorted.

The script works but there are a few behaviors that are odd so I figured I'd ask for help cleaning this up. The first issue is it continues to ask to move the file even if you have answered yes prior, which should cause an error but instead it just happily copies it to both, or all three which is really weird. I'd like it to stop after one affirmative answer or better yet if its easier & someone can show me how it could be one read with a (M)ovie (T)elevision or (K)ids prompt & and three $replys looking for first corresponding letters . I just wasn't able to figure that out for the life of me.

Here it is: TIA to all, this is my goto group for this stuff, since I'm obviously not a coder.
Code:
#/bash
for files in `cd /mnt/storage/media/temp/; ls`; do

echo "Found: /mnt/storage/media/temp/"$files;

read -p "Move to movies (y/n)?"
[ "$REPLY" == "n" ] || mv /mnt/storage/media/temp/$files /mnt/storage/media/Video/movies/$files

read -p "Move to Mike (y/n)?"
[ "$REPLY" == "n" ] || mv /mnt/storage/media/temp/$files /mnt/storage/media/Video/mike/$files 

read -p "Move to TV (y/n)?"
[ "$REPLY" == "n" ] || mv /mnt/storage/media/temp/$files /mnt/storage/media/Video/television/$files

done


Last edited by dpreviti; 09-19-2012 at 12:55 PM..
# 2  
Old 09-19-2012
#/bash is wrong. It needs to be #!/bin/bash.

That's a useless use of ls and dangerous use of backticks.

You can use the built-in select menu to make things simpler.

Code:
#!/bin/bash


for FILE in /mnt/storage/media/temp/*
do
        [ -f "$FILE" ] || continue # Ignore non-files

        # Special variable which controls select menu prompt
        PS3="Move $FILE to /mnt/storage/media/Video/?"

        # 'select' is a loop like 'while', but prints and does a menu inside
        select DIR in movies mike television quit skip
        do
                [ -z "$DIR" ] && continue # User picked a bad option
                [ "$DIR" = "quit" ] && exit # User wants to quit
                [ "$DIR" = "skip" ] && break # User wants to skip this file

                echo mv "$FILE" "/mnt/storage/media/Video/$DIR/"
                break
        done
done


Last edited by Corona688; 09-19-2012 at 01:54 PM..
# 3  
Old 09-19-2012
Thanks that worked perfect.
This User Gave Thanks to dpreviti For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automatic file movement between folders

Hello There, Here is the use cases Input folders dropbox/project/abc/ dropbox/project/pqr/ dropbox/project/lmn/ dropbox/project/xyz/ Target Folders /data/abc/ /data/pqr/ /data/lmn/ /data/xyz/ (2 Replies)
Discussion started by: TreasureCookies
2 Replies

2. Shell Programming and Scripting

File movement based on peak hours ( 10AM - 3PM )

Hi , I came across a requirement in writing a script to move files from one location to another location having the number of files limited based on the server time. For example: In total number of files , I have to move files in below order 00 hours - 6AM 10% of the total number of... (1 Reply)
Discussion started by: sakthivel021
1 Replies

3. Open Source

Shell script file movement to a Mail Box server using ftp commands

Hi All, I have a current Process that runs "windows script " for the file movement that needs to changed to a "DataStage Process (Using shell script )" Source :Text file is getting generated as part of Datastage Jobs processes and resides in a shared drive (Unix server) Target :ftp... (2 Replies)
Discussion started by: developer.dwh9
2 Replies

4. Shell Programming and Scripting

sftp script file movement

Hi, I am newbie in unix scripting, I have written a bash script of SFTP that transfer some files from one folder to another within a server , I have two folders test and temp in the directory /home/p5060/sxk124 , the temp folder(/home/p5060/sxk124/temp)contain the files which I through my... (5 Replies)
Discussion started by: KAREENA18
5 Replies

5. Shell Programming and Scripting

Searching for a string in a log file with little movement

I have a script which tails a log file and if it finds certain strings in the data tailed it sends an email, basically like this: tail -f logfile > tmp.file & sleep 10 kill $! STRING=$(grep -c "string" tmp.file) && echo $STRING | mailx -s "Warning.." admin@123.com When the string is... (10 Replies)
Discussion started by: Moxy
10 Replies

6. Shell Programming and Scripting

How to clean this script?

Hello guys, this script partially works but it's still pretty ugly and, moreover, if the month is jan/feb/mar... it doesn't work at all. Could anyone say me how to correct, cut and clean a little bit? #!/usr/bin/ksh egrep -v -e "^\s*#" /file/permission | awk '{ print $1 }' | sort | uniq... (3 Replies)
Discussion started by: gogol_bordello
3 Replies

7. UNIX for Dummies Questions & Answers

Permission for file movement.

Hi , How will put the condition whether the file has permission to move from one location to another in scripting? Regards Rajesh (1 Reply)
Discussion started by: rajesh08
1 Replies

8. OS X (Apple)

Startup script to clean out trash can

I need to know how I would be able to clean out the trash can of a single "dumb" user every time the MAC is turned on. Back ground. OS 10.3x G3 Mac Two users configured... 1) Root or Admin (superuser) 2) student (Simple no access to anything but shared folder for files etc.) The problem... (4 Replies)
Discussion started by: Andrek
4 Replies

9. Shell Programming and Scripting

clean up script

I have a script which would monitor a given directory and delete any files which are older than 10 days. I was going to set the 10 crob jobs to perform this operation for 10 different directories (some are actually sub-directories), but my boss doesn't like that idea, so I need to do that in one... (1 Reply)
Discussion started by: mpang_
1 Replies

10. Shell Programming and Scripting

Conditional File Movement script scheduled using CRON job

Hi All, i am trying to automate a process and have to create a unix script like wise. I have a scenario in which i need to automate a file movement. Below are the steps i need to automate. 1. Check whether a file (Not Fixed name-Pattern search of file say 'E*.dat') is present in a... (2 Replies)
Discussion started by: imu
2 Replies
Login or Register to Ask a Question