scripting newbie... some help please?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scripting newbie... some help please?
# 8  
Old 03-03-2009
Quote:
Originally Posted by avronius
No, it is not recursive
ok, thanks. with that in mind, what if i needed to make it recursive? what would i do?

i can't think of a use for that right now, but i'm sure it'll come up sometime!
# 9  
Old 03-03-2009
Quote:
Originally Posted by jmd9qs
[INDENT]
how do i make an "overwrite" option if the $SAVEPATH specified already exists?

Why do you need an "overwrite" option? What do you want to overwrite?
Quote:
as it is now, I'm assuming that I would have to use find (and put the two variables together, ie find -something -something $SAVEPATH$FILENAME) but i'm not too sure of how to go about this.

Why would you need find?

To copy $FILENAME into $SAVEPATH, you use:

Code:
cp "$FILENAME" "$SAVEPATH"

Quote:
will

Code:
:
if [ -d $DIRECTORY ];

look in only the current directory? or does it span the whole system? how does this work?

You should quote the variable:

Code:
if [ -d "$DIRECTORY" ]

It looks at whatever is specified in "$DIRECTORY".
# 10  
Old 03-03-2009
Quote:
Originally Posted by cfajohnson

Why do you need an "overwrite" option? What do you want to overwrite?

Why would you need find?

To copy $FILENAME into $SAVEPATH, you use:

Code:
cp "$FILENAME" "$SAVEPATH"

i guess i just don't know what i'm doing. I thought i'd need an 'overwrite' option because of output i have recieved from programs before... thinking about it now, i guess it was a silly question, seeing as the filename has a timestamp on it Smilie...

now i have a different issue... i have put all of my changes that you guys have helped me figure out into the script. i also added a little bit of code to create a directory if the $SAVEPATH wasn't one already. here is that section:

Code:
press_enter
        echo ""
        echo ""
        echo "Where would you like the new .tar.gz archive for $FILENAME stored?"
        echo -n "(just specify a directory with / at the end, filename is automatic) >  "
        echo ""
        read SAVEPATH
        if [ -z $SAVEPATH ]; then
                echo "No directory specified. Exiting..."; exit 1;
        fi
        if [ ! -d $SAVEPATH ]; then
                echo -n "$SAVEPATH does not exist. Would you like to create it? (y/n) >  ";
                read $answer
                        if [ "$answer" != "y" ]; then
                                echo "O.K. Exiting..."; exit 1;
                        fi
        fi
        echo "Making directory $SAVEPATH..."
        mkdir $SAVEPATH
        echo ""
        echo "$SAVEPATH created..."

