Distribute bash script ‘silently’ to multiple macos machines

We want to deploy a script ‘silently’ across all mac machines in organization. We have created a bash script that will run using launchd agent. we need to deploy the launchd agent and script on all macos machines. some instructions are needed during installation:

• The bash script ‘script1’ should be added to folder “/Library”

• Read and execute permissions should be added. Manually it can be done by running the command: “sudo chmod 511 /library/script1”

• The Agent “com.script1.plist” should be added to folder “/Library/LaunchAgents”

• Permission should be updated : “sudo chmod 644 /Library/LaunchAgents/com.script1.plist”

Can you please advise how to package all of this and distribute on all machines silently?

Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so:

#!/usr/bin/env bash  script="path_to_python_script" N=16 # number of processors mkdir -p data/  for i in `seq 1 1 100`; do     for j in {1..100}; do     ((q=q%N)); ((q++==0)) && wait      if [ -e data/file_$  i-$  j.txt ]     then         echo "data/file_$  i-$  j.txt exists"     else         ($  script -args_1 $  i > data/file_$  i-$  j.txt ;         $  script -args_1 $  i -args_2 value -args_3 value >> data/file_$  i-$  j.txt) &         fi     done done 

However, I am wondering if this code follow common best practices of parallelization of for loops in Bash? Are there ways to improve the efficiency of this code?

Empty variables in termux’ bash

I want to perform a test: if a certain variable exists, is non-empty, and its value matches an existing directory, then “exists” should be outputted.

I did the following:

$   echo $  var  $   if [ -d $  var ]; then echo "exists"; fi exists 

I got “exist”, although I did not assign any value to $ var. Why did this happen, and how do I test this properly?

screenshot

Распарсить текст в bash

test-1.me:010203(tcp) 0 test-2.me:030201(tcp) 0 test-3.not.me:010203(udp) 256 test-4.maybe.me:030201(udp) 0 test-5.who.is.me:010203(tcp) 65280 test-6.me:030201(tcp) 65280 

Есть файл с примерно таким содержимым. Нужно как-то распарсить его, чтоб на выходе получить в одной строке через запятую всё, где нет в конце одного 0. То есть в данном конкретном случае будет RESULT IS: test-3.not.me:010203(udp),test-5.who.is.me:010203(tcp),test-6.me:030201(tcp).

Пока написал регулярку ^.*(?<!\s0{1})$ https://regex101.com/r/NkXFwP/1 которая почему-то работает на regex101, но не хочет в grep/egrep 🙂 Был бы признателен, если б мне подсказали решение с использованием sed/awk/join и т.п. стандартных утилит. Я бы мог сделать это на python, к примеру, но мне кажется, это то же самое что по гвозди отвёрткой забивать.

Ubuntu desktop with bash keyboard shortcuts

I’m looking to migrate from OS X to Ubuntu. I’m very used to bash keyboard shortcuts working throughout all applications (ctrl-a=start of like, ctrl-e, ctrl-d etc) as those work in many desktop applications on OS X.

Is there ready-made package/extension/desktop environment, that uses bash keyboard shortcuts throughout, while moving ‘linux desktop’ shotcuts like ctrl-a=select all to other keys? (Like alt-a?)

Can’t cd to a (passed) variable in bash script

