LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2006, 06:34 PM   #1
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 91

Rep: Reputation: 15
Simple script won't work


Dear Group
I have a script located inside a file:
/home/medicus/backup2.sh
(the contents of the script are below)

When I try to run it, I get the following error messages and the script does not execute. However, if I enter each line at the command prompt, it does execute:

[root@compused medicus]# sh ./backup2.sh
busy: /dev/sda1 already mounted or /tmp/usb
mount: according to mtab, /dev/sda1 is already mounted on /tmp/usb
Performing backup...
: command not found5:
============================================
: command not found6:
: command not found7:
gbak: readied database /opt/firebird/bin/mIBDB for backup
gbak: creating file /tmp/usb/mIBDB.gbk
gbak: cannot open backup file /tmp/usb/mIBDB.gbk
gbak: Exiting before completion due to errors
============================================
: command not found9:
'leep: invalid time interval `5
Try `sleep --help' for more information.
./backup2.sh: line 20: syntax error: unexpected end of file
[root@compused medicus]#

Here are contents of script:


#!/bin/sh
mkdir -p /tmp/usb
mount -t auto /dev/sda1 /tmp/usb
# perform backup
echo "Performing backup..." &&
echo "===========================================" &&
cd /opt/firebird/bin &&
./gbak -b -t -v -user sysdba -password masterkey /opt/firebird/bin/mIBDB /tmp/usb/mIBDB.gbk > /dev/null 2>&1
echo "============================================" &&
# wait a few seconds to make sure the disk is no longer being used
sleep 5
if [ "$?" == "0" ]; then
SCRIPT_MESSAGE="Backup completed successfully. It is safe to remove the drive"
else
SCRIPT_MESSAGE="Backup failed. To retry, please remove the drive, wait 10 seconds, and re-insert"
fi
umount /tmp/usb &&
rmdir /tmp/usb &&
echo "Backup Script Complete. Safe to remove drive."


Any help would be greatly appreciated

Sincerely
Compused
 
Old 11-19-2006, 07:12 PM   #2
card-suse
Member
 
Registered: Dec 2005
Location: Ohio, USA
Distribution: OpenSuSE 10.2
Posts: 74

Rep: Reputation: 15
Just from a quick look I think you need a line continuation "\" after each logical and (i.e. &&). For instance:

Code:
echo "Performing backup..." && \
echo "===========================================" && \
cd /opt/firebird/bin && \
yadayadayada......
That's why you keep seeing ":command not found". Try that.
 
Old 11-19-2006, 07:50 PM   #3
Sepero
Member
 
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 33
Here's a little bit better script for ya. The first problem you're having is that your USB device is _already_ mounted. Unmount it before you run the script.

Code:
#!/bin/sh
mkdir -p /tmp/usb
mount -t auto /dev/sda1 /tmp/usb || exit 1
# perform backup
echo "Performing backup..."
echo "============================================"
cd /opt/firebird/bin && \
./gbak -b -t -v -user sysdba -password masterkey /opt/firebird/bin/mIBDB /tmp/usb/mIBDB.gbk > /dev/null 2>&1
echo "============================================"
# wait a few seconds to make sure the disk is no longer being used
sleep 5
if [ "$?" == "0" ]; then
        SCRIPT_MESSAGE="Backup completed successfully. It is safe to remove the drive"
else
        SCRIPT_MESSAGE="Backup failed. To retry, please remove the drive, wait 10 seconds, and re-insert"
fi
umount /tmp/usb && \
rmdir /tmp/usb
echo "Backup Script Complete. Safe to remove drive."
 
Old 11-19-2006, 10:12 PM   #4
debuser123
Member
 
Registered: Nov 2006
Distribution: Ubuntu Hardy
Posts: 69

Rep: Reputation: 15
Get rid of those &&'s after the echos, they're unnecessary. However a cd some_directory && do_something_with_this_directory is fine.
 
Old 11-22-2006, 06:52 AM   #5
compused
Member
 
Registered: Oct 2006
Location: Melbourne Australia
Distribution: centos and redhat 8
Posts: 91

Original Poster
Rep: Reputation: 15
Thanks everyone....for sorting out the compusion

it works now

Best wishes

Am no longer 'compused'...well at least for the moment
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 12:45 PM
newbie, getting simple python script to work Monjawi Programming 6 10-03-2005 11:51 AM
Why doesnt my simple html post to cgi script work? ginda Linux - Networking 10 03-15-2005 03:32 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration