Shell scripting help required

Forum rules
Before you post please read how to get help
Post Reply
deepakdeshp
Level 11
Level 11
Posts: 3853
Joined: Sun Aug 09, 2015 10:00 am

Shell scripting help required

Post by deepakdeshp » Sat Mar 24, 2018 8:17 am

Hello ,
Following is the shell script I am trying to write but am getting errors.

Code: Select all

########### START the SERVER
su - ortest<<!
!
/apps/ortest/VIS/db/tech_st/11.1.0/bin/sqlplus " /as sysdba"<<!
startup
exit
!
lsnrctl start VIS
exit


su - aptest <<!
cd /apps/aptest/VIS/inst/apps/VIS_apps/admin/scripts
./adstrtal.sh apps/apps
!
First line says that I have to be ortest and get the environment variables. As this user the script till lsnrctl start VIS and exit have to be executed.

Similarly for aptest users.

Thanks in anticipation.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
I am using Mint 19 Cinnamon 64 bit with AMD A8/7410 processor . Memory 8GB

User avatar
tovian
Level 5
Level 5
Posts: 529
Joined: Sun Nov 22, 2015 1:17 pm
Location: Heart of Dixie

Re: Shell scripting help required

Post by tovian » Sat Mar 24, 2018 9:18 am

It looks like a bash script, but it does not start with a shebang (#!/bin/bash).

Refer to: This Page

I believe it is required - at least I've never had any luck running a bash script without that code at the beginning.
“I think that this situation absolutely requires a really futile and stupid gesture be done on somebody's part!"
"We're just the guys to do it.”

Animal House

deepakdeshp
Level 11
Level 11
Posts: 3853
Joined: Sun Aug 09, 2015 10:00 am

Re: Shell scripting help required

Post by deepakdeshp » Sat Mar 24, 2018 1:40 pm

tovian wrote:
Sat Mar 24, 2018 9:18 am
It looks like a bash script, but it does not start with a shebang (#!/bin/bash).

Refer to: This Page

I believe it is required - at least I've never had any luck running a bash script without that code at the beginning.
That's correct. I was testing it with

Code: Select all

 bash -x file
command which runs the script in debug mode.
The question is where exactly to put the exclamation mark in the script.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
I am using Mint 19 Cinnamon 64 bit with AMD A8/7410 processor . Memory 8GB

lmuserx4849

Re: Shell scripting help required

Post by lmuserx4849 » Mon Mar 26, 2018 4:59 am

deepakdeshp wrote:
Sat Mar 24, 2018 8:17 am
...

Code: Select all

########### START the SERVER
su - ortest<<!
!
/apps/ortest/VIS/db/tech_st/11.1.0/bin/sqlplus " /as sysdba"<<!
startup
exit
!
lsnrctl start VIS
exit
...
...
Is that suppose to be a HERE Doc? Just guessing here, but I wouldn't use an exclamation point; That has meaning to bash.

Code: Select all

#!/bin/bash
sqlplus -s  <<EOF
connect / as sysdba
COMMANDS
exit
EOF

User avatar
Termy
Level 5
Level 5
Posts: 762
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Shell scripting help required

Post by Termy » Wed Mar 28, 2018 4:17 am

Yeah, I was just about to ask the same thing as the previous poster. Definitely looks like you were shooting for a heredoc. The exclamation mark works for a heredoc (just tested it), but you've got nothing in it, so su has nothing to do except, likely, attempt to log in as the actual root user (not like sudo) which is disabled (locked password) in Ubuntu and most if not all distributions based off it, including Mint. Even if it were accepted, or you had something in the heredoc, su complains that it must be run "from a terminal"; it needs user input, interactively, probably for security reasons.

Are you just trying to run commands as the root user, without logging in as the root user, as it were? If so, and you have sudo installed, I recommend using sudo ("substitute user do"), which is in my opinion the better and safer tool for the job now anyway. I would use something like: sudo CMD Where CMD is the command you want to run with root privileges. Although adding sudo into scripts is something I avoid.
Last edited by Termy on Fri Mar 30, 2018 2:29 pm, edited 2 times in total.
Here to help.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/channel/UCfp-lN ... naEE6NtDSg
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife

FreedomTruth
Level 4
Level 4
Posts: 417
Joined: Fri Sep 23, 2016 10:19 am

Re: Shell scripting help required

Post by FreedomTruth » Wed Mar 28, 2018 8:29 pm

I think he's using su to run different parts of the script as different users (ortest and aptest); not as root.
maybe make an ortest-commands script and an aptest-commands script, then this could call each individually
something along the lines of

Code: Select all

su -c ortestscript.sh ortest
su -c aptestscript.sh aptest
If you abide in My word, you are My disciples indeed. And you shall know the truth, and the truth shall make you free... Most assuredly, I say to you, whoever commits sin is a slave of sin... Therefore if the Son makes you free, you shall be free indeed.

Post Reply

Return to “Scripts & Bash”