copying multiple files with user input

Reply

Join Date: Nov 2008
Posts: 9
Reputation: wmuldoon is an unknown quantity at this point 
Solved Threads: 0
wmuldoon wmuldoon is offline Offline
Newbie Poster

copying multiple files with user input

 
0
  #1
Nov 20th, 2008
I'm currently trying to write a shell script at work that would loop and allow me to enter the date, and the ad number of a PDF file, that would then copy that ad into a designated file and I can't get it to run correctly

heres the code:
Shell Scripting Syntax (Toggle Plain Text)
  1. #! /bin/bash
  2. year=`date +%Y`
  3. month=`date +%m`
  4. monthname=`date +%B`
  5. day=`date +%d`
  6. hotfolder=`expr $day + 2`
  7. open "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"
  8.  
  9. echo "Enter the DATE of the PDF you wish to Copy";
  10. while read inputline
  11. do
  12. copydate="$inputline"
  13. echo "you entered $copydate";
  14. if [ "$copydate" -ge 1 ]
  15. then
  16. echo "You entered $copydate"
  17. fi
  18. while read inputline2
  19. do copynum=$inputline2;
  20. done

right now I need to drag and drop multiple files from a few folders, into one folder, I would like to be able to have it go along the lines of...

Enter date for the ad:
22

Enter number for the ad:
107548

then i would like it to copy ad number 107548*pdf from the 22nd folder, into the hotfolder.


thanks in advance,

-Wm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: copying multiple files with user input

 
0
  #2
Nov 20th, 2008
Hi,

You have some spaces which may be causing you some problems. One here:
Shell Scripting Syntax (Toggle Plain Text)
  1. #! /bin/bash
should be
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
and also
Shell Scripting Syntax (Toggle Plain Text)
  1. open "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"
might need to be??
Shell Scripting Syntax (Toggle Plain Text)
  1. open "/Volumes/_Issues/$year/$month $monthname/$hotfolder/"
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: copying multiple files with user input

 
0
  #3
Nov 20th, 2008
Also instead of this:
Shell Scripting Syntax (Toggle Plain Text)
  1. while read inputline
  2. do
  3. copydate="$inputline"
  4. echo "you entered $copydate";
Why dont you just use
Shell Scripting Syntax (Toggle Plain Text)
  1. while read coypdate
  2. do
  3. echo "you entered $copydate";
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,756
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

Re: copying multiple files with user input

 
0
  #4
Nov 20th, 2008
I see two "do"s and only one "done"
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: copying multiple files with user input

 
0
  #5
Nov 20th, 2008
Good spoting!!
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: wmuldoon is an unknown quantity at this point 
Solved Threads: 0
wmuldoon wmuldoon is offline Offline
Newbie Poster

Re: copying multiple files with user input

 
0
  #6
Nov 20th, 2008
The space on the server address is supposed to be there, our admin made that mistake when re assigning shards, and its made everything a nightmare...

definitely a good spotting on the two do's, one done, I'm thinking that might be it, I'll give it a shot here in a few hours.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: copying multiple files with user input

 
0
  #7
Nov 21st, 2008
Hey there,

Does the line:

open "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"

not give you an error for "open"?

Just curious. My bash's do.

Some of the logic of the scripts function doesn't seem to be completed either, like the final move. Is this just part of the code? Or, possibly, a little bit of pseudo code mixed in with regular?

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,756
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

Re: copying multiple files with user input

 
0
  #8
Nov 21st, 2008
btw, isn't the whitespace in the path supposed to be escaped?
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

Re: copying multiple files with user input

 
0
  #9
Nov 21st, 2008
ok but this definatly needs to be changed:

#! /bin/bash

As it sets the file descriptor of the file and if you keep the space it wont reconsie it as a bash file!
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: wmuldoon is an unknown quantity at this point 
Solved Threads: 0
wmuldoon wmuldoon is offline Offline
Newbie Poster

Re: copying multiple files with user input

 
0
  #10
Nov 24th, 2008
I'm running os x 10.4.8, and my script seems to run with/without the whitespace in the first line, but i removed it either way...
I just removed both while's and do's and placed it in root and made it recursive...and everything seems to work fine now, thanks everyone.

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. year=`date +%Y`
  3. month=`date +%m`
  4. monthname=`date +%B`
  5. day=`date +%d`
  6. hotfolder=`expr $day + 2`
  7. echo "Enter the DATE of the PDF you wish to Copy";
  8. read inputline
  9. copydate="$inputline"
  10. echo "you entered $copydate";
  11. echo "Enter the NUMBER of the PDF you wish to copy."
  12. read inputline2
  13. copynum=$inputline2;
  14. cp "/Volumes/ _Issues/$year/$month $monthname/$copydate/$copynum"* "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"
  15. echo "Copying ad number # $copynum from $copydate to $hotfolder..."
  16. echo "Done."
  17. exec ~/Desktop/test.sh
  18. exit
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC