Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing script with sudo: lolcat: not found #119

Open
Ghost1nTh3SSH opened this issue Dec 20, 2020 · 8 comments
Open

Executing script with sudo: lolcat: not found #119

Ghost1nTh3SSH opened this issue Dec 20, 2020 · 8 comments

Comments

@Ghost1nTh3SSH
Copy link

Hi!

I'm trying to execute a script with sudo that contains an echo with lolcat.

Example file:

#!/bin/bash
echo "#####################################" | lolcat -f 

Without executing with sudo, lolcat is recognized and works as expected.

image

Also, when executing from terminal works well:

image

image

However, seems that sudo cannot execute lolcat within a script. Is this an expected behaviour? How can I make that sudo is able to recognize the lolcat command?

image

Thanks in advance,

@JohnRamon
Copy link

Same problem, any help on this?

@m-o-e
Copy link
Member

m-o-e commented Feb 26, 2021

On what linux distro is this? (can not reproduce on Ubuntu)

Maybe you can get around it by calling lolcat with its absolute path (as given by which lolcat).

@JohnRamon
Copy link

I'm on Centos 7 and I installed through Ruby, I removed and installed using snap and now i can call from a bash script. Gh05t1nTh3SSH, check if lolcat was installed in your home folder, if so remove and install with snap that worked for me.

@Efreak
Copy link

Efreak commented Dec 16, 2021

@JohnRamon Sudo doesn't pass along the path variable. You're installing a program into your user folder and expecting it to work for other users. If you want it installed globally without snap, install as root instead of your user.

In general, you can't expect any software installed without sudo to work with sudo without passing a full path or setting the path variable.

Try sudo $(command -v lolcat).

@Efreak
Copy link

Efreak commented Dec 16, 2021

@Gh0st1nTh3SSH in your second example, you're only passing the echo command to sudo, then passing the result of that to lolcat. That's why the command works with sudo echo and not within a script.

If you wanted to pipe the output of the previous command, you have two options:

  • put the entire command into quotes: sudo "echo '#####' | lolcat"
  • use sudo on the command after the pipe: `sudo echo '#####' | sudo lolcat

Add the full path to lolcat to your script (not recommended, use command -v lolcat to get the full path), or install it in a standard location. Try sudo gem install lolcat.

This is not a bug.

@Fire7ly
Copy link

Fire7ly commented Jan 5, 2022

@Efreak As You Marination sudo "echo '#####' | lolcat" && sudo echo ##### | sudo lolcat In both cases it says not find but when im put full path of lolcat which im get from which lolcat In my case it is /usr/games/lolcat and it work flowlessly as i want..
im make a variable of lolcat like this lolcat=/usr/games/lolcat and where in put lolcat im just add path variable like this $lolcat
im install lolcat from sudo apt install lolcat Im using linux mint xface edition with ryzen 5.
here is a screenshot attached
Screenshot_2022-01-06_01-43-41

And here is code Im Make...
#!/bin/bash
ROOT_UID=0
PATH=$PATH
lolcat=/usr/games/lolcat

if [ "$UID" -ne "$ROOT_UID" ]; then
echo -e "${RED}Run script with superuser (root) rights. It needed because on some linux distros fastboot doesn't work without root.${END}"
exit 87
fi
echo "Testing One With LOLCAT" | $lolcat
echo "Testing Two With LOLCAT WITHOUT PATH VERIABLE" | lolcat
sudo "echo 'Testing Two With LOLCAT WITHOUT PATH VERIABLE AND WITH SUDO' | lolcat"
sudo echo 'Testing Two With LOLCAT WITHOUT PATH VERIABLE AND WITH DOUBLE SUDO' | sudo lolcat

@dedeard
Copy link

dedeard commented Dec 3, 2022

sudo snap install lolcat

@Morsmalleo
Copy link

Morsmalleo commented Apr 20, 2024

I tried to create a stylish banner in a bash script by doing the following:

create_3d_banner() {
    
    # Reset color code
    reset_color="\033[0m"
    
    # Default Banner color code
    blue="\033[34m"
    
    # Banner text
    banner_text="   AhMyth"

    # Check if figlet and lolcat are installed
    if command -v figlet > /dev/null 2>&1; then
        # Use figlet to create ASCII art with mono9 font
        figlet_output=$(figlet -f mono9 "$banner_text")

        # Use lolcat to add color to the ASCII art
        banner_output=$(echo "$figlet_output" | lolcat)

        # Print the result
        echo "${blue}${banner_output}${reset_color}"
    else
        if [ "$PACKAGE_MANAGER" = "apt-get" ]; then
            apt-get install -y figlet
        elif [ "$PACKAGE_MANAGER" = "pacman" ]; then
            pacman -Sy figlet
            
            # Reset color code
            reset_color="\033[0m"
    
            # Default Banner color code
            cyan="\033[36m"
    
            # Banner text
            banner_text="   AhMyth"
           
            # Use figlet to create ASCII art with mono9 font
            figlet_output=$(figlet -f mono9 "$banner_text")

            # Use lolcat to add color to the ASCII art
            banner_output=$(echo "$figlet_output" | lolcat)

            # Print the result
            echo "${blue}${banner_output}${reset_color}"

        fi
    fi
}

create_3d_banner

However everytime I tried to pipe the figlet results through lolcat, my terminal always told me command lolcat: not found and I was stumped on this because it worked fine when it was being used in the terminal itself, but with the bash configuration seen above, lolcat would only work if the banner I was trying to colour was stored in another file.... until I done some experimenting and found out the problem.

For me, my Linux distro is Kali Linux which uses apt as it's package manager and for some reason installing lolcat on Kali Linux with sudo apt-get install lolcat -y ends up unpacking and installing the lolcat executable file to the /usr/games directory, which stops lolcat from being used in scripts even when you specify it's absolute path in the /usr/games directory!!

Anyways the solution to that problem for some reason is to either move or copy the lolcat executable file from the /usr/games directory to the /usr/bin directory with the following command:

sudo cp /usr/games/lolcat /usr/bin

After doing that, the command lolcat: not found error disappeared completely and my configuration above in the code snippet magically started working fine without problems.

So the solution, if you installed lolcat on Linux via apt, then move or copy the executable lolcat file from the /usr/games to the /usr/bin directory with one the following commands

# copy the file ovet
sudo cp /usr/games/lolcat /usr/bin

# move the file over
sudo mv /usr/games/lolcat /usr/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@JohnRamon @Efreak @m-o-e @dedeard @Ghost1nTh3SSH @Morsmalleo @Fire7ly and others