Shell script to startup, exit and run other scripts once it completes - database

I have been trying to automate this process in shell script in a unix box. I am new to shell scripts.
I have not been able to figure out how to detect when the startup for it has finished . Also, how to
create a new terminal and check the domain.log for the new terminal. I would appreciate if anyone
can help me on this .
cd $/home/oracle/12/bin
./lsnrctl start
Login to sqlplus with username sys as sysdba and password: oracle3211
and run the database startup command startup
Once it is started type exit
--now start the dbconsole
cd $/home/oracle/12/bin
./emctl start dbconsole
--open a new terminal and execute this
$/home/oracle/startWeblogic.sh
--wait for domain.log keyword in the log file to confirm the server has started
--if the server is started proceed to the following in a new terminal
$/home/oracle/startManagedWeblogic.sh
--after this access the following urls
https://178:198:29:28:1167/em (username=system1, password=oracle123)
https://178:198:29:28:1176/em (username=system2, password=oracle132)

Sounds like you also need to learn about the GNU screen command. You may already have it installed. Try screen -R -D
If it gives you a shell prompt at the top of the screen then it works. Now if you disconnect your ssh session or close your terminal window (click on the X), the next time you log in and run the exact same screen command, you are reconnected to the same running terminal session.
This allows you to run scripts, etc. which do not stop when you disconnect. And when you reconnect you can see their current output.
Also, you can have many terminal sessions. Ctrl-A c creates another one. Ctrl-A [space] and Ctrl-A [backspace] rotate between sessions in the list. Ctrl-A ? gives you all the other Ctrl-A commands that you can use. For instance, one session could be tail logfile while another one is running a program waiting for input.

Related

Why am I not able to type anything in the terminal window after running npm start in order to fire up the development server?

I am using create-react-app tool to create a React project. But after running npm start command in my terminal window in order to fire up the development server, I am not able to type anything in the terminal. Why so and how can I rectify it?
That terminal command is still running (specifically it is running your server) so it can't take anymore commands. If you want to run other commands while it is running, you will have to open another terminal tab/window. The + button in the top right of the terminal window should do it for you
Press Ctrl c twice it will show you ^c
Then you can write your command under the ^c

log in adb shell "interactive mode" and "non-interactive mode"

I'm writing script to run iperf on linux device accessible via adb.
From a terminal, when I run the command: adb shell iperf -c ......
I get the log of the command 50 s after the command starting.
inconvenient: during 50 s you are not sure that iperf has started
I tried the logcat command (logcat --pid ...), It gives the same result.
From a terminal, when I enter adb session first and then I run the command: iperf -c .....
I get the log of the command in real time.
inconvenient: I'm not able to automate the procedure, because I have to start the adb session first
For the first use case: Is there a way to force "log flush" in order to get the log in real time?
For the second use case: Is there a way to send commands to already opened adb shell session?
Is there any other ways to launch iperf on device and get the log in real time?
The solution i found is the library pexpect that allow to interact with adb session.

catch console output from background process

I have a program running on armbian single board computer. The program starts with -b option during the startup of the system. I created this simple shell script
#!/bin/bash
#Myprog server start
sudo -b /home/myprog/myprog
This program is C written and it sometimes outputs some information with printf functions. But since it is started with -b option there's is noting in the console.
Now when I log in to the armbian via ssh with Putty I want to occasionally read the output of this program. Is it even possible?
Not exactly what you’re asking, but generally speaking it’s better practice to redirect output to a log file than to try to interactively look at the console output for a background app.
Something like:
sudo -b /home/prog/myprog >> /home/prog/log.txt 2>&1
Should do it.
Then view output with
tail -f /home/prog/log.txt
If it’s really important to you to run interactively without logs, I would suggest running it from within “screen” without backgrounding it.
screen
sudo /home/prog/myprog
Then ctrl-d to detach and let it run in background. screen -r to reattach.

Automating putty with .bat file [duplicate]

I want to run a few shell commands every time I SSH to a server via PuTTY. I'm connecting to a production web server managed by someone else, and I don't want to store my own scripts there.
I see the option Connection > SSH > Remote Command, but if I put my initialization commands there, after starting the session, it closes immediately after the commands execute. How can I run the Remote Command, and then keep the session open so I can continue using it?
The SSH session closes (and PuTTY with it) as soon as the command finishes. By default the "command" is a shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:
my-command ; /bin/bash
See also Executing a specific command on the server.
One option to go is set up your putty remote command like this:
ls > dir.ls & /bin/bash
In this example command you want to run is "ls > dir.ls" what creates file dir.ls with content of directory listing.
And as you want to leave shell open you can add aditional command "/bin/bash" or any other shell of your choice.

.bat Script Terminating Before AWS Auto Scaling Commands Executed

I am fairly new to Amazon Cloud Auto Scaling (and AWS all together).
I am currently trying to write a .bat script that will automatically create a launch configuration and then an auto scaler. The aim is for an image that was previously set up about a week ago by a coworker.
The problem I encounter is that when I run the script, no commands past the launch configuration command is executed.
The code is here:
echo Beginning Auto Scale Up Process
REM Create a launch config
as-create-launch-config --image-id ami-xxxxxxx --instance-type t1.micro --user-data "Created by Launch Config reportingServerScaleUp-lc" --launch-config reportingServerScaleUp-lc
echo Timer Complete
I am looking for suggestions to help me debug this issue. Or advice on how to solve it. After the "echo Timer Complete" I have a command to create an auto scaler. Though, not even the "echo Timer Complete" is executed. The console does return indicating that the launch configuration is created though :)
Also, when I enter each command sequentially into the command line, each executes perfectly. The launch configuration is created as is the auto scale group.
It turns out that the AWS commands call exit which exits the .bat script prematurely.
Prepending each AWS command with "call" did the trick.
I found suggestions in this question: Why does only the first line of this Windows batch file execute but all three lines execute in a command shell?

Resources