Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script Problem

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Dave-Pritchard



Joined: Sun Jan 08, 2006 8:59 pm
Posts: 33

PostPosted: Tue Jul 06, 2010 10:31 pm    Post subject: Script Problem Reply with quote

Hi

My first attempt at writing/using a script, basicly taken from
LXF 126 PAGE 48 TO 51 to do a backup.
The computer is not always on, so I need to backup when needed
hopefully from an icon if possible, however the script does not work. any help most welcome. Script and error message follows.
Dave P..


#!/bin/sh
clear
echo "STARTING BACK-UP OF /HOME/DAVE/"
dir1="/home/dave/"
dir2="/media:/sdf1"

if[ -d $dir1 -a -d $dir2 ]
then
rsync --recursive --times --perms --exclude "~*" --exclude "*bak" $dir1 $dir2
echo "BACK-UP COMPLETE"
elif[ -d $dir1 ]
then
mkdir $dir2
rsync --recursive --times --perms --exclude "~*" --exclude "*bak" $dir1 $dir2
echo "BACK-UP COMPLETE"
else
echo "UNABLE TO LOCATE SOURCE DIRECTORY"
fi

Running the script produces the following

STARTING BACK-UP OF /HOME/DAVE/
backup.sh: line 8: if[ -d /home/dave -a -d /media:/sdf1 ]: No such file or directory
backup.sh: line 9: syntax error near unexpected token `then'
backup.sh: line 9: `then'
[dave@localhost ~]$
Back to top
View user's profile Send private message
MartyBartfast
LXF regular


Joined: Mon Aug 22, 2005 8:25 am
Posts: 814
Location: Hants, UK

PostPosted: Tue Jul 06, 2010 10:39 pm    Post subject: Reply with quote

Well
Code:

dir2="/media:/sdf1"

has a superfluous colon

and
Code:

if[ -d $dir1 -a -d $dir2 ]

needs a space between if and [

edit to add, same problem with elif[
HTH
_________________
I have been touched by his noodly appendage.
Back to top
View user's profile Send private message
Dave-Pritchard



Joined: Sun Jan 08, 2006 8:59 pm
Posts: 33

PostPosted: Wed Jul 07, 2010 9:25 am    Post subject: Script Problem Reply with quote

Hi
Thanks for the reply, previous errors cleared, but I am getting a permission denied error, not sure if this is the correct place to post this type of problem.
/media/sdf1/ is a usb hard drive, permissions owner = dave group = dave
device node = /dev/sde1 & base url = file:///media/hd
still stuck, so any help most welcome
Dave P..

script and error message follows


#!/bin/sh
clear
echo "STARTING BACK-UP OF /HOME/DAVE/"
dir1="/home/dave/"
dir2="/media/sdf1/"

if [ -d $dir1 -a -d $dir2 ]
then
sync --recursive --times --perms --exclude "~*" --exclude "*bak" $dir1 $dir2
echo "BACK-UP COMPLETE"
elif [ -d $dir1 ]
mkdir $dir2
rsync --recursive --times --perms --exclude "~*" --exclude "*bak" $dir1 $dir2
echo "BACK-UP COMPLETE"
else
echo "UNABLE TO LOCATE SOURCE DIRECTORY"
fi

Error message follows

STARTING BACK-UP OF /HOME/DAVE/
mkdir: cannot create directory `/media/sdf1/': Permission denied
rsync: mkdir "/media/sdf1" failed: Permission denied (13)
rsync error: error in file IO (code 11) at main.c(529) [receiver=2.6.9]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(453) [sender=2.6.9]
BACK-UP COMPLETE
[dave@localhost ~]$
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8457
Location: Warrington, UK

PostPosted: Wed Jul 07, 2010 2:31 pm    Post subject: Reply with quote

What does
Code:
 ls -ld /media/sdf1

show. Is the drive mounted when you run this script?
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
Dave-Pritchard



Joined: Sun Jan 08, 2006 8:59 pm
Posts: 33

PostPosted: Thu Jul 08, 2010 8:13 am    Post subject: Script Problem Reply with quote

Hi thanks for the reply

here is the result from the suggested command

[dave@localhost ~]$ ls -ld /media/sdf1
ls: cannot access /media/sdf1: No such file or directory
[dave@localhost ~]$

clicking on the "storage media" icon, brings up konqueror with an icon for the usb drive, I am able to copy to and from the drive, brining up the permissions/mounting indicates - mountpoint /media/hd , also mount automaticaly is ticked.
looking at /media/hd just displays the /home/dave desktop icons !

I tried running the script while konqueror was open and accessing the drive, but with the same result.

Dave P..
Back to top
View user's profile Send private message
Ram
LXF regular


Joined: Thu Apr 07, 2005 10:44 pm
Posts: 1671
Location: Guisborough

PostPosted: Thu Jul 08, 2010 9:38 am    Post subject: Reply with quote

When the drive is mounted, what do you actually see listed in /media/ ?
_________________

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
Back to top
View user's profile Send private message MSN Messenger
Dave-Pritchard



Joined: Sun Jan 08, 2006 8:59 pm
Posts: 33

PostPosted: Fri Jul 09, 2010 11:25 pm    Post subject: Script Problem Reply with quote

Hi thanks for the reply
/media/ has 3 directories cdrom, floppy, & hd
/media/hd has the contents of the usb drive, so I changed dir2 to
dir2 = "media/hd" and the script works OK

( it could not copy 2 directories named Cuba and Tanzania, the usb drive will not accept directories with these names, or rename another to to them !!!
HOW WEEEERED )

Dave P..
Back to top
View user's profile Send private message
ajgreeny
LXF regular


Joined: Wed May 10, 2006 9:18 pm
Posts: 452
Location: Oxfordshire.

PostPosted: Sat Jul 10, 2010 1:49 pm    Post subject: Reply with quote

Has the usb disk partition been given the label "hd" at some point in its history, as that would explain why it was mounting in a folder named /media/hd.

If any usb disks I own are not already labeled appropriately by their manufacturer, I quickly give them a label I will know and recognise to make life that little bit easier for me.

Odd about those two folders that will not copy, however. Must be a permissions problem of some sort, I suspect.
_________________
Xubuntu 12.04 user, and loving it!
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast