Shell scripting help required

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
deepakdeshp
Level 20
Level 20
Posts: 12334
Joined: Sun Aug 09, 2015 10:00 am

Shell scripting help required

Post by deepakdeshp »

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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
tovian
Level 5
Level 5
Posts: 630
Joined: Sun Nov 22, 2015 1:17 pm
Location: Heart of Dixie

Re: Shell scripting help required

Post by tovian »

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 20
Level 20
Posts: 12334
Joined: Sun Aug 09, 2015 10:00 am

Re: Shell scripting help required

Post by deepakdeshp »

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.
Regards,
Deepak

Mint 21.1 Cinnamon 64 bit with AMD A6 / 8GB
Mint 21.1 Cinnamon AMD Ryzen3500U/8gb
lmuserx4849

Re: Shell scripting help required

Post by lmuserx4849 »

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 12
Level 12
Posts: 4254
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Shell scripting help required

Post by Termy »

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.
I'm also Terminalforlife on GitHub.
FreedomTruth
Level 4
Level 4
Posts: 443
Joined: Fri Sep 23, 2016 10:19 am

Re: Shell scripting help required

Post by FreedomTruth »

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
Locked

Return to “Scripts & Bash”