Rtsp Source:Video: payload 97, H264Audio: payload 96, MPEG4-GENERIC AACWorks:Watch Video and Listen to Audiortspsrc location=[RTSP_Server_IP] name=rtspsrc rtspsrc.
! queue ! application/x-rtp,payload=96 ! rtpmp4gdepay ! aacparse ! avdec_aac ! audioconvert ! autoaudiosink sync=false rtspsrc.
! queue ! application/x-rtp,payload=97 ! rtph264depay ! h264parse ! avdec_h264 ! autovideosink sync=falseDoesn't WorkConvert to MP4 filertspsrc location=[RTSP_Server_IP] name=rtspsrc rtspsrc. ! queue ! application/x-rtp,payload=96 ! rtpmp4gdepay ! aacparse ! avdec_aac ! audioconvert ! autoaudiosink sync=false rtspsrc. mux. ! queue ! application/x-rtp,payload=97 ! rtph264depay ! h264parse mux. ! mp4mux name=mux ! filesink location=test.mp4Anybody have any ideas?
rtspsrc location=[RTSP_Server_IP] name=rtspsrc ! rtph264depay ! h264parse ! mpegtsmux name=mux ! filesink location="test.mp4" rtspsrc. ! rtpmp4gdepay ! aacparse ! mux.
Related
This one is stumping me quite well! Big points for a resolution!
I need to traverse a directory and all levels below it to discover any files or directories that do not match a pattern.
I'm using find command -
find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '/home/user/inbox/*' -a ! -path /home/user/inbox/imaging -a ! -path '/home/user/inbox/imaging/*' \) -ls
The error -
find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '/home/user/inbox/*' -a ! -path /home/user/inbox/imaging -a ! -path '/home/user/inbox/imaging/*' \) -ls: No such file or directory
Yes, each of those directories in the find command do indeed exist -
ls -ld /home/user/inbox /home/user/inbox/imaging/
drwxr-xr-x. 5 user grp-ftp-admin 8192 Jan 13 12:45 /home/user/inbox
drwxr-xr-x. 3 user grp-ftp-admin 152 Jan 13 12:21 /home/user/inbox/imaging/
The entire script source -
#!/usr/bin/env bash
function findInvalidArtifacts() {
unset inbox sshCommand exitCode cmdOutput
s ilocal -A VENDOR=(
['FTPBASE']="/home/user"
['FTPSOURCEDIR']="/home/user/inbox/imaging"
['FRIENDLYNAME']="user"
['ENVIRONMENT']="dev"
)
inbox="${VENDOR['FTPBASE']}/inbox"
printf -v sshCommand "find -L %s \( ! -path %s -a ! -path '%s/*' -a ! -path %s -a ! -path '%s/*' \) -ls" \
"${inbox}" "${inbox}" "${inbox}" "${VENDOR['FTPSOURCEDIR']}" "${VENDOR['FTPSOURCEDIR']}"
#cmdOutput=$(ssh ${SSHOPTIONS} ${SSHUSERHOST} "${sshCommand}" 2>&1)
cmdOutput=$("${sshCommand}")
exitCode="${?}"
if (( 0 != $exitCode )); then
printf "FAILED - sshCommand=[%s], exitCode=[%d], cmdOutput=[%s]\n" "${sshCommand}" "${exitCode}" "${cmdOutput}"
exit 1
fi
printf "SUCCEEDED - sshCommand=[%s] exitCode=[%d]\n" "${sshCommand}" "${exitCode}"
printf "%s\n\n" "${cmdOutput}"
} # end findInvalidArtifacts()
And, finally, running the script with bash -vx -
#!/usr/bin/env bash
function findInvalidArtifacts() {
unset inbox sshCommand exitCode cmdOutput
local -A VENDOR=(
['FTPBASE']="/home/user"
['FTPSOURCEDIR']="/home/user/inbox/imaging"
['FRIENDLYNAME']="user"
['ENVIRONMENT']="dev"
)
inbox="${VENDOR['FTPBASE']}/inbox"
printf -v sshCommand "find -L %s \( ! -path %s -a ! -path '%s/*' -a ! -path %s -a ! -path '%s/*' \) -ls" \
"${inbox}" "${inbox}" "${inbox}" "${VENDOR['FTPSOURCEDIR']}" "${VENDOR['FTPSOURCEDIR']}"
#cmdOutput=$(ssh ${SSHOPTIONS} ${SSHUSERHOST} "${sshCommand}" 2>&1)
cmdOutput=$("${sshCommand}")
exitCode="${?}"
if (( 0 != $exitCode )); then
printf "FAILED - sshCommand=[%s], exitCode=[%d], cmdOutput=[%s]\n" "${sshCommand}" "${exitCode}" "${cmdOutput}"
exit 1
fi
printf "SUCCEEDED - sshCommand=[%s] exitCode=[%d]\n" "${sshCommand}" "${exitCode}"
printf "%s\n\n" "${cmdOutput}"
} # end findInvalidArtifacts()
findInvalidArtifacts
+ findInvalidArtifacts
+ unset inbox sshCommand exitCode cmdOutput
+ VENDOR=(['FTPBASE']="/home/user" ['FTPSOURCEDIR']="/home/user/inbox/imaging" ['FRIENDLYNAME']="user" ['ENVIRONMENT']="dev")
+ local -A VENDOR
+ inbox=/home/user/inbox
+ printf -v sshCommand 'find -L %s \( ! -path %s -a ! -path '\''%s/*'\'' -a ! -path %s -a ! -path '\''%s/*'\'' \) -ls' /home/user/inbox /home/user/inbox /home/user/inbox /home/user/inbox/imaging /home/user/inbox/imaging
++ 'find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '\''/home/user/inbox/*'\'' -a ! -path /home/user/inbox/imaging -a ! -path '\''/home/user/inbox/imaging/*'\'' \) -ls'
./try.sh: line 16: find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '/home/user/inbox/*' -a ! -path /home/user/inbox/imaging -a ! -path '/home/user/inbox/imaging/*' \) -ls: No such file or directory
+ cmdOutput=
+ exitCode=127
+ (( 0 != 127 ))
+ printf 'FAILED - sshCommand=[%s], exitCode=[%d], cmdOutput=[%s]\n' 'find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '\''/home/user/inbox/*'\'' -a ! -path /home/user/inbox/imaging -a ! -path '\''/home/user/inbox/imaging/*'\'' \) -ls' 127 ''
FAILED - sshCommand=[find -L /home/user/inbox \( ! -path /home/user/inbox -a ! -path '/home/user/inbox/*' -a ! -path /home/user/inbox/imaging -a ! -path '/home/user/inbox/imaging/*' \) -ls], exitCode=[127], cmdOutput=[]
+ exit 1
This is a stumper. I cannot see where why find is complaining about 'no such file or directory'.
Appreciate the valiant effort, however the constructed command still does not return the desired results. The contents of finding all existing artifacts in /home/user/inbox are:
/home/user/inbox
/home/user/inbox/invalidDir2
/home/user/inbox/invalidDir2/invalidSubdir2
/home/user/inbox/invalidDir2/invalidSubdir2/invalidFile1
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2/invalidSubSubSubDir2
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2/invalidSubSubSubDir2/invalidSubSubSubSubDir2
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2/invalidSubSubSubDir2/invalidSubSubSubSubDir2/invalidFile
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2/invalidSubSubSubDir2/invalidFile
/home/user/inbox/invalidDir2/invalidSubdir2/invalidSubSubDir2/invalidFile
/home/user/inbox/imaging
/home/user/inbox/imaging/validFile
/home/user/inbox/imaging/invalidFile
/home/user/inbox/imaging/invalidImagingDir1
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1/invalidFile1
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1/invalidSubSubDir1
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1/invalidSubSubDir1/invalidSubSubSubDir1
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1/invalidSubSubDir1/invalidSubSubSubDir1/invalidFile
/home/user/inbox/imaging/invalidImagingDir1/invalidSubdir1/invalidSubSubDir1/invalidFile
/home/user/inbox/imaging/invalidImagingDir1/invalildFile
/home/user/inbox/invalidFile
/home/user/inbox/invalidDir1
/home/user/inbox/invalidDir1/invalidSubdir1
/home/user/inbox/invalidDir1/invalidSubdir1/invalidFile1
/home/user/inbox/invalidDir1/invalidSubdir1/invalidSubSubDir1
/home/user/inbox/invalidDir1/invalidSubdir1/invalidSubSubDir1/invalidSubSubSubDir1
/home/user/inbox/invalidDir1/invalidSubdir1/invalidSubSubDir1/invalidSubSubSubDir1/invalidFile
/home/user/inbox/invalidDir1/invalidSubdir1/invalidSubSubDir1/invalidFile
The result set should NOT contain anything matching the directory to search in, or any of the parameters passed to your function that constructs the command. Results should NOT contain these lines -
/home/user/inbox
/home/user/inbox/imaging
/home/user/inbox/imaging/validFile
The command your function constructs looks like this -
find -L /home/user/inbox '(' '!' -path /home/user/inbox -a '!' -path '/home/user/inbox/*' -a '!' -path /home/user/inbox/imaging -a '!' -path '/home/user/inbox/imaging/*' ')' -ls
which returns nothing at all
I'm beginning to think that the find command is not what I need to obtain the desired results and that I'll need to do some more processing of the result set to disclude, probably awk or something.
Relevant snippet:
printf -v sshCommand "find -L %s \( ! -path %s -a ! -path '%s/*' -a ! -path %s -a ! -path '%s/*' \) -ls" [more args]
cmdOutput=$("${sshCommand}")
This is a classic pitfall of trying to shove a command into a variable and run it. The basic solution is to use a function, not a variable.
The reason for your error is that Bash determines the name of the command you're trying to run by selecting the first word of the command line after completing all of its parsing steps. You want to use the command find with some arguments, but since you have "${sshCommand}" in quotes, there's only one word in the entire command line so Bash thinks the command you want is called find -L /home/dir ( ! -path etc etc... ). I bet you don't have any executables with that name on your system.
A function equivalent of what you're trying to do might look like:
_findCmd() {
searchDir=$1 # first arg is the directory to search from
shift
# each extra argument is a directory to exclude from the search
# we can loop over the list and build the arguments that find needs
# in an array
path_args=()
if (( $# > 0 )) ; then
path_args+=( "(" "!" "-path" "$1" )
shift
while (( $# > 0 )) ; do
path_args+=( "-a" "!" "-path" "$1" )
shift
done
path_args+=( ")" )
fi
find -L "$searchDir" "${path_args[#]}" -ls
}
cmdOutput=$( _findCmd /home/user/inbox /home/user/inbox "/home/user/inbox/*" /home/user/inbox/imaging "/home/user/inbox/imaging/*" )
I'm trying to record a specific audio + video-stream to a file (while this stream is displayed on the same machine).
Here is the code from my receiver.sh file:
#!/bin/sh
#
# A simple RTP receiver
#
# receives H264 encoded RTP video on port 5000, RTCP is received on port 5001.
# the receiver RTCP reports are sent to port 5005
# receives alaw encoded RTP audio on port 5002, RTCP is received on port 5003.
# the receiver RTCP reports are sent to port 5007
#
# .-------. .----------. .---------. .-------. .-----------.
# RTP |udpsrc | | rtpbin | |h264depay| |h264dec| |xvimagesink|
# port=5000 | src->recv_rtp recv_rtp->sink src->sink src->sink |
# '-------' | | '---------' '-------' '-----------'
# | |
# | | .-------.
# | | |udpsink| RTCP
# | send_rtcp->sink | port=5005
# .-------. | | '-------' sync=false
# RTCP |udpsrc | | | async=false
# port=5001 | src->recv_rtcp |
# '-------' | |
# | |
# .-------. | | .---------. .-------. .-------------.
# RTP |udpsrc | | rtpbin | |pcmadepay| |alawdec| |autoaudiosink|
# port=5002 | src->recv_rtp recv_rtp->sink src->sink src->sink |
# '-------' | | '---------' '-------' '-------------'
# | |
# | | .-------.
# | | |udpsink| RTCP
# | send_rtcp->sink | port=5007
# .-------. | | '-------' sync=false
# RTCP |udpsrc | | | async=false
# port=5003 | src->recv_rtcp |
# '-------' '----------'
# the destination machine to send RTCP to. This is the address of the sender and
# is used to send back the RTCP reports of this receiver. If the data is sent
# from another machine, change this address.
DEST=192.168.1.1
# this adjusts the latency in the receiver
LATENCY=200
# the caps of the sender RTP stream. This is usually negotiated out of band with
# SDP or RTSP. normally these caps will also include SPS and PPS but we don't
# have a mechanism to get this from the sender with a -launch line.
VIDEO_CAPS="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264"
AUDIO_CAPS="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)PCMA"
VIDEO_DEC="rtph264depay ! avdec_h264"
AUDIO_DEC="rtppcmadepay ! alawdec"
VIDEO_SINK="videoconvert ! videoscale ! video/x-raw,width=720,height=480 ! autovideosink"
AUDIO_SINK="audioconvert ! audioresample ! autoaudiosink"
gst-launch-1.0 -v rtpbin name=rtpbin latency=$LATENCY \
udpsrc caps=$VIDEO_CAPS port=5000 ! rtpbin.recv_rtp_sink_0 \
rtpbin. ! $VIDEO_DEC ! $VIDEO_SINK \
udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0 \
rtpbin.send_rtcp_src_0 ! udpsink port=5005 host=$DEST sync=false async=false\
udpsrc caps=$AUDIO_CAPS port=5002 ! rtpbin.recv_rtp_sink_1 \
rtpbin. ! $AUDIO_DEC ! $AUDIO_SINK \
udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1 \
rtpbin.send_rtcp_src_1 ! udpsink port=5007 host=$DEST sync=false async=false
I've found a very similar question how to record instead of playing a video stream but my intention is to play video + audio and record both to one file (for example mp4 or mkv).
In another thread i red that i have to do this by using the queue, tee and mux commands but i need some help by adding them correctly.
My thoughts were adding the commands like this :
...
VIDEO_DEC="rtph264depay ! avdec_h264 ! tee name=videoTee"
AUDIO_DEC="rtppcmadepay ! alawdec ! tee name=audioTee"
VIDEO_SINK="videoconvert ! videoscale ! video/x-raw,width=720,height=480 ! autovideosink !"
AUDIO_SINK="audioconvert ! audioresample ! autoaudiosink"
gst-launch-1.0 -v rtpbin name=rtpbin latency=$LATENCY \
udpsrc caps=$VIDEO_CAPS port=5000 ! rtpbin.recv_rtp_sink_0 \
rtpbin. ! $VIDEO_DEC ! $VIDEO_SINK \
udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0 \
rtpbin.send_rtcp_src_0 ! udpsink port=5005 host=$DEST sync=false async=false\
udpsrc caps=$AUDIO_CAPS port=5002 ! rtpbin.recv_rtp_sink_1 \
rtpbin. ! $AUDIO_DEC ! $AUDIO_SINK \
udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1 \
rtpbin.send_rtcp_src_1 ! udpsink port=5007 host=$DEST sync=false async=false \
matroskamux name=mkvMux ! filesink location=test1.mkv \
videoTee. ! queue ! mkvMux. \
audioTee. ! queue ! mkvMux.
but i get following error:
WARNING: erroneous pipeline: could not link autovideosink0 to udpsrc1
probably i have to change the position of these commands or/and i missed something.
It would be great, if i would get some hints to solve this.
I got some professional help solving my problem.
here's the correct way:
VIDEO_DEC="rtph264depay ! tee name=video_splitter ! queue ! h264parse ! avdec_h264"
AUDIO_DEC="rtppcmadepay ! tee name=audio_splitter ! queue ! alawdec"
...
rtpbin. ! $AUDIO_DEC ! $AUDIO_SINK\
udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1\
rtpbin.send_rtcp_src_1 ! udpsink port=5007 host=$DEST sync=false async=false \
matroskamux name=mux ! filesink location=test.mkv \
video_splitter. ! queue ! h264parse ! mux.video_%u \
audio_splitter. ! queue ! mux.audio_%u
Here I placed working example, solved thanks to all you and completed with comments:
#!/bin/bash
errors=() #array to store all errors
to="" #a variable
DEST="" #another variable
from="" #and so on
e=$(mv "$from" "$to" 2>&1) #this command makes first error
if [ -n "$e" ] ;then errors+=("$e"); fi #and this save it to array
e=$(mv "$DEST" "$to" 2>&1) #so this makes second error
if [ -n "$e" ] ; then errors+=("$e"); fi #and this saves it to array
if [ ${#errors[#]} -eq 0 ]; then #if no errors
echo OK
else #if there are error (YES)
echo "ATTENZIONE: SI SONO VERIFICATI DEGLI ERRORI DURANTE L'OPERAZIONE DI RESTORE:"
for t in "${errors[#]}"; do #display all errors
echo "$t"
done
fi
Thank you very mutch.
This is the first answare before the solution:
I need to add to an array all error messages in my bash file.
Thanks to shellcheck.net and Cyrus and Freddy I adjusted code:
I did it:
#!/bin/bash
#set -x #DEBUG
errors=()
to=""
DEST=""
if ! mv "$from" "$to" ; then errors+=("$?"); fi
if ! mvv "$DEST" "$to" ; then errors+=("$?"); fi
if [ ${#errors[#]} -eq 0 ]; then
echo OK
else
echo "ATTENZIONE: SI SONO VERIFICATI DEGLI ERRORI DURANTE L'OPERAZIONE DI RESTORE:"
for t in "${errors[#]}"; do
echo "$t"
done
fi
the output that I obtain is :
ATTENZIONE: SI SONO VERIFICATI DEGLI ERRORI DURANTE L'OPERAZIONE DI RESTORE:
0
0
How can I do to obtain the right error messages in my array "$errors" ?
Thanks
The problem is that you aren't getting the exit status of the command (e.g. mv "$from" "$to"), but of the negated command (e.g. ! mv "$from" "$to") -- since the command failed (nonzero exit status), the negated status is success (zero). In order to do this, you need to avoid negating the status between the command and when you record the status. The easiest way I know of to do this is to use || instead of if, like this:
mv "$from" "$to" || errors+=("$?")
I am working with influxDB. My requirement is that i have to edit init-influxdb.sh file and add a small script at the end of this file. My init-influxdb.sh file code is:
#!/bin/bash
set -e
AUTH_ENABLED="$INFLUXDB_HTTP_AUTH_ENABLED"
INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)
if [ -z "$INFLUXDB_META_DIR" ]; then
META_DIR="/var/lib/influxdb/meta"
else
META_DIR="$INFLUXDB_META_DIR"
fi
if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d "$META_DIR" 2>/dev/null)" ]; then
INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
if [ ! -z "$INIT_USERS" ]; then
if [ -z "$INFLUXDB_ADMIN_PASSWORD" ]; then
INFLUXDB_ADMIN_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)"
echo "INFLUXDB_ADMIN_PASSWORD:$INFLUXDB_ADMIN_PASSWORD"
fi
INIT_QUERY="CREATE USER \"$INFLUXDB_ADMIN_USER\" WITH PASSWORD '$INFLUXDB_ADMIN_PASSWORD' WITH ALL PRIVILEGES"
elif [ ! -z "$INFLUXDB_DB" ]; then
INIT_QUERY="$CREATE_DB_QUERY"
else
INIT_QUERY="SHOW DATABASES"
fi
INFLUXDB_INIT_PORT="8086"
INFLUXDB_HTTP_BIND_ADDRESS=127.0.0.1:$INFLUXDB_INIT_PORT INFLUXDB_HTTP_HTTPS_ENABLED=false influxd "$#" &
pid="$!"
INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -execute "
for i in {30..0}; do
if $INFLUX_CMD "$INIT_QUERY" &> /dev/null; then
break
fi
echo 'influxdb init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'influxdb init process failed.'
exit 1
fi
if [ ! -z "$INIT_USERS" ]; then
INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -username ${INFLUXDB_ADMIN_USER} -password ${INFLUXDB_ADMIN_PASSWORD} -execute "
if [ ! -z "$INFLUXDB_DB" ]; then
$INFLUX_CMD "$CREATE_DB_QUERY"
fi
if [ ! -z "$INFLUXDB_USER" ] && [ -z "$INFLUXDB_USER_PASSWORD" ]; then
INFLUXDB_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)"
echo "INFLUXDB_USER_PASSWORD:$INFLUXDB_USER_PASSWORD"
fi
if [ ! -z "$INFLUXDB_USER" ]; then
$INFLUX_CMD "CREATE USER \"$INFLUXDB_USER\" WITH PASSWORD '$INFLUXDB_USER_PASSWORD'"
$INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_USER\""
if [ ! -z "$INFLUXDB_DB" ]; then
$INFLUX_CMD "GRANT ALL ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_USER\""
fi
fi
if [ ! -z "$INFLUXDB_WRITE_USER" ] && [ -z "$INFLUXDB_WRITE_USER_PASSWORD" ]; then
INFLUXDB_WRITE_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)"
echo "INFLUXDB_WRITE_USER_PASSWORD:$INFLUXDB_WRITE_USER_PASSWORD"
fi
if [ ! -z "$INFLUXDB_WRITE_USER" ]; then
$INFLUX_CMD "CREATE USER \"$INFLUXDB_WRITE_USER\" WITH PASSWORD '$INFLUXDB_WRITE_USER_PASSWORD'"
$INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_WRITE_USER\""
if [ ! -z "$INFLUXDB_DB" ]; then
$INFLUX_CMD "GRANT WRITE ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_WRITE_USER\""
fi
fi
if [ ! -z "$INFLUXDB_READ_USER" ] && [ -z "$INFLUXDB_READ_USER_PASSWORD" ]; then
INFLUXDB_READ_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)"
echo "INFLUXDB_READ_USER_PASSWORD:$INFLUXDB_READ_USER_PASSWORD"
fi
if [ ! -z "$INFLUXDB_READ_USER" ]; then
$INFLUX_CMD "CREATE USER \"$INFLUXDB_READ_USER\" WITH PASSWORD '$INFLUXDB_READ_USER_PASSWORD'"
$INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_READ_USER\""
if [ ! -z "$INFLUXDB_DB" ]; then
$INFLUX_CMD "GRANT READ ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_READ_USER\""
fi
fi
fi
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.iql) echo "$0: running $f"; $INFLUX_CMD "$(cat ""$f"")"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'influxdb init process failed. (Could not stop influxdb)'
exit 1
fi
fi
# My custom script starts here
INIT_QUERY="CREATE USER \"$INFLUXDB_ADMIN_USER\" WITH PASSWORD '$INFLUXDB_ADMIN_PASSWORD' WITH ALL PRIVILEGES"
INFLUXDB_INIT_PORT="8086"
INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -username admin -password admin -execute "
echo 'Creating admin user of influx db'
$INFLUX_CMD "$INIT_QUERY"
echo 'Admin user of influx db created successfully'
echo 'Enabling authentication on influxdb server'
if [ -z "$AUTH_ENABLED" ]; then
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*true' /etc/influxdb/influxdb.conf | grep -io 'true' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
fi
Issue is that, after printing "Creating admin user of influx db" i get the error "Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: getsockopt
Please check your connection settings and ensure 'influxd' is running."
What can be the possible issue here ? There isn't any error on any other query. Why i am getting this error. I am stuck, any help would be much appreciated.
My DockerFile is:
FROM influxdb:1.7.6
ENV INFLUXDB_ADMIN_USER="admin"
ENV INFLUXDB_ADMIN_PASSWORD="admin"
ENV INFLUXDB_HTTP_AUTH_ENABLED=true
ENV TZ=America/Los_Angeles
RUN chmod +x entrypoint.sh
RUN chmod 777 /init-influxdb.sh
COPY init-influxdb.sh /
RUN chmod 777 /init-influxdb.sh
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
I think the problem is that the DB is not yet started when you try to run the statement.
Checking the rest of the script you can see their solution to the problem:
for i in {30..0}; do
if $INFLUX_CMD "$INIT_QUERY" &> /dev/null; then
break
fi
echo 'influxdb init process in progress...'
sleep 1
done
if [ "$i" = 0 ]; then
echo >&2 'influxdb init process failed.'
exit 1
fi
I think your setup does not involve the execution of that portion of the script though.
I am trying to write a bash/shell script for downloading BuildTools and compiling the jars with it, after that I want to move them to my webserver (/var/www/html/jars/) from within the script at /home/buildtools/
BuildTools downloads/compiles the jars and places them at the base directory, except the vanilla jar, which is located at work/ inside the base directory.
Even though it does download/compile the jars, they aren't all moving to the desired directories.
This is the code I am using at the moment (I think it might all be relevant to provide):
directory="$(pwd)/"
jar="BuildTools.jar"
path="${directory}${jar}"
output="/var/www/html/jars"
version=$1
if [[ ( -d "BuildData" ) || ( -d "Spigot" ) || ( -d "CraftBukkit" ) || ( -d "Bukkit" ) || ( -d "work" ) || ( -d "apache-maven-*" ) || ( -f "BuildTools.log.txt" ) ]]; then
echo "Cleaning up..."
rm -f -r BuildData/ Spigot/ CraftBukkit/ Bukkit/ work/ apache-maven-*/
rm -f BuildTools.log.txt spigot-*.jar craftbukkit-*.jar vanilla-*.jar
fi
if [[ ! -f "${jar}" ]]; then
echo "Downloading BuildTools..."
wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O ${jar}
chmod 775 ${jar}
fi
if [[ ! -z "${version}" ]]; then
echo "Compiling jars for version ${version}..."
java -jar ${jar} --rev ${version}
else
echo "No version specified."
echo "Compiling jars for the latest version..."
java -jar ${jar} --rev latest
fi
if [[ ( -f "${directory}spigot-*.jar" ) || ( -f "${directory}craftbukkit-*.jar" ) ]]; then
echo "Compilation is done. Re-organizing..."
if [[ ! -z "${version}" ]]; then
mv work/minecraft_server.*.jar ${directory}/vanilla-${version}.jar
else
mv work/minecraft_server.*.jar ${directory}/vanilla-latest.jar
fi
echo "Moving jars to the webserver..."
mv ${directory}/vanilla-*.jar ${output}/
mv ${directory}/spigot-*.jar ${output}/
mv ${directory}/craftbukkit-*.jar ${output}/
else
echo "Could not re-organize, the jars hasn't been moved."
fi
Edit:
By executing the command: ./compile.sh 1.8.6
For some reason the jarfiles aren't the right names.
Result of the code.
directory="$(pwd)/"
jar="BuildTools.jar"
path="${directory}${jar}"
output="/var/www/html/jars"
version=$1
if [[ ( -d "BuildData" ) || ( -d "Spigot" ) || ( -d "CraftBukkit" ) || ( -d "Bukkit" ) || ( -d "work" ) || ( -d "apache-maven-*" ) || ( -f "BuildTools.log.txt" ) ]]; then
echo "Cleaning up..."
rm -f -r BuildData/ Spigot/ CraftBukkit/ Bukkit/ work/ apache-maven-*/
rm -f BuildTools.log.txt done.txt spigot-*.jar craftbukkit-*.jar vanilla-*.jar
fi
if [[ ! -f "${jar}" ]]; then
echo "Downloading BuildTools..."
wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O ${jar}
chmod 775 ${jar}
fi
if [[ ! -z "${version}" ]]; then
echo "Compiling jars for version ${version}..."
java -jar ${jar} --rev ${version}
echo "done" > done.txt
else
echo "No version specified. Compiling jars for the latest version..."
java -jar ${jar} --rev latest
echo "done" > done.txt
fi
if [[ -f "done.txt" ]]; then
echo "Compilation is done. Re-organizing..."
for x in $(find ${directory} \( -name "*.jar" \)); do
name=$(basename "${x}" ".jar")
if [[ ${name} =~ ^(spigot|craftbukkit|minecraft_server)(-)?(.*)? ]]; then
fullname="${name}.jar"
echo "Jar found: ${fullname}, Moving to webserver..."
if [[ ! -z "${version}" ]]; then
outpath=${output}/${version}
if [[ ! -d ${outpath} ]]; then
mkdir ${outpath}
fi
mv -f ${x} ${outpath}/${fullname}
else
outpath=${output}/latest
if [[ ! -d ${outpath} ]]; then
mkdir ${outpath}
fi
rm -f -r ${outpath}
mv -f ${x} ${outpath}/${fullname}
fi
fi
done
echo "Jars uploaded."
else
echo "Could not re-organize, the jars hasn't been moved."
fi
And additionally, I would like to only have one file of each uploaded (Vanilla, Spigot, Craftbukkit), how do I do that?
It's because of the parenthesis inside your conditional expression, as well as trying to use globs on the wrong part of the expression (you can't use tests like that with globs).
To fix this you should do something like:
#set nullglob so non-matching globs return an empty string instead of an error
shopt -s nullglob
# assing the globs to arrays, note the quoting
spigotfiles=("${directory}"spigot-*.jar)
bukkitfiles=("${directory}"craftbukkit-*.jar)
# using an array without an index gives us the first item in the array
if [[ -f "$spigotfiles" || -f "$bukkitfiles" ]]; then
...
fi
The same error with parenthesis is in your cleanup-code too, which you can handle by just removing the parens (e.g. [[ -d "dirname" || -d "fooname" ]] )
You should also quote your variable expansions (i.e. "${jar}" etc.) in every case (like in a part of a command).
Also using [[ ! -z $foo ]] is the same as [[ -n $foo ]]
Edit:
Don't do
for x in $(find ${directory} \( -name "*.jar" \)); do
but instead just:
for x in *.jar; do
or if you want only your versioned files, you can do:
for x in *"-${version}.jar"; do
You still have the parens in the cleanup check, see the answer above for that.
And in the end of the script these lines are counterproductive:
if [[ ! -d ${outpath} ]]; then
mkdir ${outpath}
fi
rm -f -r ${outpath}
mv -f ${x} ${outpath}/${fullname}
As you first create a dir, then remove it and then try to move things into it (hint: remove the rm line)