Reputation: 2502
I am loading a script (whiptail) when the root user logs into their Linux server, which works fine. The thing is, now, when I attempt to run other scripts from the command prompt (or crontab) the initial script is loaded instead, and it looks like the script that I want to run is not.
This is what ~/.profile
looks like:
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
mesg n
source /root/menu.sh
So, when I try to run bash -lc 'ruby some/other/script.rb
I'm taken into the script that runs at the end of ~/.profile
which is menu.sh
. How can I keep this from happening?
Here's what I need to have happen in the long run:
/root/menu.sh
crontab
such as a check in script, job script, etc.Upvotes: 0
Views: 254
Reputation: 295500
When you pass the -l
argument to bash, you're telling it to behave as a login shell; this includes running the user's .profile
.
If you don't want that behavior, don't pass -l
. Thus:
bash -c 'ruby some/other/script.rb'
That said, there's no advantage to doing that over just invoking ruby
directly, without any enclosing shell:
ruby some/other/script.rb
If you want other effects of running the user's .profile
, you might set an environment variable to indicate that you want to bypass this behavior:
# in the user's login scripts
[ -n "$skip_menu" ] || source /root/menu.sh
...and then...
skip_menu=1 bash -lc '...your command here...'
...or, if being executed without an enclosing shell...
env skip_menu=1 bash -lc '...your command here...'
Upvotes: 1