help on this command, creating ..

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions help on this command, creating ..
# 1  
Old 03-25-2010
help on this command, creating ..

1. The problem statement, all variables and given/known data:


Description



Bsafe The command creates a backup directory of each month at the command line (arguments of the script). The names of directories to copy will always be specified for the home user. To save copies of the script uses a specific directory, now called the backup directory. If the backup directory does not exist, the script should create it. Within the backup directory, the script should create a directory for each backup done (use a different name every time). Within this directory (the copy of the instant), each directory passed as argument of the script should be copied, including sub-directories and files, preserving dates and times of access and modification of them. Of course, the backup directory should not be copied into itself.

2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):
Code:
#!/bin/bash
DIR=base/path/of/your/backup/dir/$(date +%y%m)
[ -d "$DIR" ] || mkdir "$DIR"
for D in $@ # gets the arguments of the command line
do
    cp -av ~/"$D" "$DIR/$D"
done

the command, need create a backup file/directory if not exist at /home, and inside of that directory, each copy safe(the command), create a subdirectory inside of backup, example: backup1, backup2...((each directory passed as argument of the script should be copied, including sub-directories and files, preserving dates and times of access and modification of them)).


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of leiria, Isla, leiria, Portugal, Unisla - Apresentação, Rosalina Pires

Last edited by pludi; 03-25-2010 at 05:33 PM.. Reason: code tags, please...
# 2  
Old 03-26-2010
You are asked to write a command that does many things depending of prerequisites and arguments entered.

You cant just like that write a program unless you are very experienced... I mean by that :
You start by analysing what is being asked and how it can be achieved!
That part you say nothing, so start by giving us How you see it should be done through a pseudocode or algorithm, here we can already give you our point of vue and correct you if necessary, the programming itself is just transcribing correctly in a language the algorithm.
# 3  
Old 03-26-2010
vbe

ok..

what i need to is create a command than will do a save copy each directory at line prompt through home... that is what i not understand, i m new in shell script, to safe the copy of directorys , the command need crete a new directory with the name backup inside of /home...
# 4  
Old 03-26-2010
Still no analyse...

hints:
1)Your command reads arguments no?
You will need to be able to parse them and see one by one if they are directories...
if no argument are passed, I suppose you will have to display a "usage "message that you will do in all cases for all errors...
2)If we agree on what is to be copied, this part isnt the difficult one...
# 5  
Old 03-26-2010
1) yes... ok a if condition... can you give a example, please, not the answer but a example... i need to do that today Smilie?

2) cp... ok...
backsave.sh

---------- Post updated at 01:11 PM ---------- Previous update was at 01:04 PM ----------

how i cp the dir...

and after this.. i could do it..

if /backup=0

mkdir BACKUP /HOME..
??
# 6  
Old 03-26-2010
If its for today.. you are a bit late my friend...

TODO
Code:
1) I need to analyse the line entered
   a) IF no argument 
           THEN Display "usage ....command with proper syntax..."
           exit  exit-value
      ELSE
          UNTIL no arguments left
          Do
              Check IF argument is a directory
                       If so is it in $HOME?
                           etc...
.
.
2)# Does backup dir exist? If not create it...
  .

3)#Within the backup directory, the script should create a directory for each backup done 
(use a different name every time).# you could use the date added to backup- for name...

.
.
etc...
..
.

Without a minimum of analyse and algorithm describing how you intend to do things I see not how you will be able to fullfill the task appointed to you..
You need to be clear in your head of how, that means each elementary task has been put in procedures and organized into an algorithm before thinking of coding where here the question is : "what will be the best command to achieve such task?" ...
# 7  
Old 03-26-2010
#!/bin/bash
DIR=/dir/$(date +%y%m)
[ -d "$DIR" ] || mkdir "$DIR"
for D in $@ # obtem os argumentos/get the arguments
do
cp /usr/home/backup**
if backup=null then

mkdir backup

**thats possible??

u are right but i m working man too.. thanks to advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating file and passing argument to a command

Hi All, I am having command to run which will take argument as input file. Right now we are creating the input file by cat and executing the command ftptransfer -i input file cat >input file file1 file2 cntrl +d Is there a way I can do that in a single command like ... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

2. Shell Programming and Scripting

Using -text command and creating multiple files

Currently using the below script to being all compressed files .gz files from source folder and appending to the target txt file uncompressed. Teh target txt file is getting too large in size, right now the size of the target txt file is almost 350GB hadoop fs -text... (3 Replies)
Discussion started by: cplusplus1
3 Replies

3. Shell Programming and Scripting

creating own command interpreter like bash...??

Hello senior members, I am a fairly newbie here. I just want to ask one question that how can once create one's own command interpreter/ shell like bash in unix/linux. I need to execute basic commands like pipes and i/o. Any help in this matter ?? (3 Replies)
Discussion started by: duma188
3 Replies

4. UNIX for Dummies Questions & Answers

Creating File using the CAT Command

Hello , I am newbie to UNIX platform . I have read that there are two ways of creating files that is using 1.) Cat 2.) touch . With Cat Command i am unable to create a File , i is saying No file or Directory exists I logged in with root as user . please help (7 Replies)
Discussion started by: Ravi Pavanv
7 Replies

5. UNIX for Dummies Questions & Answers

creating a command and sorting???

How do you write a command line that displays the number of files in the working directory with names that end with the letter S? Thanks ---------- Post updated at 09:34 PM ---------- Previous update was at 09:33 PM ---------- for unix sorry (1 Reply)
Discussion started by: jorogon0099
1 Replies

6. Shell Programming and Scripting

Creating a command on a BASH shell

Hi all. Suppose I have the following function in an executable file named "HOLA": ------------------------ function hola { echo "Hola ${@}."; } ------------------------ In addition, suppose that I want to execute the file so I can input my name next to ./HOLA. I mean,... (4 Replies)
Discussion started by: hresquivelo
4 Replies

7. Solaris

Creating a Man page for a command

Hi, I would like to develop a man page as the one we usually get when we execute man <command name>. This man page will be for a samll utility that i have written. If this is not possible then what are the available possibilites for creating such help. thanks in advance. (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

8. UNIX for Dummies Questions & Answers

Creating a file that contains output from a command, and then displays itself

hey, I'm trying to create the command that will create a file named user.txt that contains the output of the command cut -d: -f1,5 /etc/passwd, and displays itself afterwards. I don't know how to bridge cat > user.txt with cut -d: -f1,5 /etc/passwd, or how display it afterwards. Any help would... (2 Replies)
Discussion started by: raidkridley
2 Replies

9. OS X (Apple)

creating a new profile from command line

Does any1 know how to preform such an operation on a mac? any help appreciated (2 Replies)
Discussion started by: cleansing_flame
2 Replies

10. Shell Programming and Scripting

creating file of 1MB using shell command?

Hi everybody in the forum, I want to create an empty file of say some 1MB ,i mean at the command line itself.How is this possible??????EEK! (4 Replies)
Discussion started by: vijaya2006
4 Replies
Login or Register to Ask a Question