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
break(1)							   User Commands							  break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 11:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy