Syntax error with automated backup script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error with automated backup script
# 1  
Old 05-13-2011
MySQL Syntax error with automated backup script

Hi guys,

I'm new to Linux and dont know much of scripting..there's an automated backup script that will backup the database from a location to another location between servers..it was created by another person and I tried to understand it somewhat..

I hope the script first checks if mount point is mounted and then starts backing up the database using From and To arguments..this script is to be added to crontab for daily backup..

I tried to run this script but it gives me syntax error...could someone please help me out with this..thanks in advance...Smilie

Quote:
#!/bin/bash
#
# creates backups of updated files for given day
#
# usage: backup_script.sh <from location> <to location>
# eg: backup_script.sh /home/oracle /backup/server/database/
# function DailyBackup()
#Variable declaration
FromLoc=$1
TOLoc=$2
FileName=D`date +%d`
mnt_point=/backup/
command=$(mount | grep $mnt_point | cut -d\ -f3)
{
{
if [ "$command" != "$mnt_point" ]
then
mount 122.23.1.12:/backup $mnt_point
else
echo "$mnt_point already mounted"
fi
}
{
find $FromLoc -mtime -2 -type f -print | tar zcvf $TOLoc/"$FileName".tgz -T -
}
}
Quote:
[root@server dbascript]# sh backup_script.sh
: command not foundine 14: {
: command not foundine 15: {
backup_script.sh: line 27: syntax error: unexpected end of file

Last edited by koolhart; 05-13-2011 at 11:54 AM..
# 2  
Old 05-13-2011
Almost certainly this script has been edited with a Microsoft editor such as Notepad rather than a unix editor such as "vi".
To prove this, please check the script file with the following "sed" command which is designed to make control codes visible.

Code:
sed -n l scriptname

A normal unix text file will display a "$" at the end of each line. A MS-DOS format file will contain "^M" characters.
# 3  
Old 05-13-2011
hi...thanks for the help..I tried the "sed" command like u said and the result is as given below...

Quote:
[root@server]$ sed -n l backup_script.sh
#!/bin/bash\r$
#\r$
# creates backups of updated files for given day\r$
#\r$
# usage: backup_script.sh <from location> <to location>\r$
# eg: backup_script.sh /home/oracle /backup/server/database/\r$
# function DailyBackup()\r$
#Variable declaration\r$
FromLoc=$1\r$
TOLoc=$2\r$
FileName=D`date +%d`\r$
mnt_point=/nfs_backup/\r$
command=$(mount | grep $mnt_point | cut -d\\ -f3)\r$
{\r$
{\r$
if [ "$command" != "$mnt_point" ]\r$
then\r$
mount 122.23.1.12:/backup $mnt_point\r$
else\r$
echo "$mnt_point already mounted"\r$
fi\r$
}\r$
{\r$
find $FromLoc -mtime -2 -type f -print | tar zcvf $TOLoc/"$FileName\
".tgz -T -\r$
}\r$
}\r$
I normally use vi backup_script.sh to look up the file and use "i" to insert into it and quit with :x! to save the changes...

wat am i do next...pls help...

Last edited by koolhart; 05-13-2011 at 11:53 AM..
# 4  
Old 05-13-2011
Yep. The ctrl-M (carriage-return) characters show as "\r".
This script file is in MS-DOS text file format not unix text file format.

What Operating System and version are you running? Most of them come with utilites to convert MS-DOS text files to unix format. Failing that there are ways to remove the carriage-return characters.


One fairly portable method is:
Code:
cat scriptname | tr -d "\032" | tr -d "\r" > newscriptname

This removes ctrl/Z (MS-DOS end-of-file) and ctrl/M (carriage return).

Last edited by methyl; 05-13-2011 at 11:59 AM..
# 5  
Old 05-13-2011
hi...

Its Red Hat Enterprise Linux ES release 4 (Nahant Update 2)

cat scriptname | tr -d "\032" | tr -d "\r" > newscriptname
I ran the script and got it conv to unix format...what is the other option to conv MSDOS file to unix format...

Will converting the script to unix format solve the problem or something else that I gotta do..

I'm trying to run the script now...will keep u posted..thanks for all the help..

any suggestions welcome...



Last edited by koolhart; 05-13-2011 at 12:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error on script

Evening All (or morning for some), Could anyone have a look at the below and advise where i've going wrong with the syntax as i keep getting the below error while trying to run. Any help would be really apprecaited. ./testout: line 13: syntax error near unexpected token `else' ... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

First Script Syntax Error

So, I'm writing my first shell script to try to speed up the process of creating lyric files for mocp and I don't know what the error is, but considering how short the code is, I'm betting it's something super-obvious. line 7: syntax error near unexpected token `echo' line 7: ` echo... (4 Replies)
Discussion started by: D351
4 Replies

3. UNIX for Dummies Questions & Answers

Syntax Error Script

Hi guys i'd like to show you this code of my script, where i couldn't find this error " #! /bin/bash #copiabin.sh: copia todos los archivos ejecutables a bin if then mkdir $HOME/bin fi # copia de archivos y contador N N=0 for ARCH in * do if # Si el archivo es... (9 Replies)
Discussion started by: Newer
9 Replies

4. UNIX for Dummies Questions & Answers

Syntax error with backup script

Hi guys, I'm new to Linux and dont know much about scripts..there's an backup script that will backup the database from a location to another location between servers..it will run automatically by adding it to crontab...it was created by another person and I tried to understand it somewhat.. ... (1 Reply)
Discussion started by: koolhart
1 Replies

5. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

6. UNIX for Dummies Questions & Answers

to take backup what is the command tell syntax

to take backup what is the command tell syntax (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

7. Shell Programming and Scripting

Syntax error in script

Hey guys keep having problems with the below script syntax error near unpexpected token '0' exit 0 I have two directorys backups and Usr in the usr i have sub dir's wp,ss,pic which i would like to back up (copy those directorys to the backups directory) with user acknowledgement from command line.... (2 Replies)
Discussion started by: Spartukus
2 Replies

8. UNIX for Dummies Questions & Answers

Automated backup script

I want to create an automated backup script that will copy files to different directories for different days. I will use a detachable USB drive, under SCO 5.0.7. I am very new to Unix, and will require most of the script. Thanks (5 Replies)
Discussion started by: Bennieinbots
5 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

syntax error in script !!

./disk_space_util.sh ./disk_space_util.sh: Syntax error at line 24 : `then' is not expected. ================================= cat disk_space_util.sh #!/bin/sh # # Parameter Settings ORA_LOG, ORA_SCRIPT, DBA_EMAIL_LIST -- (Set in .profile) bdf | sed "s/%/ /g" | sed "/Filesystem/d" |... (13 Replies)
Discussion started by: uuser
13 Replies
Login or Register to Ask a Question