Verify dbman is finished before continuing - openedge

For reasons I'd rather not go into, I have to use dbman on Windows to stop and start a database in a script. It works a treat, except it returns back to the OS that it finished before the database is actually shutdown.
According to this KB article https://knowledgebase.progress.com/articles/Article/P136887 there is stuff about this in the documentation, but I can't find it there!
Here's my script - would appreciate some help in working out how to wrap a check for the db being down!
call del /Q C:\temp\BackupLog.txt
call c:\Progress\OpenEdge117_64\bin\dbman.bat -database sports -user dbuser -password 111! -stop >> C:\temp\BackupLog.txt
call c:\Progress\OpenEdge117_64\bin\probkup C:\temp\sports C:\temp\SmartDBDelta%date%.bkp incremental -Bp 10 >> C:\temp\BackupLog.txt
call c:\Progress\OpenEdge117_64\bin\dbman.bat -database sports -user dbuser -password 111! -start >> C:\temp\BackupLog.txt

This seems to do the trick actually.
call del /Q C:\temp\BackupLog.txt
call c:\Progress\OpenEdge117_64\bin\dbman.bat -database sports -user dbuser -password 111! -stop >> C:\temp\BackupLog.txt
:loop
call c:\Progress\OpenEdge117_64\bin\proutil C:\temp\sports -C HOLDER >> C:\temp\BackupLog.txt
if %ERRORLEVEL% == 0 goto cont
goto loop
:cont
call c:\Progress\OpenEdge117_64\bin\probkup C:\temp\sports C:\temp\SmartDBDelta%date%.bkp incremental -Bp 10 >> C:\temp\BackupLog.txt
call c:\Progress\OpenEdge117_64\bin\dbman.bat -database sports -user dbuser -password 111! -start >> C:\temp\BackupLog.txt

Related

How to create a shortcut for task to run for local services in windows 10?

I have Bluetooth headphone, sometimes windows 10 fails to connect with Bluetooth device so I need to go to task manager -> Services - Open Services -> Find Bluetooth Support Service and restart it.
I was curious if I can make any shortcut or batch file operation or kind of script and I can just click on it and it will restart Bluetooth Support Service.
First, find your service name by typing this command:
powershell -Command "sc.exe query | Select-String -Pattern Bluetooth -Context 1,0"
You'll find your service's name with the string SERVICE_NAME just above the DISPLAY_NAME you searched for. It can be something like UmRdpService or RasMan, whatever.
Then, in an ELEVATED command prompt, type these two commands:
sc stop YourServiceNameFoundAbove
sc start YourServiceNameFoundAbove
Your service is now restarted.
You can use the following batch, it will ask automatically for elevation if needed.
Just modify the line set SRV=... and save it where it suits you, then you simply need to create a shortcut manually (done only once) on your desktop.
#echo off
setlocal EnableExtensions EnableDelayedExpansion
set SRV=YourServiceNameFoundPreviously
REM Check admin mode, auto-elevate if required.
openfiles > NUL 2>&1 || (
REM Not elevated. Do it.
echo createObject^("Shell.Application"^).shellExecute "%~dpnx0", "%*", "", "runas">"%TEMP%\%~n0.vbs"
cscript /nologo "%TEMP%\%~n0.vbs"
goto :eof
)
del /s /q "%TEMP%\%~n0.vbs" > NUL 2>&1
sc stop !SRV! || (
echo ERROR: Couldn't stop service !SRV!.
pause
goto :eof
)
sc start !SRV! || (
echo ERROR: Couldn't start service !SRV!.
pause
goto :eof
)
goto :eof

How are zsh autocompletions for commands with subcommands defined?

