Score:0

Why a bash script is not working properly after being installed via .deb package in /usr/local/bin and without installation it works?

ve flag

I have developed a bash script named njsearch that should perform a search in a given folder, and save the log inside auditlogs.log file:

#!/bin/bash

logs_dir=/var/log/mylogfolder
mydata=/path/to/mydata
daysbefore=1

Find()
{
    truncate -s 0 $logs_dir/auditlogs.log
    echo "Searching files .$1"
    find $mydata/ -mtime -$daysbefore -name *.$1 >> $logs_dir/auditlogs.log
    cat $logs_dir/auditlogs.log
}

# Get the options
while getopts ":hmkaro:" option; do
    case $option in
        h) # Display Help
            Help
            exit;;
        m) # Find mp4
            Find mp4
            exit;;
        k) # Find mkv
            Find mkv
            exit;;
        a) # Find avi
            Find avi
            exit;;
        r) # Find rar
            Find rar
            exit;;
        o) # Enter new file format
            namedial=$OPTARG
            Find $namedial
            exit;;
        \?) # Invalid option
            echo "Error: that's not a valid option"
            exit;;
    esac
done

This script works great, the problem comes when I generate the .deb installer file following the steps explained here. Once installed, the script does not perform the searches.

I'm missing something here about creation and compilation this script for being part of Debian OS?

PS: I checked the +x permission for the script, and nothing

Any solution to this?

UPDATE: I recently found out that after installing it, if I do a logout - login, then this script works without any problem. Any ideas?

hr flag
You should double-quote `*.$1` to prevent it from potentially expanding to a list of matching files in the current directory. More generally, you should double-quote bash variable expansions like `$mydata` and `$log_dir` as well - see for example [Security implications of forgetting to quote a variable in bash/POSIX shells](https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells)
Eduardo Osquel Pérez Rivero avatar
ve flag
Thanks, for the answer, but, is not any code trouble. This works perfectly, my problem is given in the post-installation of this code as part of a package. I recently found out that after installing it, if I do a logout - login, then this script works without any problem. Any ideas?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.