• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • 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.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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