Trying to run all of the sql scripts in one NOHUP command. Below is my code. But, it is not running in nohup mode based on the below. There are no errors either. How do I run all of the below in one NOHUP command??
nohup sqlplus -S /NOLOG << %EOF% > engine_error.log
WHENEVER SQLERROR EXIT 1;
#$Level2/passFile server05
#engine_check.sql $stroke1 $bore1
#engine_start.sql
%EOF% &
When you have a script that must start some background jobs, make a script that starts functions with & and nohup your script.
When your script startit.sh looks like
function f1 {
echo "f1 start"
sleep 2
echo "f1 end"
}
function f2 {
echo "f2 start"
sleep 1
echo "f2 end"
}
function f3 {
echo "f3 start"
sleep 1
cat <<END
f3 start here
more f3
f3 end here
END
echo "f3 end"
}
f1 &
f2
f3 &
call nohup startit.sh.
Try putting this in a script and then nohup the script. The nohup is probably getting confused because of the command.
#!/usr/bin/env
#query.sh
sqlplus -S /NOLOG << %EOF% > engine_error.log
WHENEVER SQLERROR EXIT 1;
#$Level2/passFile server05
#engine_check.sql $stroke1 $bore1
#engine_start.sql
EOF
Then in your shell try doing this
nohup query.sh &
Problem is "&" (or any sign) in same line with EndOfMessage-String.
"EOF &" is not equal to "EOF" -> "inline script" is still waiting for "EOF".
A line with only the defined string after "<<" can finalize the "inline script":
Related
I want to configure zsh to append the time each command started next to the line command was executed on. For example:
# before I press ENTER
$ ./script
# after I press enter
$ ./script [15:55:58]
Running script...
I came up with the following config (which also colors the timestamp yellow):
preexec () {
TIME=`date +"[%H:%M:%S] "`
echo -e "$1 %{$fg[yellow]%}\033[1A\033[1C${TIME}$reset_color"
}
But it breaks and prints { and % characters on basic commands such as cat and echo. It also breaks on password prompts (macOS terminal). For example with echo:
$ echo "hello" [15:55:58]
hello"hello" %{%}
How can I fix this config?
Thank you.
You inspired me and based on your script I wrote mine. I have tested this on zsh 5.4.smth.
preexec () {
local TIME=`date +"[%H:%M:%S] "`
local zero='%([BSUbfksu]|([FK]|){*})'
local PROMPTLEN=${#${(S%%)PROMPT//$~zero/}}
echo "\033[1A\033[$(($(echo -n $1 | wc -m)+$PROMPTLEN))C $fg[blue]${TIME}$reset_color"
}
In your ~/.zshrc file, put:
function preexec() {
timer=${timer:-$SECONDS}
}
function precmd() {
if [ $timer ]; then
timer_show=$(($SECONDS - $timer))
export RPROMPT="%F{cyan}${timer_show}s %F{$black%}"
unset timer
fi
}
And that should give you something like this:
I am not exactly sure if i am using the exits correctly. But when i execute the code with something that prints the usage statement it should stop there.
It should do one or the other. In my case it is doing both.
cmd="$1" ## the command to find
if [[ $# -ne 1 ]]
then
echo "usage: ./findcmd command"
fi
exit=1
path=$(echo $PATH | tr ":" " ")
for dir in $path
do
if [[ -x "$dir/$cmd" && -r "$dir/$cmd" ]]
then
echo "$dir/$cmd"
exit 0
fi
done
echo "$cmd not on $PATH"
exit=0
OUTPUT:
[112] ./findcmd
usage: ./findcmd command
/usr/local/bin/ **this should not be here
[113] ./findcmd ping
/usr/bin/ping
You use exit correctly to stop the script after your dir/cmd gets printed; try using it that way elsewhere.
Keep in mind that your first exit, once correct, will stop the script before the loop whether usage was printed or not.
It should be exit [n].
Within a script, an exit nnn command may be used to deliver an nnn
exit status to the shell (nnn must be an integer in the 0 - 255
range).
And it should be inside the IF/FOR block.
Like this:
cmd="$1" ## the command to find
if [[ $# -ne 1 ]]
then
echo "usage: ./findcmd command"
exit 1
fi
## rest of code to execute if args are correct
I am writing a script where I am grepping for a word and if it is true it should exit script else should continue the script. But my script is not going to else part even when grep output is false.
ps -fu rdb1 | grep humor >> humor_chk
grep humor.pl humor_chk | tail -1
if [ $? -eq 0 ]
then
echo "`date +%D' '%T` Humor is still running. Hence exiting" >> $LOG1
exit
else
ls -lrt /a/b/c/ >> files
fi
I am getting the output as:
01/19/15 05:54:03 Humor is still running. Hence exiting
I would like to do something like this in a zsh script
flock my_lock_file if condition_a ;
then
do_b
else
do_c
fi
Unfortunately I get a parse error around the then.
I would like to execute this in the same process, so something like
flock my_lock_file (
if condition_a ;
then
do_b
else
do_c
fi
)
is out of the question.
You can open a file descriptor for flock like this:
integer myfd
exec {myfd}<>lockfile
flock $myfd
# do whatever you want
echo "with lock"
sleep 3
# close the file descriptor
exec {myfd}>&-
echo "release lock"
I have a scheduled unix script that I want to log the output of. I am unable to edit the cron file due to the user interface restrictions, and I am unable to add >> logfile to the command. Is there something I can add within the script itself to send the output to a log?
{
printf poo
#Do not change
PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf
#Can be changed
FROM="nas4free#usinfosec.com"
TO="dpatino#usinfosec.com"
MDIR="CaseData"
SUBJECT="$MDIR Backup Report"
} > /mnt/support/logs/$SUBJECT.log
#BODY="$(cat /mnt/support/logs/test.log)"
#$PRINTF "From:$FROM\nTo:$TO\nSubject:$SUBJECT\n\n$BODY" | $MSMTP --file=$MSMTPCONF -t
Try
#!/bin/bash
exec > /tmp/myLog.log 2>&1
set -x
The log shows:
+ echo 'Hello World!'
Hello World!
One way is to wrap your script in braces and redirect the output as shown below:
#!/bin/bash
{
# script contents here
echo running script
} > logfile
Append following line in starting of your script
log_file_path="/tmp/output.log"
log() { while IFS='' read -r line; do echo "$line" >> "$log_file_path"; done; };
exec > >(tee >(log)) 2>&1
Your script with modification
PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf
FROM="nas4free#usinfosec.com"
TO="dpatino#usinfosec.com"
MDIR="CaseData"
SUBJECT="$MDIR Backup Report"
{
printf poo
} > /mnt/support/logs/$SUBJECT.log
#BODY="$(cat /mnt/support/logs/test.log)"
#$PRINTF "From:$FROM\nTo:$TO\nSubject:$SUBJECT\n\n$BODY" | $MSMTP --file=$MSMTPCONF -t