New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

SOLVED Trying to set up a backup script - bin/sh, bad int..

Got problems with your B2 or B3? Share and get helped!
Post Reply
rog
Posts: 22
Joined: 22 Sep 2011, 00:19

SOLVED Trying to set up a backup script - bin/sh, bad int..

Post 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?
Last edited by rog on 15 Feb 2012, 01:18, edited 1 time in total.
RandomUsername
Posts: 904
Joined: 09 Oct 2009, 18:49

Re: Trying to set up a backup script - bin/sh, bad interpret

Post by RandomUsername »

Try changing it to

Code: Select all

#!/bin/bash
Gordon
Posts: 1464
Joined: 10 Aug 2011, 03:18

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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).
Ubi
Posts: 1549
Joined: 17 Jul 2007, 09:01

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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?
6feet5
Posts: 269
Joined: 13 Apr 2007, 17:32
Location: Gnesta, Sweden
Contact:

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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
rog
Posts: 22
Joined: 22 Sep 2011, 00:19

Re: Trying to set up a backup script - bin/sh, bad interpret

Post by rog »

RandomUsername wrote:Try changing it to

Code: Select all

#!/bin/bash
That was the first thing I tried, and I got basically the same error message, except it said "bin/bash" instead of "bin/sh".
rog
Posts: 22
Joined: 22 Sep 2011, 00:19

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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
rog
Posts: 22
Joined: 22 Sep 2011, 00:19

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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.
rog
Posts: 22
Joined: 22 Sep 2011, 00:19

Re: Trying to set up a backup script - bin/sh, bad interpret

Post 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.
Post Reply