Extracting a URL from a list of flash variables from bash - bash

I would want to download the ( .smil ) file with bash
The link of the file looks like that
http://website.fr:1535/3PBOLaEQ2kC19nmxtIYg8a4ziKlPQ9l0Jkn2hecxIexEZYc32znTlugcyxus%3D-08Fw3XtDFE9wrMbCGOZTOw%3D%3D.mp4?audioindex=0.smil
The filename -- everything after the last / and before the .mp4 -- changes on each reload, and is embedded in the site's code, within the flashvars parameter:
<param name="flashvars" value="netstreambasepath=http%3A%2F%2Fwebsite.fr%2Fvideo%2Fcelestial_method%2F5675-episode-4-04-fragments-d-emotions&id=yui_3_17_2_13_1414622045495_169&image=http%3A%2F%2Fi.jpg&skin=%2Fcomponents%2Fcom_vodvideo%2Fmediaplayer%2Fskin%2Fadn%2Fadn.xml&bufferlength=16000&repeat=list&title=undefined&logo=undefined&plugins=http%3A%2F%2Fwebsite.fr%2Fcomponents%2Fcom_vodvideo%2Fmediaplayer%2Fplugins%2Fcontrol%2Fcontrol.swf%2Chttp%3A%2F%2...wJgu2BiCfbqlqd6sQDZUlMO56C270iwoWT7GZ6txc%253D-ep69DPqWGsFsiQgVBAbiHQ%253D%253D.mp4%3Faudioindex%3D0.smil%22%2C%22default%22%3A%22http%3A%2F%website.fr%3A1935%2FS2v5wo0p7Fum7GI8_WlyBJU%252BXtVRjXY%252BkTuo_TXa0Wv0tpLLzR37DWx0AQkK52G9FMwJgu2BiCfbqlqd6sQDZUlMO56C270iwoWT7GZ6txc%253D-ep69DPqWGsFsiQgVBAbiHQ%253D%253D.mp4%3Faudioindex%3D0.smil%22%7D%5D&control.pluginmode=FLASH&mulutibu_v4_3.back=false&mulutibu_v4_3.cc=true&mulutibu_v4_3.pluginmode=FLASH&controlbar.position=over&dock.position=true">
How can I extract the link to launch VLC with the file directly?

The following would be a place to start:
# credit to https://gist.github.com/cdown/1163649
urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\x}"
}
flashvars_u=$(
curl http://your-website/ | \
xmllint --html --xmlout - | \
xmlstarlet sel -t -m '//param[#name="flashvars"]' -v #value
)
flashvars=$(urldecode "$flashvars")
Further extracting content from flashvars is hindered by the content being provided only in redacted/modified form, making it impossible to test whether code is correct.

Related

how can i run some custom commands in a loop sequentially

There are variables that I need to change and run sequentially within certain codes.For example, the ionex_list variable looks like this and i need to change this in a loop. I have 3 variable files like this and 9 pieces of data in a row (ionex_list,receiver_ids,data_record).
ionex_list data_record
jplg0910.19i.Z ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz
jplg0920.19i.Z ISTA00TUR_R_20190920000_01D_30S_MO.crx.gz
... ...
jplg0980.19i.Z ISTA00TUR_R_20190980000_01D_30S_MO.crx.gz
jplg0990.19i.Z ISTA00TUR_R_20190990000_01D_30S_MO.crx.gz
For example, I need to show ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz as -dataFile in rnxEditGde.py, but I get the error "File: "/y2019/d091" does not exist" and I cannot show the path. these .gz files are a few directories under from the directory I'm working in. Since I couldn't pass the rnxEditGde.py part, I can't see if the codes below work properly.
dir=`pwd`
function pl {
sed -n "$1p" $2
}
for j in {091..099}; do
ids=$(pl $j receiver_ids)
ionex=$(pl $j ionex_list)
dataRecordFile=$(pl $j data_record)
gd2e.py -mkTreeS Trees
sed -i "s/jplg.*/**$ionex**/g" $dir/Trees/ppp_0.tree
rnxEditGde.py -dataFile "/y2019/d${j}/**$dataRecordFile**" -o dataRecordFile.Orig.gz
gd2e.py \
-treeSequenceDir Trees \
-drEditedFile** $dataRecordFile** \
-antexFile goa-var/etc/antennaCalsGNSS/igs14_2038.atx \
-GNSS https://sideshow.jpl.nasa.gov/pub/JPL_GNSS_Products/MultiGNSS_Rapid_Test\
-runType PPP \
-recList **$ids** \
-staDb /goa-var/sta_info/sta_db_qlflinn \
>gd2e.log 2>gd2e.err
done

Supply binary content inside a JSON string via curl

I'm trying to use the Yandex.Cloud function API from bash and cURL.
In order to do that, I'm composing a JSON like this:
#Make header
IAM_TOKEN="myToken"
HEADER="Authorization: Bearer ${IAM_TOKEN}"
#Make data JSON
DATA=""
for ELEMENT in \
"'"\
'{"runtime":"dotnetcore31", "entrypoint": "Function.Handler",'\
'"resources":{"memory":"134217728"}, "content": "PLACEHOLDERFORCONTENT",'\
'"ServiceAccountId":"accId", '\
'"function_id": "funcId"}'\
"'"; do
DATA+="${ELEMENT}"
done
Then, I need to supply content of the deployment package inside JSON, as API suggests:
In my case, it is a zip archive with function code. So, I read the file as bytes and inject the result into the JSON string. And send the request.
#Read file content
FILE_LOC="/Users/Constantine/Downloads/archiveName.zip"
FILE_BYTES=`(xxd -b ${FILE_LOC}) | base64`
#Inject content into JSON
DATA=${DATA/PLACEHOLDERFORCONTENT/$FILE_BYTES}
#Send the request
eval "$(echo curl -H \"$HEADER\" --data-binary $DATA https://serverless-functions.api.cloud.yandex.net/functions/v1/versions)"
Here, I'm getting the -bash: /usr/bin/curl: Argument list too long error. I suspect this happens because cURL interprets the binary content as the filename to read, but I'm not sure how to resolve this.
How can I supply binary content from a file into a JSON string?
You are sending the request using a cURL call under bash. And the shell have a maximum line length that you are largely surpassing.
Your easiest workaround is to save your JSON data to a file and supply cURL with a pointer to this file, so that the line length remains contained:
#Make data JSON
data_file="data.json"
> "${data_file}"
for ELEMENT in \
"'"\
'{"runtime":"dotnetcore31", "entrypoint": "Function.Handler",'\
'"resources":{"memory":"134217728"}, "content": "PLACEHOLDERFORCONTENT",'\
'"ServiceAccountId":"accId", '\
'"function_id": "funcId"}'\
"'"; do
echo "${ELEMENT}"
done >> "${data_file}"
#Read file content
FILE_LOC="/Users/Constantine/Downloads/archiveName.zip"
FILE_BYTES=$(xxd -b "${FILE_LOC}" | base64)
#Inject content into JSON
sed -i "s/PLACEHOLDERFORCONTENT/${FILE_BYTES}/" "${data_file}"
#Send the request
eval "$(echo curl -H \"$HEADER\" --data-binary "#${data_file}" https://serverless-functions.api.cloud.yandex.net/functions/v1/versions)"
Besides that, your code seems quite complex for the duty. You could simplify it a little. Avoid loops, create the file in one go and avoid eval:
#Make data JSON
data_file="data.json"
FILE_LOC="/Users/Constantine/Downloads/archiveName.zip"
cat <<-EOF > "${data_file}"
{
"runtime": "dotnetcore31",
"entrypoint": "Function.Handler",
"resources": {
"memory": "134217728"
},
"content": "$(xxd -b "${FILE_LOC}" | base64)",
"ServiceAccountId": "accId",
"function_id": "funcId"
}
EOF
#Send the request
curl -H "$HEADER" --data-binary "#${data_file}" https://serverless-functions.api.cloud.yandex.net/functions/v1/versions

Issue on concatenating files shellscipt

