Changing script to work with freeBSD


 
Thread Tools Search this Thread
Top Forums Programming Changing script to work with freeBSD
# 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 11: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 11: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 or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

An installation script on freeBSD

Hello So i got my hands on some freebsd iso, installed it in a qcow2 image and installled git and bash. So far, so good. Git repositry retireved install script executed files got copied files have exec flag files are in $PATH / found by which / bash-completion works But still,... (3 Replies)
Discussion started by: sea
3 Replies

2. Infrastructure Monitoring

Need help getting Loadrunner to work with freeBSD system monitoring rstatd/rup/rsysinfo

Hi there, I'm trying to use loadrunner with freebsd system monitoring tools like rstatd/rup/rsysinfo, but I keep getting this error from loadrunner: Monitor name :UNIX Resources. Internal rpc error (error code:4). Machine: 192.168.1.15. Hint: Check that RPC on this machine is up and running.... (0 Replies)
Discussion started by: echan00
0 Replies

3. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

4. Shell Programming and Scripting

FreeBSD rc.subr wireless script

Hi, This is my first thread on Unix forums, so be gentle.:o I'm trying to write a simple start/stop script for my wireless networking adapter, under FreeBSD, using the rc.subr framework. #!/bin/sh # PROVIDE Wireless # KEYWORDS shutdown . /etc/rc.subr name="wireless"... (1 Reply)
Discussion started by: regexp
1 Replies

5. Shell Programming and Scripting

FreeBSD new user login script

I am a beginner programmer and would like to know where to start to modify the login process so that a user can login as username new password new and have it prompt user for username and password and nothing else and then create said user account on the system so they can ssh back in and login... (9 Replies)
Discussion started by: deshi
9 Replies

6. Ubuntu

Changing boot order doesn't work

Hey i am running both ubuntu 10.10 and windows 7, trying to make the default boot be windows 7 instead of ubuntu but it doesn't want to work. Ive tried changing default in the grub file it didnt work, then i installed startup-manager and set windows 7 as the OS and it still boots into ubuntu. Thx... (3 Replies)
Discussion started by: Era555
3 Replies

7. Shell Programming and Scripting

Bash script: issue changing directories in script

I am working on a script that checks two arguments at the command line. The first argument is a search pattern, the second can be a file or a directory, if it is a file a second script is called that checks it for the search pattern. If the second argument is a directory, it checks for the search... (5 Replies)
Discussion started by: Breakology
5 Replies

8. Programming

Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3

Hello there, My mulithreaded application (which is too large to represent the source code here) is crashing after installing FreeBSD 7.1-RELEASE/amd64. It worked properly on others machines (Dual Cores with 4GB of RAM - FreeBSD 6.2-RELEASE/i386). The current machine has 2x Core 2 Duo... (1 Reply)
Discussion started by: Seenquev
1 Replies

9. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question