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:

#! /bin/bash
year=`date +%Y`
month=`date +%m`
monthname=`date +%B`
day=`date +%d`
hotfolder=`expr $day + 2`
open "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"

echo "Enter the DATE of the PDF you wish to Copy";
while read inputline
	do
	copydate="$inputline"
	echo "you entered $copydate";
if [ "$copydate" -ge 1 ]
then
echo "You entered $copydate"
fi
while read inputline2
	do copynum=$inputline2;
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.

Recommended Answers

All 9 Replies

Hi,

You have some spaces which may be causing you some problems. One here:

#! /bin/bash

should be

#!/bin/bash

and also

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

might need to be??

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

Also instead of this:

while read inputline
	do
	copydate="$inputline"
	echo "you entered $copydate";

Why dont you just use

while read coypdate
	do
	echo "you entered $copydate";

I see two "do"s and only one "done"

Good spoting!!

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.

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

btw, isn't the whitespace in the path supposed to be escaped?

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!

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.

#!/bin/bash
year=`date +%Y`
month=`date +%m`
monthname=`date +%B`
day=`date +%d`
hotfolder=`expr $day + 2`
echo "Enter the DATE of the PDF you wish to Copy";
read inputline
copydate="$inputline"
echo "you entered $copydate";
echo "Enter the NUMBER of the PDF you wish to copy."
read inputline2
copynum=$inputline2;
cp "/Volumes/ _Issues/$year/$month $monthname/$copydate/$copynum"* "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/"
echo "Copying ad number # $copynum from $copydate to $hotfolder..."
echo "Done."
exec ~/Desktop/test.sh
exit
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.