Script Problem

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Script Problem

Postby Dave-Pritchard » Tue Jul 06, 2010 9:31 pm

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 ~]$
Dave-Pritchard
 
Posts: 33
Joined: Sun Jan 08, 2006 8:59 pm

Postby MartyBartfast » Tue Jul 06, 2010 9:39 pm

Well
Code: Select all
dir2="/media:/sdf1"

has a superfluous colon

and
Code: Select all
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.
User avatar
MartyBartfast
LXF regular
 
Posts: 820
Joined: Mon Aug 22, 2005 7:25 am
Location: Hants, UK

Script Problem

Postby Dave-Pritchard » Wed Jul 07, 2010 8:25 am

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 ~]$
Dave-Pritchard
 
Posts: 33
Joined: Sun Jan 08, 2006 8:59 pm

Postby nelz » Wed Jul 07, 2010 1:31 pm

What does
Code: Select all
 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)
User avatar
nelz
Site admin
 
Posts: 8577
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Script Problem

Postby Dave-Pritchard » Thu Jul 08, 2010 7:13 am

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..
Dave-Pritchard
 
Posts: 33
Joined: Sun Jan 08, 2006 8:59 pm

Postby Ram » Thu Jul 08, 2010 8:38 am

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.....
User avatar
Ram
LXF regular
 
Posts: 1684
Joined: Thu Apr 07, 2005 9:44 pm
Location: Guisborough

Script Problem

Postby Dave-Pritchard » Fri Jul 09, 2010 10:25 pm

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..
Dave-Pritchard
 
Posts: 33
Joined: Sun Jan 08, 2006 8:59 pm

Postby ajgreeny » Sat Jul 10, 2010 12:49 pm

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!
ajgreeny
LXF regular
 
Posts: 462
Joined: Wed May 10, 2006 8:18 pm
Location: Oxfordshire.


Return to Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests