I am trying to write a script that will run and send a notification email regarding a successful server restart, however, how should i do so in the best way?
Weblogic 8.1
Probably not the best way, but assuming you are working in a Linux/Unix environment you could try this script. This will watch your Weblogic start up script for a keyword (I chose "in RUNNING mode").
COUNTER=0
while [ $COUNTER -le 5 ]
do
grep "started in RUNNING mode" <full path and name of log file>
if [ $? -eq 0 ];
then
mail -s 'Server started' your_email#mail.com </dev/null
break
fi
COUNTER=`expr $COUNTER + 1`
sleep 6
done
Related
Need to check for distribution of a file in an array programmatically. Logging into a master server and then would like to check for file on workers using simple ssh. So far I have:
ssh $HOSTNAME "[ -e '$HOSTNAME:/directory/filename' ] && echo 'Exists'"
Based on some of the logging output, I know the ssh is successful, but how can I get the test to return a message to the master server? Running the above returns nothing.
SSH will exit with the same exit code as the command that you run on the remote host. If that command is a test, then the exit code will match what you would normally expect from a test.
I would suggest the following:
Simplify your command to only run the test over SSH
Run the echo on your local machine
It doesn't seem correct that you have $HOSTNAME: in front of your path.
ssh "$HOSTNAME" "test -e '/directory/filename'" && echo 'Exists'
I personally find if statements to be much more easily understandable, which is an optional change if you are willing to go that route:
if ssh "$HOSTNAME" "test -e '/directory/filename'"; then
echo "Exists"
else
echo "Does not exist" >&2
exit 1
fi
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.
I have a Meteor application with Circle CI as continuous integration service.
Facebook Flow is running locally with the following .flowconfig:
[ignore]
.*/node_modules/.*
[options]
module.name_mapper='^\/\(.*\)$' -> '<PROJECT_ROOT>/\1'
module.name_mapper='^meteor\/\(.*\):\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1_\2'
module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1'
In CI I get errors like:
client/main.jsx:4
4: import { Meteor } from 'meteor/meteor';
^^^^^^^^^^^^^^^ meteor/meteor. Required module not found
Flow seems not to find my modules. The rewrite rules do not apply. With SSH access to Circle CI I found ot that the <PROJECT_ROOT>/.meteor/local directory is not present.
Once I run meteor on the CI machine the directory will appear.
Problem: If I run meteor the Meteor server will start up and my test will time out.
As far as I see I need to either
Adapt my .flowconfig or
Find a way to get Meteor to create the directory without running meteor or
Find a way to kill the meteor process once the server is running.
I went with the third option:
bbaja42 shared a script that saves the output of a program and terminates the program once a keyword is reached.
Adapted to my case I have two files:
ci-tests.sh
#!/bin/sh
# Check if the output directory exits. Flow needs the modules there.
if [ ! -d ".meteor/local/build/programs/server/packages" ]; then
echo "Meteor build directory does not exist. Starting Meteor."
# Run Meteor so the output directory is built.
./build-and-kill-meteor.sh
else
echo "Meteor build directory exists"
fi
./node_modules/.bin/flow --json
if [ $? -ne 0 ] ; then
exit 1
fi
build-and-kill-meteor.sh
#!/bin/bash
OUTPUT=/tmp/meteor-launch.log
PROGRAM=meteor
$PROGRAM > $OUTPUT &
PID=$!
echo Program is running under pid: $PID
#Every 10 seconds, check requirements
while true; do
tail -1 $OUTPUT
grep "App running at: http://localhost" $OUTPUT
if [ $? -eq 0 ] ; then
break
fi
sleep 10
done
kill $PID || echo "Killing process with pid $PID failed, try manual kill with -9 argument"
I ran into the same issue and came up with my own derivation based on the OP's answer. I run this script on every CI build to ensure that Meteor will always install any new atmosphere packages that I'm shipping with.
#!/bin/bash
# Install meteor
if [ -d ~/.meteor ]; then sudo ln -s ~/.meteor/meteor /usr/local/bin/meteor; fi
if [ ! -e $HOME/.meteor/meteor ]; then curl https://install.meteor.com | sh; fi
OUTPUT=/tmp/meteor-launch.log
PROGRAM=meteor
$PROGRAM > $OUTPUT &
PID=$!
echo Program is running under pid: $PID
# Start meteor to install atmosphere packages
while true; do
tail -1 $OUTPUT
grep "Your application is crashing." $OUTPUT
# Cancel the program once meteor has started
if [ $? -eq 0 ] ; then
break
fi
sleep 10
done
kill $PID || echo "Killing process with pid $PID failed, try manual kill with -9 argument."
I tried adding a Meteor build for Sublime Text as follow :
{
"cmd": "meteor",
"working_dir": "${project_path}",
"shell": true
}
This build requires to save a file (.sublime-project) in the project's root folder. And it works... sort of. It just won't stop. Even closing Sublime, meteor will not stop and I have to ps and kill the process manually. I have tried the "Cancel Build" menu, and it does write (Cancelled), but meteor is still running.
It is even possible to stop the build command from Sublime? Can someone share their .sublime-build file for meteor?
Thank you.
I don't totally agree with you on the comment section, but I think it gonna be easy to solve your problem. I have a start script to start my meteor on the server and local like this
# start.sh
if [ "$1" = "local" ]; then
echo "Local mode is running"
nohup meteor --settings config/settings.json >> log.txt 2>&1 &
else
echo "Server mode is running"
nohup meteor --settings config/settings.server.json >> log.txt 2>&1 &
fi
echo $! > save_pid.txt
and this is the stop script
#stop.sh
kill -9 `cat save_pid.txt`
Now what you need to do is making the build start on Sublime to call the start script and cancel to call the stop script
i want to write script where it will login into 50 hosts and if login is successful it print message "login to host1 is
successful" if not it should print message "Not able to login to host1". once connection to the host is succesful it should fire df command to check filesystem if df is stuck somewhere
then it should print message "DF got stuck otherwise print message "DF is successful"
Please advice how should i achive this
i used below approach
#!/usr/bin/ksh
for i in `cat host.txt`
do
ssh $i
if [[ $? -eq 0 ]] then
df
if [[ $? -eq 0 ]] then
return 0
else
echo "Something is wrong"
fi
else
echo "not able to do df"
fi
done
Thanks
You could do this in you script:
$ ssh loessl.org df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda2 103212320 52448972 45520468 54% /
[..]
and/or have a look at pconsole
There are a million solutions to this, all of them too large to fit into this tiny box. Which one is right for you depends on your tastes (I prefer Dancer's Shell for small groups of machines and simple tasks, but other tools for larger tasks on more machines)
https://puppetlabs.com/mcollective/introduction/
http://rundeck.org/
http://docs.fabfile.org/en/1.0.1/index.html
http://func.et.redhat.com/
http://docs.opscode.com/knife.html
http://sourceforge.net/projects/dsh/
http://www.netfort.gr.jp/~dancer/software/dsh.html.en
http://sourceforge.net/apps/mediawiki/clusterssh/index.php?title=Main_Page
http://cssh.sourceforge.net/
But this is not something you're going to be solve with a few lines of bash.