Shell scripting/working with a file | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Shell scripting/working with a file

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-18-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Shell scripting/working with a file

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:

1. Write a shell script that will work with a file from the command line.

The program should:
a. Check for the existence of a bkup directory in your home directory. If it does not exist create it.

For the file:
b. Verify that the file exists
c. Copy it to the bkup directory in your home directory.
d. Issue messages on the success or failure of each file copy to a log file.
e. Print out a copy of the log file and the bkup directory at the end of the program.

Print out a copy of the program and an example of the output.

2. Relevant commands, code, scripts, algorithms:

shell programming/scripting

3. The attempts at a solution (include all code and scripts):

1.
Code:
#!/bin/bash

if [ -d /var/home/stud3/myname/bkup ]; then
	mkdir /var/home/stud3/myname/bkup
elif [ -f /foo.txt ]
then
	cp foo.txt /var/home/stud3/myname/bkup && echo The file was copied
else
	echo The file was not copied
fi 

-print logfile

I do not think this is right, but it is my best attempt.

P.S. I was not sure how to print the bkup directory

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

Brookdale Community College - Lincroft, New Jersey - United States - Dr. Rick Bournique- COMP 145


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).
Sponsored Links
    #2  
Old 04-19-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 18 September 2014, 3:28 PM EDT
Location: Switzerland - GE
Posts: 5,724
Thanks: 156
Thanked 400 Times in 375 Posts
From my understanding ( non anglophone world...), you are not far from succeeding...
But from a) to b) I dont understand "and exit" at the end of a) but as mentionned I may be wrong in understanding, but in my logic to process an existing file, the prerequisite is to have a backup directory and so after check of existence and creation if non existent you continue (and so no else/elif ...) for you would end with not processing a existing file because you had no backup directory...

c) crazy guys like sysadms like to keep files with their timestamp so we would cp with the according arguments...even more we would use the date as a suffix so the file would not be overwritten by mistake, and it would be more in the "spirit" of having backups in such way you could have in your log file e.g. a long with long listing of the new file created...
d) I see no log file created...
e) what comforts me in my understang here is this task, if you were to copy the file "as it is", here you would only have one file with just the timestamp changing (well ok and size...)
Do you agree?
Sponsored Links
    #3  
Old 04-21-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
It was exists not exit I am having a tough time with this, any other advice anyone?
    #4  
Old 04-21-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts

Code:
if [ -d /var/home/stud3/myname/bkup ]; then
	mkdir /var/home/stud3/myname/bkup

Are you sure about the logic here?
Take another look, say out loud what's supposed to happen.
Hint: it ain't correct.
Sponsored Links
    #5  
Old 04-22-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 18 September 2014, 8:25 PM EDT
Location: Amsterdam
Posts: 9,460
Thanks: 279
Thanked 2,384 Times in 2,137 Posts
Also, there is difference between foo.txt and /foo.txt
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell scripting - need to arrange the columns from multiple file into a single file siva kumar Shell Programming and Scripting 3 03-14-2013 10:05 AM
Need to create file from shell scripting smr_rashmy Shell Programming and Scripting 4 01-28-2008 09:59 PM
file permissions using shell scripting barbus Shell Programming and Scripting 11 10-02-2007 02:51 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
file activity (open/closed) file descriptor info using KORN shell scripting Gary Dunn UNIX for Dummies Questions & Answers 3 06-07-2004 01:54 PM



All times are GMT -4. The time now is 11:46 PM.