I am using bash to get some information from audacious to conky for display (including album art). I get the path to the directory of the music file from audacious, then attempt to cd to that directory to find folder.jpg – if found, prepare for display. Unfortunately can’t rely on ‘well-formed’ path names. None of them have a problem from terminal, but the evaluations that bash does… It chokes on doubled spaces ( ) ‘ / and probably others, although the current setup seems to handle – ok. Here’s the relevant function:

     GetArt ()         {         file_path=`audtool --current-song-tuple-data file-path` # get the path to the song         file_path=$  (eval echo "$  {file_path}")                   # pre-expand to full path         cd "$  {file_path}"         if [[ ! -e "folder.jpg" ]];                             # if no art work found             then             cp ~/Work/vinyl.png /tmp/cover.png              # put in placeholder         else             convert "$  {file_path}""/folder.jpg" -resize 120x120 /tmp/cover.png # ready for showing         fi         } 

Any ideas, or would getting out the wire brush and removing the rust from my ‘C’ compiler be easier?

I tried with double quotes, single quotes, backticks, and even a construct like:

code=$  code \"$  filename\"" 

but nothing seems to work correctly as yet. Fortunately it fails ‘pretty’ because it just pops up the “can’t find art” substitute pic instead, but sometimes things burp all over stderr until the next song – or album.

Thanks

Параллельное выполение команд в bash

Прошу помощи. Есть большое количество текстовых файлов расположенных в нескольких подкаталогах каталога data. Есть текстовый файл содержащий ~200 строк. Задача найти все строки из этого файла в файлах расположенных в каталоге data. Вот такая конструкция решает вопрос, но ужасно медленно (по 10 минут на каждую строку, а их порядка 200)

#! /bin/bash/ readarray -t LINES < file.lst     for i in "$  {!LINES[@]}"; do     grep -r -i "$  {LINES[i]}" /home/data/     echo "$  {LINES[i]}"  done 

Попытка добавить & в конеце строки с grep

#! /bin/bash/ readarray -t LINES < file.lst     for i in "$  {!LINES[@]}"; do     grep -r -i "$  {LINES[i]}" /home/data/ &     echo "$  {LINES[i]}"  done 

для запуска всех процессов параллельно приводит к некорректной работе скрипта.

Подскажите, как ускорить этот процесс?

I need to learn how to create an bash script with the following parameters [on hold]

I need to create a document with the following parameters:

  • the file needs to start with the following parameters:

    IT BLOG  - ACCESS TO THE PRIMARY COMPUTER INFRASTRUCTURE 
  • the following text needs to be present 15000 times in the file starting from line 2

    TIME Y DATE:__________________________________________________________________ NAME:_________________________________________________________________________ REASON:_______________________________________________________________________ LENGTH:_______________________________________________________________________ TIME AND DATE OF THE RESOLUTION:______________________________________________ AUTHORIZED BY:________________________________________________________________ DEPARTMENT:___________________________________________________________________  COMMENTS:_____________________________________________________________________ ______________________________________________________________________________ _______________________________________________________________________________ ---------------------------------END OF THE REGISTRY------------------------------- 
  • the file needs to finish with the following line

    -------------------THE BLOG FINISHES ON THE 15002 LINES--------- 

The file needs to be saved on .REG format

Bash script to restart systemd unit ran as a cron job repeats indefinitely

I have a quick and dirty bash script to restart a running Minecraft server by passing some announcement messages to the screen instance running it and then restarting the systemd unit:

#!/bin/bash screen -p 0 -S minecraft -X eval 'stuff "say Automated server restart in 60 seconds."\015' sleep 30 screen -p 0 -S minecraft -X eval 'stuff "say Automated server restart in 30 seconds."\015' sleep 20 screen -p 0 -S minecraft -X eval 'stuff "say Automated server restart in 10 seconds."\015' sleep 5 screen -p 0 -S minecraft -X eval 'stuff "say Restarting server! We'"'"'ll be back shortly."\015' sleep 5 systemctl --user restart minecraft 

This script works as expected when ran outside cron, but when I create a cron job like this, the script will fail to restart the server, and will instead repeatedly send the announcement messages to the screen instance over and over again:

* 7 * * * /bin/bash /home/mine/minecraft/restartserver.sh 1> /home/mine/minecraft/restart_log.txt 2> /home/mine/minecraft/restart_err.txt 

What could be going on here? My best guess is that the systemctl command must be failing somehow, which causes cron to re-run the script from the top. This is a server running Debian 9.