Since update 9.3.1-9.10 script not working

Status
Not open for further replies.

eddi1984

Dabbler
Joined
Apr 3, 2015
Messages
42
Hi,

I just updated from 9.3.1 to 9.10. I had written a script a while ago, that I was using to make my life easier. After the update that script stopped working. I used the script before updating to 9.10, it was working perfectly fine.

I have not touched the script otherwise.

This is the script:
Code:
#!/bin/bash

source=$1
destination=$2
NOW=$(date +"%Y-%m-%d")
log="$NOW.log"
tmp="$NOW.tmp"

if [ ! -f ~/rsyncLogFiles/$log ]; then
        echo "Log File does not exist, creating log $log."
        touch ~/rsyncLogFiles/$log
        printf "########################   START OF RSYNC FILE ON $NOW FOR $source   ########################\n" >> ~/rsyncLogFiles/$log
else
        echo "Log File $log already exists."
        printf "\n\n########################   NEW RSYNC FOR $source   ########################\n" >> ~/rsyncLogFiles/$log
fi

echo "---   RSYNC FOR $source TO $destination ON $NOW   ---" > ~/rsyncLogFiles/$tmp
rsync -ahviPt --sparse --delete --stats --human-readable --exclude-from="/root/rsync-exclude.txt" --delete-excluded $3 $4 $5 $6 $7 $source $destination | tee -a ~/rsyncLogFiles/$log ~/rsyncLogFiles/$tmp

mail -s "RSYNC Completed to Backup 2TB of $source" "home@emailhere.com" < ~/rsyncLogFiles/$tmp
echo "Email send to home@emailhere.com."
rm ~/rsyncLogFiles/$tmp


The output is:
Code:
[root@freenas] ~# ./runRsync.sh
./runRsync.sh: Command not found.


Any ideas?

Cheers,

Eddi
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
Sir, are you sure the file name, as specified, "runRsync.sh", exists in the current directory and/or its permissions are correct?
 

eddi1984

Dabbler
Joined
Apr 3, 2015
Messages
42
Sir, are you sure the file name, as specified, "runRsync.sh", exists in the current directory and/or its permissions are correct?

Yes, the syntax is correct. The file is there as well. It should work, it has worked today in 9.3, few hours later after update to 9.10 it did not work.

I also did
Code:
chmod 755 runRsync.sh
with no success. The permissions are shown correct.
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
ok try this then:
Code:
/bin/sh ./runRsync.sh
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
Oh wait, I see it's a bash script.

If "sh" doesn't work, see if you have /bin/bash
 

eddi1984

Dabbler
Joined
Apr 3, 2015
Messages
42
Oh wait, I see it's a bash script.

If "sh" doesn't work, see if you have /bin/bash

So, I changed the script from "#!/bin/bash" to "#!/bin/sh" and ran it. It worked.

However, now RSYNC does not work as I am using it in the script. This script is so basic, it should not cause any issues, but it does ...
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
So, I changed the script from "#!/bin/bash" to "#!/bin/sh" and ran it. It worked.

However, now RSYNC does not work as I am using it in the script. This script is so basic, it should not cause any issues, but it does ...


Well you were not specific on what was failing. Is it not finding the rsync executable? If so, try replacing the "rsync" line with the fully delimited path. To see what that is, type
Code:
which rsync
. It's probably /usr/bin/local/rsync
 

eddi1984

Dabbler
Joined
Apr 3, 2015
Messages
42
Well you were not specific on what was failing. Is it not finding the rsync executable? If so, try replacing the "rsync" line with the fully delimited path. To see what that is, type
Code:
which rsync
. It's probably /usr/bin/local/rsync

Yes, I was not specific. This is the error:

Code:
rsync error: syntax or usage error (code 1) at main.c(1649) [Receiver=3.1.2]
./runRsync.sh: --exclude-from=/root/rsync-exclude.txt: not found


However, the file does exist. I will remove the exclude-from statement and than see.
 

eddi1984

Dabbler
Joined
Apr 3, 2015
Messages
42
Yes, I was not specific. This is the error:

Code:
rsync error: syntax or usage error (code 1) at main.c(1649) [Receiver=3.1.2]
./runRsync.sh: --exclude-from=/root/rsync-exclude.txt: not found


However, the file does exist. I will remove the exclude-from statement and than see.

So I did not remove it. It seems like there was line break in the text file. My mistake. All working now.
 
Joined
Dec 2, 2015
Messages
730
Some common utilities are in different locations on 9.10 as compared to 9.3.1:
Code:
freenas# which bash
/usr/local/bin/bash
I've had to tweak several scripts.
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
To be clear, all that really ended up happening here, was you had to change the shell called from bash to sh, right?
 

Islander

Cadet
Joined
Apr 9, 2015
Messages
3
In FreeBSD 10 (which is a difference in FreeNAS 9.10 compared to FreeNAS 9.3) there is no longer /bin/bash (not even a link to /usr/local/bin/bash which is where it is )
For portability I recommend you use

#!/usr/bin/env bash

and it will find bash from your PATH variable (which includes /usr/local/bin)
On FreeNAS PATH is usually
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin:/usr/local/fusion-io

bash and sh are certainly not the same executable:

[root@host]# ls -ld /bin/sh
-r-xr-xr-x 1 root wheel 143432 Mar 28 18:15 /bin/sh*
[root@host] # ls -ld /usr/local/bin/bash
-rwxr-xr-x 1 root wheel 1002616 Mar 28 18:15 /usr/local/bin/bash*
 
Status
Not open for further replies.
Top