• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx

  • We are developing a new feature in Plesk that will help you promote your websites or business on social media. We want to conduct a one-hour online UX test to present the prototype and collect feedback. If you are interested in the feature, please book a meeting via this link.
    Thank you in advance!
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

Question Prefix commands with bash in command line

DennyP

Basic Pleskian
Running Version 17.8.11 Update #91

I have scripts with #!/bin/bash as the first line. The scripts are running perfectly via cron.

To run the scripts on a command line, I have to put bash in front of the script name otherwise I get "Command not found".

The "Access to server over SSH" option is set to /bin/bash in Web Hosting Access.

Is there a way to make it so I don't have to type bash in front of any of my own scripts in order to get them to run?

Thank you.
 
Have you tried to run the scripts with a preceding ./ instead? At first sight to me the post reads as if the file is not found that shall run as a script. You can normally overcome this by prefixing a relative path ./ .
 
That worked - thanks. But why? Same script I ran on an older Plesk system that I just migrated from. Same path, same name. I didn't have to put ./ or bash in front of the script name on my older system.
 
Hi @DennyP,

This situation is not related to Plesk. According to the operating system you are using "." adding / not adding may vary. You can add "./" without exception to run sh on all linux systems.
 
It's the same operating system (CentOS) that I used on my prior system where I didn't need to prefix the script nor add bash. Thank you.
 
Which user did you log in as?
It's pretty much standard for security reasons that root does not have the current directory . in $PATH.
If you absolutely want to append :. to the PATH, you can do so in any of the configuration files bash reads on startup, from /etc/profile to ~/.bashrc.
Or you could put the scripts in the location intended for additional executables /usr/local/bin/.
 
I logged in as root as I did on my prior server where I did not need to append anything to the front of the script name. The scripts I was running are in /root/scripts/ where I did a cd to run them.

I did not have to append anything in front of the command on my prior plesk system and I'm just trying to find out why I have to append something in front of the same scripts running out of the same directory with the same user.
 
As @mow pointed out, the shell looks up a list of directories that are specified by the PATH variable, but the current directory is not in that list BY DEFAULT. That is the default and correct setting in CentOS. If it was different in your previous system, the previous system had an individual setting that is not normal for other installations.

Here is an example why the ./ is an important extra. Suppose you are logged in as root and you are in your directory. Now you type one of the Linux commands like "mv" to move a file to a different location. Linux knows where to find the mv, because it looks in certain paths for it. Next you descend into a directory of another user on your server, because the user has asked you to move one of his directories to a different location. You execute "mv" in that directory just as you normally do it - suddenly your server becomes unresponsive and later you find out that the partition table was destroyed. What has happend? The user placed his own "mv" into his directory, so now, as your CentOS finds that "mv" in the current path, it executes that mv, but the user has placed commands into it that erase your hard disk. In the default CentOS setup however, when you run "mv" it will run the real one while ./mv would be needed to run the one located in the current directory.

For that reason CentOS by default requires the extra ./ to run a locally stored script. Your current path is never part of the PATH environment, so that you cannot accidentally run malicious software. If your previous system did not observe this, you are subject to easy attacks by your users.
 
Peter, now that makes sense. I guess my prior Plesk server had something set differently. Thank you for that complete and understandable information.
 
Back
Top