i know i have to be overlooking a syntax error (or i just don't have it set up correctly) because, when i test the program with a directory that doesn't exist, it asks if I want to create it, i signal "y", and then it immediately exits... what am i doing wrong?

edit -

also, when i give it a directory that does exist, it does the mkdir $SAVEPATH command... i must have them switched up somehow. what should this look like?
# 11  
Old 03-03-2009
Quote:
Originally Posted by jmd9qs
i guess i just don't know what i'm doing. I thought i'd need an 'overwrite' option because of output i have recieved from programs before... thinking about it now, i guess it was a silly question, seeing as the filename has a timestamp on it Smilie...

What does the timestamp have to do with it?
Quote:
now i have a different issue... i have put all of my changes that you guys have helped me figure out into the script. i also added a little bit of code to create a directory if the $SAVEPATH wasn't one already. here is that section:

Code:
press_enter
        echo ""
        echo ""
        echo "Where would you like the new .tar.gz archive for $FILENAME stored?"
        echo -n "(just specify a directory with / at the end, filename is automatic) >  "
        echo ""
        read SAVEPATH
        if [ -z $SAVEPATH ]; then
                echo "No directory specified. Exiting..."; exit 1;
        fi
        if [ ! -d $SAVEPATH ]; then
                echo -n "$SAVEPATH does not exist. Would you like to create it? (y/n) >  ";
                read $answer
                        if [ "$answer" != "y" ]; then
                                echo "O.K. Exiting..."; exit 1;
                        fi
        fi
        echo "Making directory $SAVEPATH..."
        mkdir $SAVEPATH
        echo ""
        echo "$SAVEPATH created..."

i know i have to be overlooking a syntax error (or i just don't have it set up correctly) because, when i test the program with a directory that doesn't exist, it asks if I want to create it, i signal "y", and then it immediately exits... what am i doing wrong?

edit -

also, when i give it a directory that does exist, it does the mkdir $SAVEPATH command... i must have them switched up somehow. what should this look like?

Put mkdir inside the if statement.
# 12  
Old 03-03-2009
Quote:
Originally Posted by cfajohnson

What does the timestamp have to do with it?


i guess nothing. i appreciate the help you've provided, but comments like that are not constructive. perhaps you can explain why the timestamp has nothing to do with overwriting files... obviously i don't know. otherwise, i prefer you just not answer at all. i'm looking for help, not to be talked to condescendingly.

Quote:
Quote:
Put mkdir inside the if statement.
i have done that, with this format:

Code:
 if [ ! -d $SAVEPATH ]; then
                echo -n "$SAVEPATH does not exist. Would you like to create it? (y/n) >  ";
                read $answer
                        if [ "$answer" != "y" ]; then
                                echo "O.K. Exiting..."; exit 1;
                        else
                                echo "Making directory $SAVEPATH";
                                mkdir $SAVEPATH;
                                echo ""
                                echo "$SAVEPATH created.";
                        fi
        fi

i get the same results: the prog says "O.K. Exiting..."
# 13  
Old 03-03-2009
Quote:
Originally Posted by jmd9qs
i guess nothing. i appreciate the help you've provided, but comments like that are not constructive. perhaps you can explain why the timestamp has nothing to do with overwriting files... obviously i don't know. otherwise, i prefer you just not answer at all. i'm looking for help, not to be talked to condescendingly.

That was a serious question intended to make you think about it, rather than leaving you with a wrong idea that could break one of your scripts.

And as for "explain why the timestamp has nothing to do with overwriting files", there is nothing to explain. Why would you think they do have anything to do with it?
Quote:

i have done that, with this format:

Code:
 if [ ! -d $SAVEPATH ]; then
                echo -n "$SAVEPATH does not exist. Would you like to create it? (y/n) >  ";
                read $answer ## not read $answer


Code:
read answer

Quote:
Code:
                        if [ "$answer" != "y" ]; then
                                echo "O.K. Exiting..."; exit 1;
                        else
                                echo "Making directory $SAVEPATH";
                                mkdir $SAVEPATH;
                                echo ""
                                echo "$SAVEPATH created.";
                        fi
        fi

i get the same results: the prog says "O.K. Exiting..."
# 14  
Old 03-03-2009
Quote:
Originally Posted by cfajohnson

That was a serious question intended to make you think about it, rather than leaving you with a wrong idea that could break one of your scripts.

And as for "explain why the timestamp has nothing to do with overwriting files", there is nothing to explain. Why would you think they do have anything to do with it?



obviously i misinterpreted you. i apologize (sometimes intent isn't too clear when dealing with text online Smilie )

as far as the timestamp issue goes, I see your point (i think): the timestamp is added AFTER the $SAVEPATH is chosen, thus really not affecting the $SAVEPATH at all. the reason i (thought) i wanted an "overwrite" option is because i dont have much free HDD space... i want to backup my important data, but can't afford to store each backup.

fixing
Code:
read $answer

to
Code:
read answer

fixed the issue. thanks again for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Newbie needs help with some bash scripting

Please bear with me, I'm a beginner but have had some experience and decent knowledge to understand things as I read them and I'm in the process of trying to learn more. I recently inherited a UNIX server which has a bash script which is part of a crontab schedule that needs to be modified (or... (3 Replies)
Discussion started by: Danylko
3 Replies

2. Shell Programming and Scripting

Bash scripting - Newbie

Hi all, I have drill to do and I'll very appreciate your help: Please create a simple CSV file as follow (3 columns and 4 rows): A,B,C A,”B,C”,D “A,B”,C,D o A,B,”C,D” - Please refer to the comma between the quotation marks as a parameter and not as a separator. - Please provide... (3 Replies)
Discussion started by: elior
3 Replies

3. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

4. Shell Programming and Scripting

Shell Scripting Newbie

Hi Guys, I want to create a shell script to run multiple jobs in sequence. Explaination - If I were to run each jobs individually I would have gone to folder - "abin"(where my shellscript is place) as follows cd abin abin > runappeng.sh abc001 Now, I have list of programs which are like... (8 Replies)
Discussion started by: chaits84
8 Replies

5. Shell Programming and Scripting

Scripting needed for newbie

Hi, I am newbie in shell scripting I have a file name like simple.txt which comes from Mainframe systems onto windows dir every 15 minutes daily. File name is same. Every 15 minutes it updates. I need to write shell script to check if the file arrived every 15 min or not. If the new file... (4 Replies)
Discussion started by: chinniforu2003
4 Replies

6. Shell Programming and Scripting

Shell Scripting NEWBIE - Need Help

Could someone please recommend a very good shell scripting book for me. I would be starting a new job that would require a very good understanding of shell scripting. Please help. (3 Replies)
Discussion started by: ayoka
3 Replies

7. Shell Programming and Scripting

scripting newbie needs help

I have written a script that will email a generic user when a device is "offline". I would like to enhance this by having the script lookup a contact's email and automatically add it to the MAIL_LIST. I am trying to lookup and return data based on a field common in two files File 1 ... (0 Replies)
Discussion started by: irishluck66
0 Replies

8. Shell Programming and Scripting

Scripting Newbie

Seems simple but I am having difficulty with this one: I am trying to write a single command line argument (which will be a path) - the program should print out the owner of the path. I can not get anything I write to run. Please help. (5 Replies)
Discussion started by: Kymmers7
5 Replies

9. UNIX for Dummies Questions & Answers

Shell Scripting Newbie

I'm relatively new at this scripting game, just need to learn some basic stuff for data handling. My current need is to write a script that loops through a textfile of filenames, and for each file removes the first line and re-writes that file to a new name. In fact I could do with knowing... (1 Reply)
Discussion started by: mattyjim2
1 Replies

10. Shell Programming and Scripting

Newbie - Need help in bash scripting

Hi there, I am a student and currently working on a project. I have a file that contains about 50 filenames. (1.txt, 2.txt, 3.txt ...). I would like to know how can I store these filenames into a variable using a loop? I would appreciate if anyone can help me. Thank You. Regards, Bib (4 Replies)
Discussion started by: coolbib
4 Replies
Login or Register to Ask a Question