Changing script to work with freeBSD

hi all,

i have made my machine a freeBSD machine instead of a centos machine and my script doesnt work anymore and i was wondering if anyone can help me into why, i thought the commands are the same, here it is -

#!/bin/bash

source=/vol/cha-work/_ARCHIVE/to_be_archived/audio
temp=/mnt/archive/temp
dest=/vol/cha-archive/audio

    echo "is this archive for an audio tar press (t) or an audio directory press (d)"
    read option

    
        d)
            cd "$source"

            echo "please specify full path to directory you want to be made into a tar"
            read -e dir

#            echo "please enter ID number ie ID1234"
#            read id

#            echo "please specify where you want the tar file to be stored"
#                       read -e dest

            cd "$dir"

            base=$(basename "$dir")

                echo -e "COPY "$base" to "$temp"\n"
                                echo -e "CREATE "$base".tar in "$temp"\n"
                echo -e "COPY "$base".tar to "$dest"\n"
                echo -e "REMOVE "$base".tar from "$temp" \n"
                                echo -e "REMOVE "$base" from "$temp"\n"
                echo -e "REMOVE "$base" from "$source"/"$dir"\n"

                                        echo "is this information correct, press (yes) or press (no)"
                                        read correct

                                        case $correct in

                                                yes)
                            echo "the script will now continue";;

                                                no)
                            echo "please re-run the script inputting correct details"
                                                        exit;;

                                                *)
                            echo "invalid selection, please re-run the script"
                                                        exit;;

                                        esac                

            date >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            echo "" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
#            echo -e ""$id"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            echo -e ""$source"/"$dir"\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            echo -e "how many files = `find . -type f | wc -l`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            echo -e "size of directory = `du -sh`\n" >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            ls -R >> /vol/cha-work/_ARCHIVE/inventories/"$base".csv
            
            cd ..

            if ! cp -R "$base" "$temp" ; then
                echo "something went wrong with the recursive copy command, please do manually"
                exit
            fi

            cd "$temp"

            chmod -R 777 "$temp"

            if ! tar -cf "$base".tar "$base" ; then
                echo "something went wrong creating the tar, please do manually"
                exit
            fi

            if ! cp "$base".tar "$dest" ; then
                echo "something went wrong copying the tar, please do manually"
                exit
            fi

            if ! rm -f "$temp"/"$base".tar ; then
                echo "something went wrong removing the tar, please do manually"
                exit
            fi


            if ! rm -rf "$temp"/"$base" ; then
                echo "something went wrong removing from temp, please do manually"
                exit
            fi

            cd "$source"/"$dir"
            cd ..

            if ! rm -rf "$base" ; then
                echo "something went wrong removing from source, please do manually"
                exit
            fi;;

        *)

            echo "invalid selection, please re-run the script"
            exit;;

    esac

many thanks,

rob

As you've been asked umpteen times before: "my script doesnt work anymore" doesn't help anybody help you. What makes it so difficult to post exact error messages, wrong / inconsistent output, failing lines' numbers?

i had to change

#!/bin/bash

to

#!/bin/sh

now im getting stuck on this command

echo "please specify full path to directory you want to be made into a tar"
            read -e dir

but when i press tab it should auto complete a directory it no longer auto completes and i dont know why?

I guess you're talking of the second line? Howsoever, man is your friend. Comparing man sh :

to man bash :

shows that after changing the executing shell to sh the -e option, and thus the readline functionality including autocompletion is no more offered. Use / istall bash

mmm... thanks, i thought freebsd and linux would use same shell but obviously not

i have found this walkthough into installing bash on freeBSD, shall i do this or re-code the whole thing for freeBSD

FreeBSD Install BASH Shell � nixCraft

Maybe it's already there? FreeBSD uses PATH settings / installation paths different from some linuxes...

ok i will have a look if its there and if not i will add bash to freeBSD

Hi.

On a system like:

OS, ker|rel, machine: FreeBSD, 11.0-RELEASE-p1, amd64

Here are some details about bash :

/usr/local/bin/bash:
        Bash version 4.4.12(1) release GNU (what)
Path    : /usr/local/bin/bash
Version : 4.4.12
Type    : ELF 64-bit LSB executable, x86-64, version 1 (Free ...)

Best wishes ... cheers, drl

good news, i did the following

pkg install bash

then to run the script

bash /path/to/script/script.name.sh

so appending the words bash infront of the script works

1 Like

sorry i removed as i posted the above, my bad