scripting

SSH session termination on script error when sourcing multiple sub-scripts

SSH session termination on script error when sourcing multiple sub-scripts I’m facing an issue with SSH on a server. Running individual scripts (source s01.sh, etc.) works fine, with errors displayed in the console. However, when using a master script to source these scripts, the SSH connection unexpectedly terminates upon encountering an error. The master script …

Total answers: 1

I'd like to batch copy files in an special way – Do I need a script?

I'd like to batch copy files in an special way – Do I need a script? I’ve been using Linux for a few years now, but I’m not very familiar with the console. I can manage simple copy commands, but now I have a requirement that is beyond my knowledge. I have a large number …

Total answers: 2

Get current directory of last tmux pane

Get current directory of last tmux pane I’m looking for a tmux command to obtain the current directory (#{pane_current_path}) of the last focused pane, that doesn’t require switching to it and switching back. The following works: tmux last-pane echo "$(tmux display-message -pF "#{pane_current_path}")" tmux last-pane however I was wondering if there is a way to …

Total answers: 1

Logging sum of Mem and Swap from free command output

Logging sum of Mem and Swap from free command output In relation to this: https://unix.stackexchange.com/a/754252/582781 Solution 1: free -g -s2 | sed -u -n ‘s/^Mem:s+[0-9]+s+([0-9]+)s.+/1/p’ >> memory.log Is there a way to add Swap to this, so that I would log the sum of used Mem and Swap? Asked By: Aleksander || Source Using AWK: …

Total answers: 1

sudo to an interactive shell without password

sudo to an interactive shell without password I know questions similar to this have been asked, but I haven’t seen this exact situation answered (though feel free to close if it is indeed a duplicate). I am on a corporate network, so I do not have access to modify the /etc/sudoers file. We use sudo …

Total answers: 1

How to stop background jobs in subshell with infinite loop?

How to stop background jobs in subshell with infinite loop? In my tmux session over SSH, I ran: ( ( while true; do echo subsubshell1 && sleep 5; done ) & ( while true; do echo subsubshell2 && sleep 10; done ) & wait; ) How can I stop both background jobs without rebooting? I …

Total answers: 1

Change hostname with a variable with for loop

Change hostname with a variable with for loop I am trying to change the "hostname –transient" to some computers with a for loop using a variable. I want it to collect the "hostname -f" from the server itself and, using the variable, change it automatically. When I run it, it tells me "Invalid number of …

Total answers: 1

Change behavior of bash script if executed from another script

Change behavior of bash script if executed from another script I have a script (say Task.sh) (with executable permission): Pseducode: if [[ Not called from inside a script ]]; then echo ‘Not called from inside a script’ else echo ‘Called from a script’ fi I have a script say Main.sh (with executable permission): Value=$(Task.sh) echo …

Total answers: 2

Force Patch character differences to a file

Force Patch character differences to a file Hello, I have an englishStrings.json file and when I make new edits/ additions to it, I need to copy the new changes to all the other language string.json files. Before making any changes to englishStrings, the englishStrings and otherLanguageStrings have the same keys and same number of lines …

Total answers: 1

Does `return 0` equal `true` (in sourced script to shell's environment)?

Does `return 0` equal `true` (in sourced script to shell's environment)? I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as it returns true or false status to the …

Total answers: 3

How to make the (N) patterns of the zsh eatable by bash?

How to make the (N) patterns of the zsh eatable by bash? I am trying to develop a script which runs (and, ideally, does the same 🙂 ) in zsh and Bash. Problem is, that at a point, the zsh-specific part contains a pattern ending with (N). So: this_pattern*(N). In zsh, that makes the pattern …

Total answers: 2

Looking for a more permissive alternative to GNU getopt for wrapper script

Looking for a more permissive alternative to GNU getopt for wrapper script I often find myself writing shell functions or shell scripts that are meant to be wrappers around other commands. It is also frequent that I want such a wrapper to support a few flags/options. The idea is that the wrapper should cull from …

Total answers: 1

Is it a good idea to put "export BASH_ENV=~/.bashrc" in my .bashrc?

Is it a good idea to put "export BASH_ENV=~/.bashrc" in my .bashrc? Let’s say my Bash has some extensive ~/.bashrc customization that aids me not only in interactive use, but also in scripting (aliases, functions, variables, etc.). I would like to have this available to all my scripts, so I was thinking of setting BASH_ENV …

Total answers: 1

endless loop in until loop for unix script

endless loop in until loop for unix script I am doing a unix script using until loop.The idea of my script is it need to continuously verify the url status whether is up or down.When its up, it will exit the loop. In my script, I will use curl for check the url status and …

Total answers: 1

Update crontab rules without overwriting or duplicating

Update crontab rules without overwriting or duplicating I’m trying to figure out a good solution to the following problem: crontab contains some default rules (A,B,C) I have a setup.sh script that should append rules from a file my.cron to crontab (suppose rules X,Y,Z). The resulting rules should be A,B,C,X,Y,Z I cannot use crontab my.cron as …

Total answers: 6

Automatically resize rofi menu height

Automatically resize rofi menu height I want rofi to automatically resize menu’s height to the number of available options. There is an option -lines but with it I could only pass constant number. So for each call I’m forced to execute command twice – to calculate number of lines and to display menu: #!/usr/bin/sh lines=$(my_command …

Total answers: 1

Copy multiple files by filenames in subdirectories in linux

Copy multiple files by filenames in subdirectories in linux I can do the following to copy a file from subdirectories. find . -name "file1.txt" -type f -exec cp {} ./distfolder ; How do I change this code to copy multiple files (file1.txt, file5.txt, file6.txt) by their names from subdirectories? Simply doing find . -name "file1.txt, …

Total answers: 1

Combine rows based on shared elements (bash/awk)

Combine rows based on shared elements (bash/awk) I have a following file: a3 v2c v5 a7 a9 v2c v1c a3 a7c Desired output (without duplicates in each row): a3 a7c a9 v1c v2c a7 v5 What I want is to combine the rows sharing at least one element. In line 2, both elements are unique …

Total answers: 2

i3blocks.conf Error could not parse JSON lexical error

i3blocks.conf Error could not parse JSON lexical error I have this error in my /etc/i3blocks.conf Error: Could not parse JSON (lexical error: invalid bytes in UTF8 string.) My code in /etc/i3blocks.conf looks like this. [rss] command=rsstail -n1 -1 -N -u https://stackexchange.com/feeds/questions | head -c 50 color=#00FF00 interval=300 [rss] command=rsstail -n1 -1 -N -u https://unix.stackexchange.com/feeds | …

Total answers: 1