2

We have:

  1. a user nico.
  2. a folder /home/nico/script_home with some bash scripts:

    1. main.sh
    2. subscripta.sh
    3. sqlscripta.sh
  3. We connect as root and cd /home/nico/script_home/

  4. Finally we run ./main.sh

We get as a result:

  1. subscripta.sh - no such file or directory
  2. The sql script works fine

I noticed that su - nico -c "pwd" returns /home/nico/ So I tried changing main.sh to ./script_home/subscripta.sh but to no avail.

What is the right syntax to avoid the no such file or directory error when running a script with su -?

#main.sh
su - nico -c "./subscripta.sh"
su - nico -c "sqlplus username/pass@some_oracle_db @script_home/sqlscripta.sql"
1

Try su - nico -c "/home/nico/script_home/subscripta.sh"

  • yeah I tried that. I need to run my scripts again to let you guys know what worked or not. That way it will funnel the answers a bit. – Nicolas de Fontenay Dec 17 '11 at 15:43
  • As I've wrote, put whole path inside "". You can try of course with some variables like $HOME/script_home/subscripta.sh ... Question is how this script is built and if there are all paths done as they should be? – Sebastian Szary Dec 17 '11 at 23:31
1

Don't do su - - that does a total login for the user ID, including setting HOME to whatever user ID's home directory is.

Try su nico -c "./script.sh"

Also, ensure that script.sh is marked executable.

  • Oh nice. This is a great tip. But to run stuff on oracle, I do need to call my oracle's user profile bash_profile has a number of variable exported which allows to call sqlplus etc... – Nicolas de Fontenay Dec 18 '11 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.