I want to stop nohup script - sql

I've started nohup command to delete 1 month worth of data:
Nohup sqlplus username/password#sidname #/home/month.sql
After deleting some 10 days of data from that script, I want to stop the nohup script, or I want to keep the remaining 20 days of data as it is.
Please help with this

If you know the PID of the script, then kill -9 PID.
else find the PID first by using ps -ef | grep "Nohup sqlplus", then kill -9 PID.

Related

Using tail to monitor an active logging file

I'm running multiple 'shred' commands on multiple hard drives in a workstation. The 'shred' commands are all run in the background in order to run the commands concurrently. The output of each 'shred' is redirected to a text file, and I also have the output directed to the terminal as well. I'm using tail to monitor the log file for errors, and halt the script if any are encountered. If there are no errors, the script should simply continue on to conclusion. When I test it by forcing a drive failure (disconnecting a drive), it detects the I/O errors and the script halts as expected. The problem I'm having is that when there are NO errors, I cannot get 'tail' to terminate once the 'shred' commands have completed, and the script just hangs at that point. Since I put the 'tail' command in the 'while' loop below, I would have thought that 'tail' would continue to run as long as the 'shred' processes were running, but would then halt after the 'shred' processes stopped, thus ending the 'while' loop. But that hasn't been the case. The script still hangs even after the 'shred' processes have ended. If I go to another terminal window while the script is "hangiing," and kill the 'tail' process, the script continues as normal. Any ideas how to get the 'tail' process to end when the 'shred' processes are gone?
My code:
shred -n 3 -vz /dev/sda 2>&1 | tee -a logfile &
shred -n 3 -vz /dev/sdb 2>&1 | tee -a logfile &
shred -n 3 -vz /dev/sdc 2>&1 | tee -a logfile &
pids=$(pgrep shred)
while kill -0 $pids 2> /dev/null; do
tail -qn0 -f logfile | \
read LINE
echo "$LINE" | grep -q "error"
if [ $? = 0 ]; then
killall shred > /dev/null 2>&1
echo "Error encountered. Halting."
exit
fi
done
wait $pids
There is other code after the 'wait' that does other stuff, but this is where the script is hanging
Not directly related to the question, but you can use Daggy - Data Aggregation Utility
In this case, all subprocesses will be end with main daggy process.

Tensorflow: how to close tensorboard server

Once I've started tensorboard server with the command
tensorboard --logdir=path/to/logdir
is there a command that explicitly close it or can I just kill it without any harm?
Thanks
In my case, CTRL+C doesn't work. The following works for me:
CTRL+Z halts the on-going TensorBoard process.
Check the id of this halted process by typing in the terminal
jobs -l
kill this process, otherwise you can't restart TensorBoard with the default port 6006 (of course, you can change the port with --port=xxxx)
kill -9 #PROCESS_ID
You can kill it without any harm! TensorBoard simply reads your log files and generates visualizations based on them in memory, so you don't need to worry about file corruption, etc.
This command will find the tensorbroad process and terminate it:
kill $(ps -e | grep 'tensorboard' | awk '{print $1}')
I solved this problem by this way - (actually in my ssh, sometimes CTRL+C don't work properly. Then I use this)
Get the running tensorboard process details
ps -ef|grep tensorboard
Sample Output: uzzal_x+ 4585 4413 0 02:46 pts/4 00:00:01 bin/python /bin/tensorboard --logdir=runs/
Kill the process using pid (process id)
kill -9 <pid>
first number 4585 is my current pid for tensorflow
There is a shortcut that is more drastic than CTRL+C:
Try CTRL+\
You can write this:
ps -ef | grep port_number
Get the port number of the tensorboard, then use:
kill -9 PortNumber
On windows, use: taskkill /F /PID <pid> where <pid> is the process ID.

Can't kill process with any kill command derivation

There is the process named flask I can't kill either with
kill -9 PID #(PID found from ps aux | grep flask)
or with
killall -9 flask
it always respawns with higher PID
this command may be useful for you. But be careful, this command will kill all python processes.
pkill python3

Cant Terminate process which is launched at bootup with at daemon

I have fooinit.rt process launched at boot (/etc/init.d/boot.local)
Here is boot.local file
...
/bin/fooinit.rt &
...
I create an order list at job in order to kill fooinit.rt. that is Triggered in C code
and I wrote a stop script (in)which kill -9 pidof fooinit.rt is written
Here is stop script
#!/bin/sh
proc_file="/tmp/gdg_list$$"
ps -ef | grep $USER > $proc_file
echo "Stop script is invoked!!"
suff=".rt"
pid=`fgrep "$suff" $proc_file | awk '{print $2}'`
echo "pid is '$pid'"
rm $proc_file
When at job timer expires 'kill -9 pid'( of fooinit.rt) command can not terminate fooinit.rt process!!
I checked pid number printed and the sentence "Stop script is invoked!!" is Ok !
Here is "at" job command in C code (I verified that the stop scriptis is called after 1 min later)
...
case 708: /* There is a trigger signal here*/
{
result = APP_RES_PRG_OK;
system("echo '/sbin/stop' | at now + 1 min");
}
...
On the other hand, It works properly in case launching fooinit.rt manually from shell as a ordinary command. (not from /etc/init.d/boot.local). So kill -9 work and terminates fooinit.rt process
Do you have any idea why kill -9 can not terminate foo.rt process if it is launched from /etc/init.d/boot.local
Your solution is built around a race condition. There is no guarantee it will kill the right process (an unknowable amount of time can pass between the ps call and the attempt to make use of the pid), plus it's also vulnerable to a tmp exploit: someone could create a few thousand symlinks under /tmp called "gdg_list[1-32767]" that point to /etc/shadow and your script would overwrite /etc/shadow if it runs as root.
Another potential problem is the setting of $USER -- have you made sure it's correct? Your at job will be called as the user your C program runs as, which may not be the same user your fooinit.rt runs as.
Also, your script doesn't include a kill command at all.
A much cleaner way of doing this would be to run your fooinit.rt under some process supervisor like runit and use runit to shut it down when it's no longer needed. That avoids the pid bingo as well as the /tmp attack vector.
But even using pkill -u username -f fooinit.rt would be less racy than the script you provided.

ubuntu shell scripting

I'm new to shell scripting. I need to write a script that executes this command to get the process ID's for the tasks...
ps aux | grep java | grep dbConvert2 | awk '{print $2}'
then do some other stuff, and then kill the process ID's that I grabbed earlier...
I know I can do kill -9, i just don't know how to dynamically grab all the PID's and store them as variables
append | xargs kill -9 to your current command
[edit]
if you want to do some operations on each id, you can use a for loop, something like:
for my_pid in `YOUR_CMD`; do
<some stuff with $my_pid>
kill -9 $my_pid
done
pkill -9 'java.*dbConvert2'
You might want to use pgrep 'pattern' to try different patterns before.
Edit: If your process isn't matched, you might need to use -f (applies to both pgrep and pkill, use after the -9 though) to search the entire command including arguments.
Example: pkill -9 -f 'java.*dbConvert2'