I have the following bash script:

#!/bin/bash
set -e
cd /var/www/html/mydir
tar cvf backup.tar file1.php file2.php ...
mysqldump -u$1 -p$2 $3 mytable > sqlbackup.sql
tar xvf mypatch.tar
mysql -u$1 -p$2 $3 < mysqlpatchfromthetarpatch.sql
echo 'Success.'

Angry edit: I don't understand the downvote. In case that guy can't read a post from start to finish, i want to just extract some files, not run them. Here's the error:

[root@webserver]# ./myscript.sh user "password" dbname
file1.php
: No such file or directorycle.php: line 1: ?php
include/DatabaseObject/Article.php: line 2: class: command not found

file1.php is called include/Controllers/AdminController.php and the next file is called include/DatabaseObject/Article.php, i'm assuming that's why i got

: No such file or directory*cle.php*: line 1: ?php

After extracting my files, it breaks on an error that's inside file1.php. What can I do?

link|improve this question

75% accept rate
1  
Be more specific. What means "breaks on an error inside file1.php"? – SvenW Nov 16 '11 at 19:49
1  
Show the error message. – glenn jackman Nov 16 '11 at 19:57
Can you run the program with the +x argument in the shebang? – MIfe Nov 16 '11 at 20:43
feedback

closed as off topic by Zoredache, Scott Pack, mdpc, MDMarra, voretaq7 Nov 17 '11 at 16:18

Questions on Server Fault are expected to generally relate to servers, networking, or desktop infrastructure, within the scope defined in the faq.

2 Answers

up vote 6 down vote accepted

I suspect you have have not given us the full script, and you have anonymized the critical and detail that is causing your problem Put a set -x at the top of your script. This basically echos every command that is being run. If you still can't figure out out with this verbose output post the exact command that set -x reports that was issued before the error.

link|improve this answer
1  
As Zoredache says, please give us all the detail. It's not helpful only to show the bits you think are relevant to the error; if you understood the error, you'd fix it yourself, so the fact you're posting here means you don't understand why it's failing, which in turn means your judgement about what's relevant may be faulty. We like to help, but it's easier for us - and faster for you - if we have as much information as possible up front. – MadHatter Nov 16 '11 at 20:55
1  
Thanks for the help! The error was because I had a line feed character in the tar cvf command. I couldn't spot it while editing the file with nano because the command involved a lot of files. The line feed was somehow introduced while copying the text from my text editor into my Putty console. – altvali Nov 17 '11 at 11:53
feedback

Does one of your filenames have a control character in it, such as & or ; ?

link|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.