scripting

SIGTSTP(Ctrl-Z) not working for script started by script command

SIGTSTP(Ctrl-Z) not working for script started by script command Note: script refers to the script command, which logs stdin and¬†stdout to files. I was trying to run a script with the¬†script utility to save output for later inspection while preserving text colors on terminal. When I try to suspend the current script with Ctrl+Z (SIGTSTP), …

Total answers: 1

Script to select which result/value to be copied to a text file using AWK

Script to select which result/value to be copied to a text file using AWK Can someone help me with the last step in my bash script. You helped me already getting this far. #!/bin/bash find . -type f -name ‘*.mp4’ -o -name ‘*.mkv’ -o -name ‘*.avi’ -o -name ‘*.mov’ | while read -r file do …

Total answers: 2

How to source environment variable in command line with && combiner?

How to source environment variable in command line with && combiner? For a NodeJs app, I wrote the following script to deploy the app: "scripts": { "deploy": "source private/create_env.sh && ./deploy.sh", } private/create_env.sh creates environment variables that are used in the deploy.sh script. export USERNAME=alphonsio export SERVER=ftp.example.com export … The && combiner prevent the environment …

Total answers: 2

openssl connect in a script

openssl connect in a script I’m using openssl s_client -connect to extract the dates from a cert. I want to integrate it into a bash script, the problem is that the command opens the connection to the server and waits for the input, making it not suitable for a noninteractive approach. Any suggestions or alternatives? …

Total answers: 1

Zsh: What is the idiomatic way of terminating lines in a script? (semicolon, new-line)

Zsh: What is the idiomatic way of terminating lines in a script? (semicolon, new-line) I’m fairly comfortable with putting semicolons, newlines and ampersands where they’re needed. But what is the "correct" way? Is it just a matter of style/personal preference, or is one in some way better than the other? while true; do cmd1 cmd2 …

Total answers: 1

Extracting strings from (BASIC) file

Extracting strings from (BASIC) file I am trying to extract all of the strings (in the order in which they appear), from a BASIC listing for Taipan. However, I also want the delimiting " (at the start and end of the strings) to also appear in the output as some of the strings have spaces …

Total answers: 3

Command-line tool enabling tagging and related tags functionality

Command-line tool enabling tagging and related tags functionality Is there a command-line tool that enables to give a file more attributes than a name? For example, we have a file called ubuntu.pdf and we give it tags like command-line, shell, nautilus, my_favourite_stuff, whatever_else and a file linux.pdf with tags shell, command-line, ln, best_book and than …

Total answers: 2

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