Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following bash script:

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]# ./ user "password" dbname
: 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?

share|improve this question

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

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Be more specific. What means "breaks on an error inside file1.php"? – Sven Nov 16 '11 at 19:49
Show the error message. – glenn jackman Nov 16 '11 at 19:57
Can you run the program with the +x argument in the shebang? – Matthew Ife Nov 16 '11 at 20:43
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.

share|improve this answer
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
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

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

share|improve this answer

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