Unix/Linux Go Back    


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

Changing script to work with freeBSD

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
robertkwild's Unix or Linux Image
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 November 2017, 9:05 AM EST
Posts: 83
Thanks: 9
Thanked 8 Times in 6 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 15 December 2017, 4:34 AM EST
Location: Aachen, Germany
Posts: 11,809
Thanks: 340
Thanked 3,659 Times in 3,357 Posts
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 11:54 AM.. Reason: typo
Sponsored Links
    #3  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
robertkwild's Unix or Linux Image
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 November 2017, 9:05 AM EST
Posts: 83
Thanks: 9
Thanked 8 Times in 6 Posts
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 11:37 AM..
    #4  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 15 December 2017, 4:34 AM EST
Location: Aachen, Germany
Posts: 11,809
Thanks: 340
Thanked 3,659 Times in 3,357 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
robertkwild's Unix or Linux Image
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 November 2017, 9:05 AM EST
Posts: 83
Thanks: 9
Thanked 8 Times in 6 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 15 December 2017, 4:34 AM EST
Location: Aachen, Germany
Posts: 11,809
Thanks: 340
Thanked 3,659 Times in 3,357 Posts
Maybe it's already there? FreeBSD uses PATH settings / installation paths different from some linuxes...
Sponsored Links
    #7  
Old Unix and Linux 05-22-2017   -   Original Discussion by robertkwild
robertkwild's Unix or Linux Image
robertkwild robertkwild is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 21 November 2017, 9:05 AM EST
Posts: 83
Thanks: 9
Thanked 8 Times in 6 Posts
ok i will have a look if its there and if not i will add bash to freeBSD
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help getting Loadrunner to work with freeBSD system monitoring rstatd/rup/rsysinfo echan00 Infrastructure Monitoring 0 05-03-2013 04:21 AM
My script work on Linux but not work in sunos. ooilinlove Shell Programming and Scripting 7 01-30-2013 07:27 AM
Changing boot order doesn't work Era555 Ubuntu 3 05-17-2011 12:19 AM
Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3 Seenquev Programming 1 01-20-2009 09:07 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM



All times are GMT -4. The time now is 12:03 PM.