Page 1 of 1
SOLVED Trying to set up a backup script - bin/sh, bad int..
Posted: 13 Feb 2012, 23:08
by rog
Pretty much as the subject line says, I just wrote a shell script that goes like this:
Code: Select all
#!/bin/sh
# What to backup.
backup_files="/home /var/www /etc"
# Where to backup to.
dest="/home/storage/transmission
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
I chmod'ed it to 755, and tried to run it, but I got the following:
Code: Select all
bash: .backup.sh: bin/sh: bad interpreter: No such file or directory
I may not be the most advanced shell scripter in the world, but I've used similar scripts on a variety of linux systems, and never seen that before. I googled it, and the usual cause seems to be people writing the script in Windows, then importing it into wherever they're going to use it, but I wrote it while ssh'ed into my B3 (2TB wifi), in vi.
Any ideas why I'm seeing this?
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 14 Feb 2012, 03:36
by RandomUsername
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 14 Feb 2012, 12:51
by Gordon
Actually the Notepad thing would have been my first bet. With writing this in vi you've certainly earned my salute, but I'd still suggest you try opening this with nano which is more user friendly and has a good interface for showing weird characters such as the trailing carriage return (^M).
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 14 Feb 2012, 14:16
by Ubi
/bin/sh should be an acceptable command for the B3 (many scripts and processes require this). Can you run the command from the shell?
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 14 Feb 2012, 15:44
by 6feet5
Are you sure the script you show us is the exact same script you have in your script?
My first guess too would be the Notepad issue, but since you say you made it in vi I suppose it is more likely a misspelled shebang line (guessing you wrote #!bin/sh instead of #!/bin/sh).
/Johan
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 15 Feb 2012, 01:01
by rog
RandomUsername wrote:Try changing it to
That was the first thing I tried, and I got basically the same error message, except it said "bin/bash" instead of "bin/sh".
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 15 Feb 2012, 01:09
by rog
Gordon wrote:Actually the Notepad thing would have been my first bet. With writing this in vi you've certainly earned my salute, but I'd still suggest you try opening this with nano which is more user friendly and has a good interface for showing weird characters such as the trailing carriage return (^M).
I opened it up in nano, and it was exactly as I wrote it above. Here it is again, this time copy and pasted from leafpad (I'm not sure how to do that in nano):
Code: Select all
#!bin/sh
#What to back up
backup_files="/home /var/www /etc"
# Where to back up to
dest="/home/storage/transmission"
# Create archive filename
day=$(date +%A)
hostname=$(hostname -s)
archive_file=$hostname-$day.tgz
# Back up files with tar
tar -czf $dest/$archive_file $backup_files
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 15 Feb 2012, 01:10
by rog
Ubi wrote:/bin/sh should be an acceptable command for the B3 (many scripts and processes require this). Can you run the command from the shell?
That actually was run (or attempted) from the shell - I haven't tried running it any other way.
Re: Trying to set up a backup script - bin/sh, bad interpret
Posted: 15 Feb 2012, 01:12
by rog
6feet5 wrote:Are you sure the script you show us is the exact same script you have in your script?
My first guess too would be the Notepad issue, but since you say you made it in vi I suppose it is more likely a misspelled shebang line (guessing you wrote #!bin/sh instead of #!/bin/sh).
/Johan
Whoops, we may have a winner. Let me give that a try...I'll report back in this post.
sigh...I'm an idiot. Yup, can't believe I
a. Missed that, and
b. didn't realize what I wrote in my first post didn't match my actual script.
Thanks guys, and my apologies for wasting everybody's time.