bash – Why in Linux the rights to run the file do not work?

I create a bash script in the user directory that, when executed, for example, shows the text "Hello world" At the same time, I want to be able to run it only me (the owner of the file) and my group's accounts, and everything else I could read. Consequently, I configure the rights through chmod, login as a user that does not belong to my group, I go to the directory with the file, I run it through sh and … it suddenly runs and shows "Hello world" in place of "Access denied". But how is this possible? Did I ban others from acting? What it is? What does that mean?

(user@localhost ~)$ ls -la *.sh
-rwxr-xr-- 1 user users 0 Feb 19 01:21 file.sh
(user@localhost ~)$ sh file.sh
Hello World
(user@localhost ~)$ groups
users wheel
(user@localhost ~)$ su - testu
Password: 
(testu@localhost ~)$ groups
testu
(testu@localhost ~)$ cd ../user
(testu@localhost user)$ sh file1.txt
Hello World```

bash – Optimizing my script that searches a large compressed file

I'm here again ! I would like to optimize my bash script to reduce the time spent on each cycle.
Basically what it does is:
– get information from a tsv
– use that information to search with awk in a file
– print the line and export it

My problems are:
1) the files are 60GB compressed files: I need software to unzip it (I'm really trying to unzip it, I'm not sure I have enough space)
2) It is long to investigate anyway

My ideas to improve it:

  1. 0) as stated, if possible I will decompress the file
  2. using GNU parallel with parallel -j 0
    ./extract_awk_reads_in_bam.sh ::: reads_id_and_pos.tsv
    but i'm not sure it works as expected? I am reducing the time for research from 36 min to 16, just a 2.5 factor? (I have 16 cores)

  3. I was thinking (but can it be redundant with GNU?) Split
    my list of information to search multiple files to start them
    parallel

  4. sort the bam file by reads name and exit awk after having
    found 2 matches (cannot be more than 2)

Here is the rest of my bash script, I'm really open to ideas to improve it, but I'm not sure I am a superstar in programming, so maybe it's simple to help. 🙂

My bash script:

#/!bin/bash
while IFS=$'t' read -r READ_ID_WH POS_HOTSPOT; do
echo "$(date -Iseconds) read id is : ${READ_ID_WH} with position ${POS_HOTSPOT}" >> /data/bismark2/reads_done_so_far.txt
echo "$(date -Iseconds) read id is : ${READ_ID_WH} with position ${POS_HOTSPOT}"
samtools view -@ 2 /data/bismark2/aligned_on_nDNA/bamfile.bam | awk -v read_id="$READ_ID_WH" -v pos_hotspot="$POS_HOTSPOT" '$1==read_id {printf $0 "t%stwh_genome",pos_hotspot}'| head -2 >> /data/bismark2/export_reads_mapped.tsv
done <"$1"

My tsv file has a format like:

READ_ABCDEFt1200

Thank you very much ++

bash: grep error only when creating a variable from results

I'm analyzing some json in bash. If I do this in a bash command prompt:

cat junk | grep -Po & # 39; "loc" :. *? [^ ] ", & # 39;

Returns:

"loc": "21.0393.105.7666",

But, if I do this to establish a variable with the results:

test = `garbage cat | grep -Po & # 39; "loc":. *? [^ ] ", & # 39;`

Returns:

grep: termination missing] for character class

For some reason, the variable encapsulation using {& # 39;} seems to trigger something with grep and my regular expression

Trash is a file with a bit of json from a query to http://ipinfo.io:

{"ip": "103.147.184.52", "city": "Cầu Diễn", "region": "Hanoi", "country": "VN", "loc": "21.0393,105.7666", "org": "AS135905 VIETNAM POSTS AND TELECOMMUNICATIONS GROUP", "time zone": "Asia / Ho_Chi_Minh", "readme": "https://ipinfo.io/missingauth"}

Is there something obvious that I'm missing?

bash – How to configure cpumask on boot 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

Y 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 looks good:
000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001

But /sys/bus/workqueue/devices/writeback/cpumask was overwritten to the default value:

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

Thought?

multi-thread – Run Bash scripts in parallel

I would like to run a script several times in more than 10 folders 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 I am not sure how to structure the arguments by folder number or something similar.

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

MySQL Server: 8.0.16 Commercial
OS: RHEL 7.5

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

Next 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}

It is assumed that this script inserts a row in a database table each time it is executed.

The following 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 in 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)' 

He inserted a row in the table, however, when I program this in crontab, and when crontab executes it, it throws me an error that is the following:

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 only choose the INSERT statement and execute it in the database, it is executed. If I simply choose the entire mysql command and execute it individually from the command line, it runs, the only problem is when I run 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)

dogs says

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

I have spent almost 3 days later without any progress.

How to run a background process, after getting a user entry in bash shell

#!/bin/bash
set -e

INPUT_NO_OF_PROCESS=$1
NO_OF_PROCESS="${INPUT_NO_OF_PROCESS:-1}"

#mkdir -p $DUMP_DIR
echo "Spawning processes=$NO_OF_PROCESS"


for i in $(seq 1 $NO_OF_PROCESS)
do
    # This command will expect a password and has to be spawned
    # into multiple processes after getting the password
    some_command_that_expects_password&
done

The bash script above cannot obtain the password, if it is started as a background process Y

Is there any way to get tickets and let the process go to the background?

if the command is true for X seconds, run the code in the bash shell script

I want an if statement to be executed only if the condition in the declaration is true for at least 3 consecutive seconds, how do I achieve it in the Linux Bash shell script? I haven't done it before, and I couldn't find anything specific searching on Google and would appreciate any help! I don't mean a loop that executes the condition x number of times, but a function that verifies the condition is true for at least x consecutive seconds / minutes before it executes a block of code.

thanks in advance

bash – Anyway, can I use the pattern in the previous command in this case?

HERE IS THE PATTERN

dialog box –keep-tite –title "WARNING!" –msgbox & # 39; THIS WRITTEN IS RUNNING UNDER SUDO MODE. WE HAVE NO LIABILITY FOR ANY DAMAGE DONE TO YOUR DEVICE FOR THIS WRITING! IF YOU UNDERSTAND THE RISKS AND STILL WANT TO CONTINUE, CLICK OK, YES WRITE THE WRITTEN WITH CTRL + Z & # 39; 20 30 | pv -qL 500

CAN I USE THE SAME PATTERN HERE ALSO IN THIS CASE (PART | pv -qL)

cmd = (dialog –keep-tite –menu "PLEASE SELECT YOUR GAME VERSION:" 22 76 16)
options = (1 "LINUX
2 "KALI"
3 "ANDROID"
4 "UBUNTU")
choices = $ ("$ {cmd (@)}" "$ {options (@)}" 2> & 1> / dev / tty)

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

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

ssh user @ hostname bash -s <"/ home / xxxx / devstop.sh"
It is not raising the question from the remote shell and exits to the source shell.

My script:

if ("$ account" -eq "0")
then
echo -e "$ {GREEN} The Tomcat server stopped successfully at & # 39; $ HOSTNAME & # 39; $ {NC}"
elif ($ account -gt "0")
then
echo -e "$ {RED} The Tomcat server did not stop at & # 39; $ HOSTNAME & # 39 ;, check it $ {NC}"
echo "Do you want to continue the entire tomcat server shutdown process in –date "
echo "Read the above and enter (Y / N) to continue or stop to cancel the shutdown processes: c"
read answer

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

if ("$ value" = "Y")
then
echo "Tomcat's remaining services are falling."
plus
echo "Tomcat services shutdown process canceled in & # 39; $ HOSTNAME".
output 1;
fi

fi

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

exit