Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 27th, 2006, 01:05 AM
Xpose Xpose is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 Xpose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 57 sec
Reputation Power: 0
Question Back up script

Trying to mess with a backup script but not having much luck

If anyone can give a helping hand would be much appreciated.

Im trying to get the script to:

1) Prompt for the name of the user account;
2) Prompt for the file name to be backed up
3) If the filename is a directory
display the message "<Filename> is a directory"

Else

Backup the user file by copying it into users home directory

Hope to get some help
Cheers,

Reply With Quote
  #2  
Old May 27th, 2006, 08:45 AM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 814 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 8 m 11 sec
Reputation Power: 243
Show us what you have so far.
I assume it will have:

A prompt for user name.
A check to see if user is valid.
A prompt for file to select
A check on file type
A check on permissions on source and target
A copy
A check of exit code from the copy

Reply With Quote
  #3  
Old May 29th, 2006, 01:59 AM
Xpose Xpose is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 Xpose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 57 sec
Reputation Power: 0
Sorry for late reply havent been on over weekend.

So far what i got i need a check on the setup,spacing and how exactly to finish the copy of the file.

echo "Enter username:"
read name
if [ -d \home\$name ]
then echo "Valid username"
ls $name
else echo "Invalid username"

echo "enter filename"
read file
if [ -d $file]
then echo "Valid file"
else echo $file "is a directory" (not to sure whether $file should be inside the brackets here)

now as for the actual backup will it just be a: cp source | $file not to sure here.

Thanks in advance any help at all will be appreciated.

Reply With Quote
  #4  
Old May 29th, 2006, 05:04 AM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 814 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 8 m 11 sec
Reputation Power: 243
Ok, just a few pointers,as what you have is basically just about there.
Just checking that a directory called /home/$name exists does not prove that user exists/is valid. You do not have a check for null input when you prompt for data. Your if statements need a balancing fi to terminate them. The test for file/directory seems to be inverted from your original requirement.

Some hints:
Code:
# Obtain user name
echo "Enter username: \c"
read name
if [ "$name" = "" ]
then
  echo "No name entered, exiting"
  exit 2
fi
# Check user exists and get their home directory
namedir=`grep "^${name}:" /etc/passwd | awk -F: '{print {$?}'`
if [ "$namedir" = "" ]
then
  echo "Invalid user"
  exit 3
else
  if [ ! -d $namedir]
  then
    echo "user home dir is not valid"
  fi
fi
# Got here,so valid user, valid home dir.
# Now get file to backup
echo "Enter file to backup: \c"
read $file
if [ ["$file" = "" ]
then
  echo "No file specified"
  exit 4
fi
if [ -d $file ]
then
  echo "$file is a directory"
elif [ ! -f $file ]
  echo "$file is not a standard file or does not exist"
else
  cp $file $namedir
  cp_rc=$?
  if [ [ $cp_rc -ne 0 ]
  then
    echo "backup of $file to $namedir failed - code $cp_rc"
  fi
fi
  
Comments on this post
Xpose agrees: Was very useful and helped me towards completion of the script
__________________
According to Sod's Law, buttered toast lands butter side down, when dropped.
Per nature, cats always land on their feet.
So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
.

Reply With Quote
  #5  
Old May 29th, 2006, 05:50 AM
Xpose Xpose is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 Xpose User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by Ehlanna
Ok, just a few pointers,as what you have is basically just about there.
Just checking that a directory called /home/$name exists does not prove that user exists/is valid. You do not have a check for null input when you prompt for data. Your if statements need a balancing fi to terminate them. The test for file/directory seems to be inverted from your original requirement.

Some hints:
Code:
# Obtain user name
echo "Enter username: \c"
read name
if [ "$name" = "" ]
then
  echo "No name entered, exiting"
  exit 2
fi
# Check user exists and get their home directory
namedir=`grep "^${name}:" /etc/passwd | awk -F: '{print {$?}'`
if [ "$namedir" = "" ]
then
  echo "Invalid user"
  exit 3
else
  if [ ! -d $namedir]
  then
    echo "user home dir is not valid"
  fi
fi
# Got here,so valid user, valid home dir.
# Now get file to backup
echo "Enter file to backup: \c"
read $file
if [ ["$file" = "" ]
then
  echo "No file specified"
  exit 4
fi
if [ -d $file ]
then
  echo "$file is a directory"
elif [ ! -f $file ]
  echo "$file is not a standard file or does not exist"
else
  cp $file $namedir
  cp_rc=$?
  if [ [ $cp_rc -ne 0 ]
  then
    echo "backup of $file to $namedir failed - code $cp_rc"
  fi
fi
  


Thanx heaps for the help man when i get some time later on tonight ill get in there and have a fiddle around.

And ill have to "man" some of those commands and learn something new

Thanx again ill let you know how i go

Reply With Quote
  #6  
Old May 29th, 2006, 06:26 AM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 814 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 8 m 11 sec
Reputation Power: 243
Meant to say that the ? in the awk command is just a placeholder as I cannot, off the top of my head, remember which colon-delimited field the hoe directory is! Find that out and change the ? to the right number.
And it is nice to see someone willing to RTFM!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Back up script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway