Sponsored Content
Full Discussion: A simple Backup script
Homework and Emergencies Homework & Coursework Questions A simple Backup script Post 302607656 by Waffles on Thursday 15th of March 2012 04:25:06 AM
Old 03-15-2012
A simple Backup script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
All I have to do is write a script that will take two arguments. The first argument is a list which will contain filenames. The second argument is a directory. Basically the idea is that this script will backup all the filenames that are listed in the file from the first argument.
I talked to my proffessor and looked at my book. Both have stated that A foreach loop is the best way to go about handling this assignment.

So far I can see that the foreach loop is only able to take in one argument. This works fine but I need to add another argument for the user to write so that the data is sent to the directory. Can I give a foreach loop more than one argument???



2. Relevant commands, code, scripts, algorithms:
#!/bin/csh

foreach filename (`cat $argv[1])
echo $filename
cat $filename
end

All this does is it takes a list of files, prints out the names of those files and then the content of each file.

3. The attempts at a solution (include all code and scripts):
I tried using the set $argv[1] = $< and set $argv[2] = $< to have the user give the arguments right away. But it didnt work. The subscript ws out of range.


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):



Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

University of Colorado at Colordo Springs
The Course is: CS209 Programming with Unix
The Proffessor is Pam Carter.

---------- Post updated at 02:21 AM ---------- Previous update was at 02:14 AM ----------

I forgot to mention that all I really need to do once I extract all the files from the filelist is use the mv or the cp command to copy or move them to the directory. It's really not that hard.

---------- Post updated at 04:25 AM ---------- Previous update was at 03:21 AM ----------

Nevermind. I figured it out.

heres the finished code:


#!/bin/csh
foreach filename (`cat $argv[1]`)
cp $filename $argv[2]
end


I didn't realize that $argv[2] can be placed anywhere in the script while still referring to the second argument. Its that whole idea of positional parameters. I was so used to coding with java and other programming languages that use order and where the placement of variables/parameters actually mattered. It took me about 5 hours to figure that out. I am mad and happy at the same time.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff. Backup Script Using TAR. Should be simple.

I'm specifically trying to find help or insight on using the --incremental ('-G') option for creating a tar. Please resist the urge to tell me to use --listed-incremental ('-g') option. That's fairly well documented in the GNU tar manual. GNU tar 1.19 This is what the manual does say in section... (0 Replies)
Discussion started by: protienplant
0 Replies

2. Shell Programming and Scripting

[bash] Simple backup (cp) script but incremental

Hi all, I would need a rather simple bash backup script that loops throught the (local) users and for each users backs up (cp!) its /home/username folder. About the functionalities: The script has to run every 2 hours (that's cron, so don't mind about that) and the files should be copied to... (12 Replies)
Discussion started by: laurens
12 Replies

3. Shell Programming and Scripting

How to create a simple shell script to backup

Hello - I am in process of deleting many files which are older than 4 weeks. For example I am inside: /subsystem/prod/ Files are with various extentions, but anything older than 4 weeks should be deleted. What would be the most simplest script to acheive this? (4 Replies)
Discussion started by: DallasT
4 Replies

4. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

7. Homework & Coursework Questions

Create a simple bash backup script of a file

This is the problem: Write a script that will make a backup of a file giving it a ‘.bak’ extension & verify that it works. I have tried a number of different scripts that haven't worked and I haven't seen anything really concise and to the point via google. For brevity's sake this is one of the... (4 Replies)
Discussion started by: demet8
4 Replies

8. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

9. Shell Programming and Scripting

Simple .sh and alias or ? whatever. Do backup!

Hi , Using bash shell (mintty) in cygwin/windows env. for some time and having issues with most basic commands. Will be quite easy to get er done once I know how , just like magic tricks. I need either alias OR shell script to change windows to posix path AND put that line back -input OR .cd to... (2 Replies)
Discussion started by: sircuts
2 Replies
foreach(n)						       Tcl Built-In Commands							foreach(n)

__________________________________________________________________________________________________________________________________________________

NAME
foreach - Iterate over all elements in one or more lists SYNOPSIS
foreach varname list body foreach varlist1 list1 ?varlist2 list2 ...? body _________________________________________________________________ DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been used to extract the element, then calls the Tcl interpreter to execute body. In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough elements for each of its loop variables in each iteration, empty values are used for the missing elements. The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string. EXAMPLES
This loop prints every value in a list together with the square and cube of the value: set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun! puts "Value Square Cube" ;# Neat-looking header foreach x $values { ;# Now loop and print... puts " $x [expr {$x**2}] [expr {$x**3}]" } The following loop uses i and j as loop variables to iterate over pairs of elements of a single list. set x {} foreach {i j} {a b c d e f} { lappend x $j $i } # The value of x is "b a d c f e" # There are 3 iterations of the loop. The next loop uses i and j to iterate over two lists in parallel. set x {} foreach i {a b c} j {d e f g} { lappend x $i $j } # The value of x is "a d b e c f {} g" # There are 4 iterations of the loop. The two forms are combined in the following example. set x {} foreach i {a b c} {j k} {d e f g} { lappend x $i $j $k } # The value of x is "a d e b f g c {} {}" # There are 3 iterations of the loop. SEE ALSO
for(n), while(n), break(n), continue(n) KEYWORDS
foreach, iteration, list, looping Tcl foreach(n)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy