How can I retrieve just the 'position' value from the 'SHOW MASTER STATUS' query expression in MariaDB(running in docker container) from outside the docker container ?
Something like, I have the following :-
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 | 375 | | |
+-------------------+----------+--------------+------------------+
and need to get only value of position using bash script ?
Please help as soon as possible.
When MariaDB running inside docker container and want to retrieve File and Position Value from "SHOW MASTER STATUS" in MariaDB/MySQL from outside the docker container, use the following command in bash :-
for File
docker exec -it <mariadb_container_name> bash -c "mysql -u<username> -p<password> -Ne 'show master status' | awk '{print $1}' | cut -f1"
for Position
docker exec -it <mariadb_container_name> bash -c "mysql -u<username> -p<password> -Ne 'show master status' | awk '{print $2}' | cut -f2"
Related
Basically the title. I've noticed recently that some of our processes are hitting an error during server start up which causes them to stop, and which pm2 does not restart them from automatically. Running pm2 restart \process name\ brings them back. As a stop gap measure while I investigate the root cause, I would like to setup a script to use pm2 restart on only stopped processes, to be used on server reboot. So far, I've been able to extract a list of the stopped processes and there status:
pm2 ls | grep "stopped" | grep "process"
However, after this, I'm not sure how to proceed with using pm2 restart on the processes. Will I have to extract the process names into a list and loop through it, or is there a better way to do this?
You can use the next command line:
pm2 ls | grep "stopped" | grep "process" | awk '{print $4}' | xargs -I{} pm2 start {}
pm2 ls gets the list of all processes.
grep "stopped" | grep "process" filters all lines that has stopped word and the all lines that has process word.
awk '{print $4}' gets the fourth column per line, having that the format for each line this:
| 20 | process_name | ...
^ ^ ^ ^ ^
1 2 3 4 5 ...
xargs -I{} pm2 start {} gets each result line and pass them to pm2 start command.
I have file in different server and that name will change.
File: testfile-1.2-12345.sh ,"12345" is going to change.
How I get chancing text to variable?
In server machine this works and it's prints 12345:
ls ~/test/testfile* | awk -F'[-.s]' '{print $5}'
But when I do it from jenkins it wont work:
def versio = sh "ssh user#${ip} ls ~/test/testfile* | awk -F'[-.s]' '{print \$5}'"
It prints "12345" but if I try to print ${versio} it shows null.
Your command is correct. But in pipeline you need to specify returnStdout:true. Detailed documentation is here.
def versio = sh returnStdout: true, script: 'ssh user#${ip} ls ~/test/testfile* | awk -F\'[-.s]\' \'{print \\$5}\''
Im trying to expose a service that is on my local to a docker network. In order to do so, i need to export the result of this command:
ip route show | grep docker0 | awk '{print \$9}'
Here is what my gradle task looks like
task exportEnvVariables( type:Exec ) {
executable "sh"
args "-c", "export", "HOST_IP=\$(ip route show | grep docker0 | awk '{print \$9}')"
/* Have also tried:
commandLine 'export HOST_IP=$(ip route show | grep docker0 | awk \'{print $9}\')' */
println System.getenv( "HOST_IP" )
}
Your current approach cannot work, simply because you try to read the environment variable before you export it.
Whatever you put inside a task closure is executed during configuration phase (e.g. your println statement), while the actual task action is executed during execution phase.
You can use a doLast closure to execute a statement during execution phase:
task exportEnvVariables( type:Exec ) {
executable "sh"
args "-c", "export", "HOST_IP=\$(ip route show | grep docker0 | awk '{print \$9}')"
/* Have also tried: commandLine 'export HOST_IP=$(ip route show | grep docker0 | awk \'{print $9}\')' */
doLast {
println System.getenv( "HOST_IP" )
}
}
I am having trouble with command output formatting.
In terminal this works nicely:
df | grep sda1 | head -c33 | tail -c7 | tr -d " "
In genmon, I get only numbers such as "1145944":
SDAFREE=$(df | grep sda1 | head -c33 | tail -c7 | tr -d " ")
echo="$SDAFREE"
How do I print that command's output through genmon to xfce panel correctly (same as in terminal)?
Thank you.
I have the same issue with every command with a pipe. As a workaround I put the command in a executable script and run the script in genmon.
BTW:
if you want just one value of a table, you can use awk instead of head, tail and tr:
df | awk '/sda1/ {print $4}'
Docker caching is not yet available on travis: https://github.com/travis-ci/travis-ci/issues/5358
I'm trying to write a workaround by doing:
`docker save -o file.tar $(docker history -q image_name | grep -v missing)`
`docker load -i file.tar
Which works great, gives me all the image layers back. My only problem now is the saving takes a long time, and most of the time I'm actually changing one layer, so I don't need to rewrite all the rest. Is there a way of telling the docker save command to skip layers already in file.tar?
In the manifest.json file inside the tar you have the information you need.
tar -xOf file.tar manifest.json
Check the value of the Config keys. The first 12 characters are the image id. You can use the command above, extract the image ids that you already have, and exclude them in your docker save command.
I'm not very good with bash scripting, but this works on my mac
tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
Using this outputs everything
docker history -q IMAGE_HERE | grep -v missing && tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
After this you only need to get the unique values. This could be done with sort and uniq -u, but for some reason, sort doesn't work as expected. This command assumes the presence of file.tar so take that into consideration too.
I couldn't find anything about append in the docker save command. The above strategy could work with multiple file tars that are all different with each other.