Sorry, I'm from Brazil and my english is not fluent.
I wanna concatenate 20 files using a shellscript through cat command. However when I run it from a file, all content of files are showed on the screen.
When I run it directly from terminal, works perfectly.
That's my code above:
#!/usr/bin/ksh
set -x -a
. /PROD/INCLUDE/include.prod
DATE=`date +'%Y%m%d%H%M%S'`
FINAL_NAME=$1
# check if all paremeters are passed
if [ -z $FINAL_NAME ]; then
echo "Please pass the final name as parameter"
exit 1
fi
# concatenate files
cat $DIRFILE/AI6LM760_AI6_CF2_SLOTP01* $DIRFILE/AI6LM761_AI6_CF2_SLOTP02* $DIRFILE/AI6LM763_AI6_CF2_SLOTP04* \
$DIRFILE/AI6LM764_AI6_CF2_SLOTP05* $DIRFILE/AI6LM765_AI6_CF2_SLOTP06* $DIRFILE/AI6LM766_AI6_CF2_SLOTP07* \
$DIRFILE/AI6LM767_AI6_CF2_SLOTP08* $DIRFILE/AI6LM768_AI6_CF2_SLOTP09* $DIRFILE/AI6LM769_AI6_CF2_SLOTP10* \
$DIRFILE/AI6LM770_AI6_CF2_SLOTP11* $DIRFILE/AI6LM771_AI6_CF2_SLOTP12* $DIRFILE/AI6LM772_AI6_CF2_SLOTP13* \
$DIRFILE/AI6LM773_AI6_CF2_SLOTP14* $DIRFILE/AI6LM774_AI6_CF2_SLOTP15* $DIRFILE/AI6LM775_AI6_CF2_SLOTP16* \
$DIRFILE/AI6LM776_AI6_CF2_SLOTP17* $DIRFILE/AI6LM777_AI6_CF2_SLOTP18* $DIRFILE/AI6LM778_AI6_CF2_SLOTP19* \
$DIRFILE/AI6LM779_AI6_CF2_SLOTP20* > CF2_FINAL_TEMP
mv $DIRFILE/CF2_FINAL_TEMP $DIRFILE/$FINAL_NAME
I solved the problem putting the cat block inside a function, and redirecting stdout to the final file.
Ex:
concatenate()

Convert multi part form from curl to ruby that uploads file and contains json [duplicate]

This question already has answers here:
Ruby: How to post a file via HTTP as multipart/form-data?
(14 answers)
Closed 6 years ago.
I need to convert this multi-part form that contains some json and also uploads a file.
curl \
-F metadata='{"userID":"12345","mimeType":"image/jpeg","typeHint": "uploadedImage" }' \
-F contents=#$HOME/Downloads/photo.jpg \
http://localhost:8083/myservice/upload
With curl
As is
The obvious answer would be to just call the given command from Ruby :
curl_command = %q(curl -F metadata='{"userID":"12345","mimeType":"image/jpeg","typeHint": "uploadedImage" }' -F contents=#$HOME/Downloads/photo.jpg http://localhost:8083/myservice/upload)
system(curl_command)
%q() is used to define a string since you have many characters that would need to be unescaped otherwise (e.g. " or ')
with parameters
If you want dynamic parameters, you could use :
def curl_command(user_id, file, url)
%Q(curl -F metadata='{"userID":"#{user_id}","mimeType":"image/jpeg","typeHint": "uploadedImage" }' -F contents=#{file} #{url})
end
picture = File.join(Dir.home, 'Downloads', 'photo.jpg')
puts curl_command(12345, picture, "http://localhost:8083/myservice/upload")
#=> curl -F metadata='{"userID":"12345","mimeType":"image/jpeg","typeHint": "uploadedImage" }' -F contents=/home/eric/Downloads/photo.jpg http://localhost:8083/myservice/upload
system(curl_command(12345, picture, "http://localhost:8083/myservice/upload"))
With curb
It looks like the curb gem can do what you want :
HTTP POST file upload:
c = Curl::Easy.new("http://my.rails.box/files/upload")
c.multipart_form_post = true
c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))

Run a string as a command within a Bash script

I have a Bash script that builds a string to run as a command
Script:
#! /bin/bash
matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"
teamAComm="`pwd`/a.sh"
teamBComm="`pwd`/b.sh"
include="`pwd`/server_official.conf"
serverbin='/usr/local/bin/rcssserver'
cd $matchdir
illcommando="$serverbin include='$include' server::team_l_start = '${teamAComm}' server::team_r_start = '${teamBComm}' CSVSaver::save='true' CSVSaver::filename = 'out.csv'"
echo "running: $illcommando"
# $illcommando > server-output.log 2> server-error.log
$illcommando
which does not seem to supply the arguments correctly to the $serverbin.
Script output:
running: /usr/local/bin/rcssserver include='/home/joao/robocup/runner_workdir/server_official.conf' server::team_l_start = '/home/joao/robocup/runner_workdir/a.sh' server::team_r_start = '/home/joao/robocup/runner_workdir/b.sh' CSVSaver::save='true' CSVSaver::filename = 'out.csv'
rcssserver-14.0.1
Copyright (C) 1995, 1996, 1997, 1998, 1999 Electrotechnical Laboratory.
2000 - 2009 RoboCup Soccer Simulator Maintenance Group.
Usage: /usr/local/bin/rcssserver [[-[-]]namespace::option=value]
[[-[-]][namespace::]help]
[[-[-]]include=file]
Options:
help
display generic help
include=file
parse the specified configuration file. Configuration files
have the same format as the command line options. The
configuration file specified will be parsed before all
subsequent options.
server::help
display detailed help for the "server" module
player::help
display detailed help for the "player" module
CSVSaver::help
display detailed help for the "CSVSaver" module
CSVSaver Options:
CSVSaver::save=<on|off|true|false|1|0|>
If save is on/true, then the saver will attempt to save the
results to the database. Otherwise it will do nothing.
current value: false
CSVSaver::filename='<STRING>'
The file to save the results to. If this file does not
exist it will be created. If the file does exist, the results
will be appended to the end.
current value: 'out.csv'
if I just paste the command /usr/local/bin/rcssserver include='/home/joao/robocup/runner_workdir/server_official.conf' server::team_l_start = '/home/joao/robocup/runner_workdir/a.sh' server::team_r_start = '/home/joao/robocup/runner_workdir/b.sh' CSVSaver::save='true' CSVSaver::filename = 'out.csv' (in the output after "runnning: ") it works fine.
You can use eval to execute a string:
eval $illcommando
your_command_string="..."
output=$(eval "$your_command_string")
echo "$output"
I usually place commands in parentheses $(commandStr), if that doesn't help I find bash debug mode great, run the script as bash -x script
don't put your commands in variables, just run it
matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"
PWD=$(pwd)
teamAComm="$PWD/a.sh"
teamBComm="$PWD/b.sh"
include="$PWD/server_official.conf"
serverbin='/usr/local/bin/rcssserver'
cd $matchdir
$serverbin include=$include server::team_l_start = ${teamAComm} server::team_r_start=${teamBComm} CSVSaver::save='true' CSVSaver::filename = 'out.csv'
./me casts raise_dead()
I was looking for something like this, but I also needed to reuse the same string minus two parameters so I ended up with something like:
my_exe ()
{
mysql -sN -e "select $1 from heat.stack where heat.stack.name=\"$2\";"
}
This is something I use to monitor openstack heat stack creation. In this case I expect two conditions, an action 'CREATE' and a status 'COMPLETE' on a stack named "Somestack"
To get those variables I can do something like:
ACTION=$(my_exe action Somestack)
STATUS=$(my_exe status Somestack)
if [[ "$ACTION" == "CREATE" ]] && [[ "$STATUS" == "COMPLETE" ]]
...
Here is my gradle build script that executes strings stored in heredocs:
current_directory=$( realpath "." )
GENERATED=${current_directory}/"GENERATED"
build_gradle=$( realpath build.gradle )
## touch because .gitignore ignores this folder:
touch $GENERATED
COPY_BUILD_FILE=$( cat <<COPY_BUILD_FILE_HEREDOC
cp
$build_gradle
$GENERATED/build.gradle
COPY_BUILD_FILE_HEREDOC
)
$COPY_BUILD_FILE
GRADLE_COMMAND=$( cat <<GRADLE_COMMAND_HEREDOC
gradle run
--build-file
$GENERATED/build.gradle
--gradle-user-home
$GENERATED
--no-daemon
GRADLE_COMMAND_HEREDOC
)
$GRADLE_COMMAND
The lone ")" are kind of ugly. But I have no clue how to fix that asthetic aspect.
To see all commands that are being executed by the script, add the -x flag to your shabang line, and execute the command normally:
#! /bin/bash -x
matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"
teamAComm="`pwd`/a.sh"
teamBComm="`pwd`/b.sh"
include="`pwd`/server_official.conf"
serverbin='/usr/local/bin/rcssserver'
cd $matchdir
$serverbin include="$include" server::team_l_start="${teamAComm}" server::team_r_start="${teamBComm}" CSVSaver::save='true' CSVSaver::filename='out.csv'
Then if you sometimes want to ignore the debug output, redirect stderr somewhere.
For me echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}'
was working fine but unable to store output of command into variable.
I had same issue I tried eval but didn't got output.
Here is answer for my problem:
cmd=$(echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}')
echo $cmd
My output is now 20200824

Resources