Home Man
Search
Today's Posts
Register

Post questions about C, C++, Java, SQL, and other programming languages here.

Changing script to work with freeBSD

Tags
programming

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 05-22-2017
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 -

Code:
#!/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
# 2  
Old 05-22-2017
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?

Last edited by RudiC; 05-22-2017 at 10:54 AM.. Reason: typo
# 3  
Old 05-22-2017
i had to change
Code:
#!/bin/bash

to
Code:
#!/bin/sh

now im getting stuck on this command

Code:
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?

Last edited by robertkwild; 05-22-2017 at 10:37 AM..
# 4  
Old 05-22-2017
I guess you're talking of the second line? Howsoever, man is your friend. Comparing man sh:
Quote:
read [-p prompt] [-r] variable [...]
to man bash:
Quote:
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
.
.
.
-e If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line. Readline uses the current (or default, if line editing was not previously active) editing settings.
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
# 5  
Old 05-22-2017
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
# 6  
Old 05-22-2017
Maybe it's already there? FreeBSD uses PATH settings / installation paths different from some linuxes...
# 7  
Old 05-22-2017
ok i will have a look if its there and if not i will add bash to freeBSD
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
An installation script on freeBSD sea BSD 3 01-27-2015 05:47 AM
Need help getting Loadrunner to work with freeBSD system monitoring rstatd/rup/rsysinfo echan00 Infrastructure Monitoring 0 05-03-2013 03:21 AM
My script work on Linux but not work in sunos. ooilinlove Shell Programming and Scripting 7 01-30-2013 06:27 AM
FreeBSD rc.subr wireless script regexp Shell Programming and Scripting 1 06-17-2012 11:51 AM
FreeBSD new user login script deshi Shell Programming and Scripting 9 11-05-2011 01:27 AM
Changing boot order doesn't work Era555 Ubuntu 3 05-16-2011 11:19 PM
Bash script: issue changing directories in script Breakology Shell Programming and Scripting 5 05-26-2009 08:47 AM
Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3 Seenquev Programming 1 01-20-2009 08:07 AM
Modify Perl script to work with txt - Permissions script joangopan Shell Programming and Scripting 1 09-12-2007 11:38 PM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 09:52 PM


All times are GMT -4. The time now is 05:27 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password