I am trying to write a tab-completion script for borg.
So far, I have managed to define completions for borg itself, as well as borg key with its subcommands and borg benchmark with its singular subcommand. However, I am now trying to define completion for borg init and I am having trouble.
The issue presents itself only when I define two arguments under the borg init command to use the same description text; i.e. both -e and --encryption should use the same description, as they are practically the same argument. This has worked fine for borg's arguments, but now it breaks.
This is my code, slightly redacted to spare you the redundancy:
compdef _borg borg
function _borg {
local line ret=1
local -a argus
local logs="--critical --error --warning --debug --info -v --verbose"
argus+=(
"(*)"{-h,--help}"[Show help and exit]"
"(*)-V[Show Borg version and exit]"
"($logs)--critical[Work on log level CRITICAL]"
"($logs)--error[Work on log level ERROR]"
"($logs)--warning[Work on log level WARNING (default)]"
"($logs)"{--info,-v,--verbose}"[Work on log level INFO]"
"($logs)--debug[Enable debug output; log level DEBUG]"
{-p,--progress}"[Show progress]"
"--log-json[Output one JSON object per log line instead of formatted text]"
"--show-version[Show/log borg version]"
"--show-rc[Show/log returncode]"
"--consider-part-files[treat part files like normal files (e.g. to list/extract them)]"
"--lock-wait[Wait at most SECONDS for acquiring a repository/cache lock (default 1)]:SECONDS:()"
"--umask[Set umask to M (local and remote; default 0077)]:M (umask value, e.g. 0077):()"
"--remote-path[Use PATH as borg executable on the remote (default: \"borg\")]:PATH:()"
"--remote-ratelimit[Set remote network upload rate limit in kiByte/s (default: 0=unlimited)]:RATE:()"
"--debug-profile[Write execution profile in Borg format into FILE.]:FILE:_files"
"--rsh[Use this command to connect to the \"borg serve\" process (default: \"ssh\")]:RSH:()"
"1: :((init\:\"Initialize a new repository\" \
create\:\"Create a new archive\" \
extract\:\"Extract the contents of an archive\" \
check\:\"Verifies consistency of a repository and its archives\" \
rename\:\"Renames an archive in a repository\" \
list\:\"Lists contents of a repository or archive\" \
diff\:\"Finds differences between archives\" \
delete\:\"Deletes an archive or an entire repository (and its cache)\" \
prune\:\"Prunes a repository\" \
info\:\"Shows info about a repository or archive\" \
mount\:\"Mounts an archive as a FUSE filesystem\" \
unmount\:\"Unmounts a FUSE filesystem mounted with \\\"borg mount\\\"\" \
key\:\"Keyword for key-related functions\" \
upgrade\:\"Upgrade a local Borg repository\" \
recreate\:\"EXPERIMENTAL: Recreates contents of existing archives\" \
export-tar\:\"Creates a tarball from an archive\" \
serve\:\"Starts repository server process. Not usually used manually.\" \
config\:\"Gets and sets options in local repository and cache config files\" \
with-lock\:\"Executes another command with the repository lock held\" \
break-lock\:\"Breaks the repository and cache locks\" \
benchmark\:\"Keyword for the benchmark function\"))" \
"*::arg:->args"
)
_arguments -w -s -S -C $argus[#] && ret=0
case $line[1] in
benchmark)
_borg_benchmark
;;
init)
_borg_init
;;
key)
_borg_key
;;
esac
return ret
}
function _borg_benchmark {
# stuff
}
function _borg_benchmark_crud {
# stuff again
}
function _borg_init {
local line ret=1
local -a argus
argus+=(
"-t[This is a test]"
"--test[This is a test]"
"(--append-only)--append-only[Create an append-only mode repository]"
"*::arg:->args"
)
_arguments -w -s -S -C $argus[#] && ret=0
return ret
}
function _borg_key {
# key stuff
}
function _borg_key_changepassphrase {
# stuff
}
function _borg_key_export {
# more stuff
}
function _borg_key_import {
# other stuff
}
If I try to tab-complete borg init - using this setup, I get the following output:
$ borg init -
Completing option
--append-only
--test
-t
-- Create an append-only mode repository
-- This is a test
--append-only
--test
-t
-- Create an append-only mode repository
-- This is a test
--append-only
--test
-t
-- Create an append-only mode repository
-- This is a test
--append-only
--test
-t
-- Create an append-only mode repository
-- This is a test
The completion appears to forget what tabs are and repeats itself four times. If I change --test[This is a test] to --test[This is another test] in _borg_init, I instead get the following completion:
$ borg init -
Completing option
--append-only -- Create an append-only mode repository
--test -- This is another test
-t -- This is a test
The above is "correct", in the sense that it's not broken, but I cannot seem to define arguments that share a description in a subcommand. How should I do that? And, more generally, how are you supposed to define completions for commands with subcommands (which may, in turn, have more arguments)?

FreePBX/Asterisk Recorded Calls not moving to correct location

FreePBX: 10.13.66-12/ISO install
Asterisk: 13.12.2
asterisk-addons: Latest
Users reported not being able to see/download on demand recordings from the UCP. The calls are however being recorded, /var/spool/asterisk/monitor is full of files, files that should have been moved to the appropriate date directories.
e.g. 2016/12/15.
I have setup a Post Call Recording Script that is set in FreePBX, this also doesn't run. It is simply to see if it ever gets called, appends to a file.
-rw-rw-r-- 1 asterisk asterisk 120364 Dec 15 17:20 1481858418.2722.wav
-rw-r--r-- 1 asterisk asterisk 147884 Dec 16 10:02 1481918523.4964.wav
The top file permissions were changed after running fwconsole chown. This leads me to think that asterisk doesn't have the correct permissions.
This is the breakdown of the debug log for MixMonitor
[2016-12-15 17:03:14] VERBOSE[20476] app_mixmonitor.c: Begin MixMonitor Recording SIP/200-00000125
[2016-12-15 17:03:24] VERBOSE[20476] app_mixmonitor.c: MixMonitor close filestream (mixed)`
[2016-12-15 17:03:24] VERBOSE[20476] app_mixmonitor.c: End MixMonitor Recording SIP/200-00000125
[2016-12-15 17:03:24] VERBOSE[20476] app_mixmonitor.c: Copying recordings for Mixmonitor SIP/200-00000125 to voicemail recipients
[2016-12-15 17:03:24] WARNING[20476] format_wav.c: Unable to set write file size
I have tried changing permissions, re-installing the asterisk-addons, and many other things. Any ideas out there?
Answering my own question.
This is an issue with digium phones and freepbx. Digium uses their own technique to record and save calls. https://wiki.asterisk.org/wiki/display/DIGIUM/Phone+Features+by+Environment
There is a solution to have the calls show up in the CDR and User Portal, but involves changes to the system. Use at you own risk.
Create an executable script belonging to the asterisk user, I keep mine in the asterisk user home directory.
#!/bin/bash
#this script is run from an incrontab
MONITOR=/var/spool/asterisk/monitor/
if [ -d "$MONITOR$1" ]; then
exit
fi
if [ ! -f "$MONITOR$1" ]; then
echo "$(date): Failed to move a recording. \"$MONITOR$1\" does not exist." >> /var/log/asterisk/moved_recording_log
exit
fi
filename=$1
uid=${filename%.*}
if [ $(sed -e "s/^.wav//I" <<< "${filename##*.}") != "wav" ]; then
exit
fi
CONF=/etc/asterisk/res_odbc_additional.conf
user=$(awk -F"=>" '/username=>/ {print $2}' ${CONF})
password=$(awk -F"=>" '/password=>/ {print $2}' ${CONF})
db=$( mysql asteriskcdrdb -u $user -p$password -se "SELECT cnum, calldate as date FROM cdr WHERE uniqueid = \"$uid\";" 2>/dev/null )
ext=$(echo $db | awk '{print $1}')
read -r -a dbd <<< "$db"
IFS="-" read -r -a dbdate <<< "${dbd[1]}"
if [ -z "${dbdate[0]}" ] || [ -z "${dbdate[1]}" ] || [ -z "${dbdate[2]}" ]; then
exit
fi
dir="/var/spool/asterisk/monitor/${dbdate[0]}/${dbdate[1]}/${dbdate[2]}/"
mkdir -p $dir
name="ondemand-${dbd[0]}-${dbd[0]}-${dbdate[0]}${dbdate[1]}${dbdate[2]}-${dbd[2]//:}-$filename"
db=$(mysql asteriskcdrdb -u $user -p$password -se "UPDATE cdr SET recordingfile=\"$name\" WHERE uniqueid = \"$uid\";")
mv $MONITOR$filename $dir$name
exit
The next step is what watches the recordings directory for any files that have been written.
As the asterisk user edit incrontab
incrontab -e
add the following with the location and name of the above script
/var/spool/asterisk/monitor/ IN_CLOSE_WRITE /bin/bash /home/asterisk/move_recordings.sh $#
This is based on a pretty generic FreePBX setup. There may be a nicer way to do this, but this has been working for me.
Correct solution - write file in place where it should be, i.e it to 2016/12/15
It is impossible guess what you dooing wrong(no scripts provided, config etc), but i can suggest you have selinux or permission issue.

Clarification in TC Shell Script

I have a script in TC shell, for some reason its not working.
Can anyone point out the issue in the same
#!/usr/bin/tcsh
while true
do
if ls /sample/test3 >& /dev/null ; then /sample/app_code/run/initiateLoad.sh ; endif
sleep 1800
done
The path /sample/test3 contains files so the if condition should have been successful and should have started the shell script, but its not happening.

cap deploy:cleanup fails with use_sudo=true

My capifony deployment works great, however the capifony cleanup command fails.
I'm using private keys over ssh, with sudo to gain write permissions on the deployment directories.
With extended logging the result of cap deploy:cleanup is this:
$ cap deploy:cleanup
* 2013-07-19 15:44:42 executing `deploy:cleanup'
* executing "sudo -p 'sudo password: ' ls -1dt /var/www/html/releases/* | tail -n +4 | sudo -p 'sudo password: ' xargs rm -rf"
Modifying permissions so that the deployment user has full write access to this directory is not an option in this instance.
Has anyone seen/worked around this issue? (This is on a RHEL6 server)
Yep, there is a problem with the cleanup command while using sudo at the moment. Here was my solution to fixing this. Add this to your deploy.rb
namespace :customtasks do
task :customcleanup, :except => {:no_release => true} do
count = fetch(:keep_releases, 5).to_i
run "ls -1dt #{releases_path}/* | tail -n +#{count + 1} | #{try_sudo} xargs rm -rf"
end
end
Then call that instead as cleanup
after "deploy:update", "customtasks:customcleanup"
More info at https://github.com/capistrano/capistrano/issues/474

Resources