bash – How to configure cpumask at startup with systemd?

I have the following service:

[Unit]
Description=foo

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/opt/script/bar.sh

[Install]
WantedBy=multi-user.target

And bar.sh:

#!/bin/bash
echo 1 > /sys/bus/workqueue/devices/writeback/cpumask
cat /sys/bus/workqueue/devices/writeback/cpumask > /tmp/writeback

Then after restarting, cat /tmp/writeback This seems good:
000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001

But /sys/bus/workqueue/devices/writeback/cpumask has been replaced by default:

ffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff,ffffffff

Thought?

multithreading – Run Bash scripts in parallel

I would like to execute a script several times on 10 files in parallel. What I need to know is how to structure the arguments by number. My non-parallel script is:

For i in {1..10};
    do python myscript.py "folder_"$i;
done;

I have heard of mpirun but am not sure how to structure the arguments by file number or something similar.

linux – MySQL ERROR 1064 (42000) insert via bash script (RHEL)

MySQL server: 8.0.16 Commercial
Operating system: RHEL 7.5

I wrote a simple script, to insert certain information into a database table.

Here is my script

# cat ~mysqldba/bin/connections.sh

   #!/bin/bash

log_file=~mysqldba/stats/connections_info.log


threads_connected=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf  -e "show global status like 'threads_connected';" | tr -d "| " | egrep -iv 'variable_name' | awk -F " " '{ print $2 }'`
echo "Number of open connections are ${threads_connected}." >> ${connections} 

threads_running=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e "show global status like 'threads_running';" | tr -d "| " | egrep -iv 'variable_name' | awk -F " " '{ print $2 }'`
echo "Number of connections that are not sleeping out of ${threads_connected} are ${threads_running}." >> ${connections} 

app1=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e "select host from information_schema.processlist;" | grep 'ip-address1'| wc -l`

sleep_app1=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e "select host from information_schema.processlist where command like 'sleep';" | grep 'ip-address1'|wc -l`

app2=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e "select host from information_schema.processlist;" | grep 'ip-address2'| wc -l`

sleep_app2=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e "select host from information_schema.processlist where command like 'sleep';" | grep 'ip-address2'|wc -l`

max_used_connections=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf  -e "show global status like 'max_used_connections';" | tr -d "| " | egrep -iv 'variable_name' | awk -F " " '{ print $2 }'`

max_used_connections_time=`/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf  -e "show global status like 'max_used_connections_time';" | tr -d "| " | egrep -iv 'variable_name' | awk -F " " '{ print $2 }'`

idle=`mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e "select count(*) from information_schema.processlist where command='sleep';" | grep -v '+'`

/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e "insert into backup_info.connection_info (serial_no, run_date, run_time, total_number_of_connections, number_of_running_connections, no_of_connections_from_app27, no_of_sleeping_from_app27, no_of_connections_from_app28, no_of_sleeping_from_app28, max_used_connections, number_of_idle_connections) values (0, curdate(), curtime(), ${threads_connected}, ${threads_running}, ${app1}, ${sleep_app1}, ${app2}, ${sleep_app2}, ${max_used_connections}, ${idle})" 2>> ${log_file}

This script is supposed to insert a row in a database table each time it is run.

Here is the database table:

CREATE TABLE `connection_info` (
  `SERIAL_NO` mediumint(9) NOT NULL AUTO_INCREMENT,
  `run_date` date DEFAULT NULL,
  `run_time` time DEFAULT NULL,
  `TOTAL_NUMBER_OF_CONNECTIONS` mediumint(9) DEFAULT NULL,
  `NUMBER_OF_RUNNING_CONNECTIONS` mediumint(9) DEFAULT NULL,
  `NO_OF_CONNECTIONS_FROM_APP1` mediumint(9) DEFAULT NULL,
  `NO_OF_SLEEPING_FROM_APP1` mediumint(9) DEFAULT NULL,
  `NO_OF_CONNECTIONS_FROM_APP2` mediumint(9) DEFAULT NULL,
  `NO_OF_SLEEPING_FROM_APP2` mediumint(9) DEFAULT NULL,
  `MAX_USED_CONNECTIONS` mediumint(9) DEFAULT NULL,
  `NUMBER_OF_IDLE_CONNECTIONS` mediumint(9) DEFAULT NULL,
  PRIMARY KEY (`SERIAL_NO`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPRESSED

When I run the script, it runs correctly and inserts a row into the table.

    # sh -x ~mysqldba/bin/connections.sh
+ log_file=/home/mysqldba/stats/connections_info.log
++ date +%F_%T
+ echo '--------##### -------- 2020-02-14_13:04:16 -------- #####-------'
+ echo '--------##### ------------------------------------------ #####-------'
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'show global status like '''threads_connected''';'
++ tr -d '| '
++ egrep -iv variable_name
++ awk -F ' ' '{ print $2 }'
+ threads_connected=271
+ echo 'Number of open connections are 271.'
/home/mysqldba/bin/connections.sh: line 17: ${connections}: ambiguous redirect
++ tr -d '| '
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'show global status like '''threads_running''';'
++ egrep -iv variable_name
++ awk -F ' ' '{ print $2 }'
+ threads_running=3
+ echo 'Number of connections that are not sleeping out of 271 are 3.'
/home/mysqldba/bin/connections.sh: line 20: ${connections}: ambiguous redirect
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e 'select host from information_schema.processlist;'
++ wc -l
++ grep ip-address1
+ app1=156
++ wc -l
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e 'select host from information_schema.processlist where command like '''sleep''';'
++ grep ip-address1
+ sleep_app1=156
++ grep ip-address2
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e 'select host from information_schema.processlist;'
++ wc -l
+ app2=107
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e 'select host from information_schema.processlist where command like '''sleep''';'
++ grep ip-address2
++ wc -l
+ sleep_app2=107
++ tr -d '| '
++ awk -F ' ' '{ print $2 }'
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'show global status like '''max_used_connections''';'
++ egrep -iv variable_name
+ max_used_connections=282
++ tr -d '| '
++ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'show global status like '''max_used_connections_time''';'
++ egrep -iv variable_name
++ awk -F ' ' '{ print $2 }'
+ max_used_connections_time=2020-02-1313:29:08
++ mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf --skip-column-names -e 'select count(*) from information_schema.processlist where command='''sleep''';'
++ grep -v +
+ idle=269
+ /mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'insert into backup_info.connection_info (serial_no, run_date, run_time, total_number_of_connections, number_of_running_connections, no_of_connections_from_app27, no_of_sleeping_from_app27, no_of_connections_from_app28, no_of_sleeping_from_app28, max_used_connections, number_of_idle_connections) values (0, curdate(), curtime(), 271, 3, 156, 156, 107, 107, 282, 269)' 

It has inserted a row in the table, however, when I schedule it in the crontab, and when crontab runs it, it throws me an error which is:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', , 158, 158, 106, 106, , )' at line 1

If I just choose the INSERT statement and execute it on the database, it executes. If I just choose the whole mysql command and execute it individually from the command line, it executes, the only problem is when I execute it from crontab.

/mysql_binaries/mysql/bin/mysql --defaults-extra-file=/mysql_data/config/extra_options.cnf -e 'insert into backup_info.connection_info (serial_no, run_date, run_time, total_number_of_connections, number_of_running_connections, no_of_connections_from_app27, no_of_sleeping_from_app27, no_of_connections_from_app28, no_of_sleeping_from_app28, max_used_connections, number_of_idle_connections) values (0, curdate(), curtime(), 271, 3, 156, 156, 107, 107, 282, 269)

Perros says

# perror 1064
MySQL error code MY-001064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d

I spent almost 3 days there without any progress.

linux – How do you automatically compare the size of two files using bash or zsh?

I want to write an optimizer for my shared documents using external tools. The idea is to process a file with a program, which will leave me a more or less small copy. I wish I could automatically compare the size of the two (input and output files), delete the larger one and keep the other.

Any clues on how to do it? Up to now I have been using

du -b

to know the size but I can't separate the number from the name.

I know it is possible to use

sed

for that but frankly I don't know where to start.

Sorry if the question is too general. Any suggestions to give you a better format are welcome.

linux – read response does not work on ssh bash -s script

I have a few commands to request a yes or no answer in my script, but the read answer command (interactive mode) does not work, when running the script using the ssh bash script -s.

ssh user @ hostname bash -s <"/ home / xxxx / devstop.sh"
it does not ask the question from the remote shell and quits the source shell.

My script:

if ("$ count" -eq "0")
then
echo -e "$ {GREEN} Tomcat Server successfully stopped on & # 39; $ HOSTNAME & # 39; $ {NC}"
elif ($ count -gt "0")
then
echo -e "$ {RED} The Tomcat server is not stopped on & # 39; $ HOSTNAME & # 39; please check it $ {NC}"
echo "Do you want to continue the whole process of stopping the tomcat server in –date "
echo "Please read the above and enter (Y / N) to continue or stop to cancel the stop processes: c"
read the answer

value =echo ${answer} | tr -s '(:lower:)' '(:upper:)'

if ("$ value" = "Y")
then
echo "The remaining Tomcat services are down."
other
echo "Tomcat service termination process canceled in & # 39; $ HOSTNAME."
outlet 1;
Fi

Fi

ps -ef | grep tomcat | grep -v grep | grep -i "catalina.startup.Bootstrap start"

exit

unix – Code Bash to install the bootstrap in a Ruby on Rails repository

Wrote code to install the bootstrap (the most recent) in a newly created rails application.

update: correction of a typo

yarn add bootstrap jquery popper.js expose-loader
yarn install --check-files
perl -pi.bak -e "s/extract_css: false/extract_css: true/" config/webpacker.yml
s1=$'nnimport "bootstrap/dist/js/bootstrap";'
echo "$s1" >> app/javascript/packs/application.js
echo '@import "~bootstrap/scss/bootstrap";' > app/javascript/packs/styles.scss
(gsed $'/module.exports = environment/{e cat expose-loader.txtn}' config/webpack/environment.js) > config/webpack/environment.js.new
mv config/webpack/environment.js.new config/webpack/environment.js
(gsed $'/javascript_pack_tag .application/{e cat stylesheet_pack_tag.txtn}' app/views/layouts/application.html.erb) > app/views/layouts/application.html.erb.new
mv app/views/layouts/application.html.erb.new app/views/layouts/application.html.erb

bash – Writing a systemd script that starts 2 applications on Linux

OS: Raspbian

I can't run 2 apps at once with rc.local

I need to find a simple example to start an application with systemd

The problem is that I only find specific examples to start servers and they are very complex, I have trouble understanding how to write a simple systemd file which runs an application, where to place it and how to start it.

The two applications that I am trying to run are: /home/pi/app1 and /home/pi/app2

When I run a command line like this: the two apps run simultaneously

/home/pi/app1 & /home/pi/app2 &

But for some reason, when I put the same line in rc.local, only the first application works,

I also can't seem to flush rc.local data

/home/pi/app1 & /home/pi/app2 &> /tmp/log this file / tmp / log is never created

I don't understand why it doesn't work, I was suggested to use systemd but it is so unnecessarily complicated with too many options.

What would a simple systemd file look like to run any of these applications?

I just want something reliable that will start these two apps on startup, that's it

Thank you

Shebang is it necessary in git bash scripts on Windows

Shebang is the first line of a bash script indicating where the bash script is executed. In Windows Git Bash scripts, is this necessary? If not why?

bash – why in linux, the size of the directory remained the same even after deleting its files and subdirectories?

why in linux, the size of the directory remained the same, even after deleting its files and subdirectories?
I created a vv1 directory and inside it created 500 files. ls -lrt showed size vv1 as 12288 as follows:

12 in total

drwxr-xr-x 2 cms ccsrm 12288 January 28 12:15 p.m. vv1

After deleting 500 files, it showed the same size

12 in total

drwxr-xr-x 2 cms ccsrm 12288 January 28 12:17 vv1

Why??

bash – ffmpeg batch script for video resizing

The only Bash feature we use is (( )) to test file properties. It is easy to replace (( -d $1 )) with ( -d "$1" ) and that allows us to stick to a standard shell, which is more portable and lighter:

#!/bin/sh

Most shellcheck results are due to not mentioning parameter extensions:

236052.sh:9:31: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:9:50: error: Delete trailing spaces after  to break line (or use quotes for literal space). (SC1101)
236052.sh:10:5: warning: This flag is used as a command name. Bad line break or missing ( .. )? (SC2215)
236052.sh:11:15: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:12:28: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:12:74: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:18:14: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:18:27: note: Expressions don't expand in single quotes, use double quotes for that. (SC2016)
236052.sh:18:53: note: Expressions don't expand in single quotes, use double quotes for that. (SC2016)
236052.sh:18:75: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:22:16: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:23:20: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:24:16: note: Double quote to prevent globbing and word splitting. (SC2086)
236052.sh:26:12: note: Double quote to prevent globbing and word splitting. (SC2086)

Ironically, you have citations in some places, they are not strictly necessary, so it is unclear why you missed it all.

echo "Argument missing"
exit 1

It should be:

echo >&2 "Argument missing"
exit 1

The test here is slightly wrong: the argument may be present, but not the name of an ordinary file or directory. So I would replace that with:

elif ( -e "$1" )
    echo "$1: not a plain file or directory" >&2
    exit 1
elif ( "$1" )
    echo "$1: file not found" >&2
    exit 1
else
    echo "Argument missing" >&2
    exit 1
fi

It may be useful to move these tests in the resize , because at the moment we assume that the content found in the directory arguments are simple files (that said, we cover a little corner with that, so I wouldn't sweat it – just let the commands fail there ).

In resize, if ffmpeg fails, there's no point in running exiftool, then connect them with &&. Also consider deleting the file if it was created with errors (so we are not fooled by partially written output thinking that this file does not need conversion).

There is no need for the file /tmp/fl_$timestamp: we could just use a pipeline there.

Instead of allowing only one argument (and ignoring everything except the first), let the user specify as many files as necessary; it’s easy to loop through them using for.


It is Shellcheck-clean, but I am not able to test it (it lacks the required directory of MPEG files).

#!/bin/sh

set -eu


status=true
fail() {
    echo "$@" >&2
    status=false
}

# Resize a single file
resize() {
    echo "Filename $1"
    filename=$(basename -- "$1")
    extension=${filename##*.}
    filename=${filename%.*}
    new_filename=${filename}.${timestamp}.${extension}
    if 
        ffmpeg -v quiet -stats -i "$1" -map_metadata 0 
               -vf scale=-1:720 -c:v libx264 -crf 23 
               -c:a copy "$new_filename" < /dev/null &&
            exiftool -TagsFromFile "$1" '-all:all>all:all' 
                     -overwrite_original "$new_filename"
    then
        # success
        true
    else
        # failed; destroy the evidence
        rm -f "$new_filename" 2>/dev/null
        fail "Failed to convert $1"
    fi
}

# Resize all *.mp4 files in a single directory
# N.B. only immediate contents; not recursive
resize_dir() {
    # shellcheck disable=SC2016
    exiftool "$1"/*.mp4 -if '$ImageHeight >= 1080' -p '$Filename' |
        while IFS= read -r line
        do
            resize "$line"
        done
}

( $# -gt 0 ) || fail "Usage: $0 FILE FILE..."

timestamp=$(date +%s)

for arg
do
    if ( -d "$arg" )
    then
        resize_dir "$arg"
    elif ( -f "$arg" )
    then
        resize "$arg"
    elif ( -e "$arg" )
    then
        fail "$arg: not a plain file or directory"
    else
        fail "$arg: file not found"
    fi
done

exec $status # true or false