Skip to content
Advertisement

Executing multiple commands under as another username within a file in BASH shell

I am attempting to execute a sqlplus command within a file. The file should be able to sudo switch into the oracle user and run the commands needed. The oracle user will need to first source a file with the parameters for the database, then be able to call a sql file from sqlplus.

The script I have is

JavaScript

Whether I run the scrupt with sudo or not, it won’t give an error. The only thing it will return is the usage for sudo

JavaScript

I figure that this means that my syntax is probably incorrect. However, without putting the command entirely on one line, I’m not sure how to fix the syntax. I’ve tried using double quotes around the command, removing the semicolon, and changing the grave symbol to use parenthesis instead. None of these produce any results. Trying it as a one liner and removing the parenthesis and grave marks gives me the usage information as well as a bunch of

JavaScript

Advertisement

Answer

Try using a heredoc:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement