Backup script
Paul Howarth
paul at city-fan.org
Mon Mar 13 11:57:48 UTC 2006
Chris Norman wrote:
> Hi,
> I've got that, the only thing, when I run the script first hand, I get:
>
> : Bad interpreter: No such file or directory
>
> At the top, I have:
> #!/bin/bash
>
> I tried:
> #!/bin/sh
>
> But that got the same results. The permission bits are:
>
> -rwxr--r-- root root
>
> I'm running it as root.
>
> No probs, I have fixed that, just re-wrote it, and it seemed to work.
You had probably created the script on a Windows box, which puts
carriage return characters at the end of each line that confuse shells
trying to interpret them.
> I have
> another problem now though:
>
> Tar says it can't "stat" ls, says there's no such file or directory.
>
> here's the script:
>
> #!/bin/bash
>
> cd /var/ftp/backup;
>
> for file in ls
> do {
> tar cf /home/backup/$file.tar.tar $file/
> } done
>
>
> What is the problem?
$file has only one value in this loop, "ls".
What you want is to capture the output of "ls" and use that:
for file in `ls`
or in bash (clearer)
for file in $(ls)
or (better still, you don't need ls at all)
for file in *
P.S. Please don't top-post on this mailing list.
Paul.
More information about the fedora-list
mailing list