shell-script

Two ssh output as awk input

Two ssh output as awk input I have two remote servers that I am trying to ssh and cat some files.. I want to input the output of the ssh to a awk command. This is what I have got ssh username@host1 “cat /tmp/test/*” ssh username@host2 “cat /tmp/test/*” | awk ‘ command ‘ But this …

Total answers: 3

Create new CSV files based on latest timestamp data

Create new CSV files based on latest timestamp data I have a script that accesses multiple dat files and produce csv files based on previous day’s data. these DAT files are updated on per minute bases with data from various instruments. Script snippet: gawk -F, ‘ { gsub(/"/,"") } FNR==2{ delete timestamp; #This code was …

Total answers: 1

Cut command stored in variable will not work

Cut command stored in variable will not work Can someone explain why I cannot store the cut command in a variable?? user:~$ echo "foo bii doo" | cut -d ‘ ‘ -f 2 bii # as expected # now put cut command into a variable: user:~$ c="cut -d ‘ ‘ -f 2" user:~$ echo "foo …

Total answers: 1

Whats the meaning of this sed command sed '/^[[:space:]]*$/d'

Whats the meaning of this sed command sed '/^[[:space:]]*$/d' I came across this sed command in a script to compare a machine’s local binaries to GTFObins binaries. for i in $(curl -s https://gtfobins.github.io/ | html2text | cut -d" " -f1 | sed ‘/^[[:space:]]*$/d’); do if grep -q "$i" installed_pkgs.list; then echo "Check GTFO for: $i"; …

Total answers: 1

How to referencing $@ without pass it in bash function?

How to referencing $@ without pass it in bash function? I wants to know how can I reference the $@ from another function or another script file without pass it just like what getopts do. Thank you very much! # previous question : How bash getopts get to know what arguments the call has A() …

Total answers: 3

How bash getopts knows what arguments the call has

How bash getopts knows what arguments the call has If getopts is a bash function, by my understanding, you need to pass $@ – the whole arguments to getopts to let the function know what kind of arguments you have in order to proceed, right? It seems to me that you don’t need it, so …

Total answers: 1

How to stop redirection via exec

How to stop redirection via exec I want to redirect some output of a script to a file. REDIRECT_FILE="foo.txt" echo to console # starting redirect exec > $REDIRECT_FILE echo to file echo … echo … # stop redirect exec >&- echo end of script "end of script" should be written to stdout. But instead there …

Total answers: 1

How to convert all newlines to "n" in POSIX sh strings

How to convert all newlines to "n" in POSIX sh strings I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "n". How can I do this in POSIX sh? Here’s the goal: $ printf ‘anbncnd’ | …

Total answers: 1

Delete lines below, excluding the line with match pattern

Delete lines below, excluding the line with match pattern One can use sed ‘/pattern/Q’ or sed ‘/pattern/,$d’ to delete lines below a match pattern, but it also deletes the line containing the match pattern. How to exclude the line containing the match pattern, and only delete the lines below it? Asked By: Sadi || Source …

Total answers: 5

Why does a backslash at the end of the line place undue whitespace?

Why does a backslash at the end of the line place undue whitespace? I wanted: #!/bin/bash cmd –options option=value, option=value, option=value, option=value But running with bash -x I got: cmd –options option=value, option=value, option=value, option=value That causes an error. How can I do this so bash doesn’t automatically place this blank space? Asked By: rhuanpk …

Total answers: 4

Shell script output/logging question

Shell script output/logging question I have a shell script that does a lot of work and pretty close to the top I have this: if [[ -r "${SCRIPT_BASE_DIR}/etc/logging.properties" ]] && [[ -s "${SCRIPT_BASE_DIR}/etc/logging.properties" ]]; then source "${SCRIPT_BASE_DIR}/etc/logging.properties" fi if [[ -r "/usr/local/lib/logger.sh" ]] && [[ -s "/usr/local/lib/logger.sh" ]] && [[ -n "${LOGGING_LOADED}" ]] && [[ …

Total answers: 1

math problem or variable value problem im not sure

math problem or variable value problem im not sure I am having an issue comparing epoch times. I’m really not sure what I’m doing wrong. I have been tasked with identifying and actioning files beyond and during certain date ranges. In this case, it’s a cleanup script. It takes a few parameters to do the …

Total answers: 2

A && B || C vs if then else fi

A && B || C vs if then else fi Stéphane commented that A && B || C cannot be used in place of proper if then else fi Can someone explain what’s the difference? Asked By: Tom Huntington || Source It is very easy to make a mistake in cases like A && B …

Total answers: 1

File backed, key value store implemented with posix utilities

File backed, key value store implemented with posix utilities I imagine this is a pretty common thing to do. Which posix utility for reads, which for writes? What are the most common file formats to do this with? Is inplace modification possible? My first thought was to use json and jq, but I’m interested in …

Total answers: 1

How to pass the standard input of a shell script to a background command

How to pass the standard input of a shell script to a background command In a shell script, I am trying to start a background command that has the same stdin as that of the shell script. #!/bin/sh # … the-program & However, the-program above will not have access to the same standard input as …

Total answers: 1

Unable to grep foreign language in shell script

Unable to grep foreign language in shell script I am a newbie in shell scripting, I have a text which contain text in following format:- "some foreign language",’corresponding ID to text’ for example:- "Назад",IDC_SSB_DLG_BACK_BTN I need to find the text related to ID and save in in text file. Here my sample script:- #!/bin/sh target_file=$1 …

Total answers: 2

Escape special characters from variables

Escape special characters from variables I have #!/usr/bin/bash search="ldo_vrf18 {" replace="$search"’ compatible = "regulator-fixed"; regulator-name = "vrf18"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-enable-ramp-delay = <120>;’ sed -i "s/$search/$replace/g" output.file The result is sed: -e expression #1, char 62: unterminated `s’ command I suspect some values arent being escape in replace. Is there a way …

Total answers: 1

How to get both the number of bytes and the sha1sum with single pass?

How to get both the number of bytes and the sha1sum with single pass? I want to get both the number of bytes and the sha1sum of a command’s output. In principle, one can always do something like: BYTES="$( somecommand | wc -c )" DIGEST="$( somecommand | sha1sum | sed ‘s/ .*//’ )" …but, for …

Total answers: 2

Select, Case in if-else statement requires double inputs

Select, Case in if-else statement requires double inputs I need to find out where is the problem. I need to write a script that prompts users to make Yes/No choice in if/else statement. In general I have a bash script that runs like this if CONDITION; then COMMANDS1 else COMMANDS2 echo "Does this look okay …

Total answers: 1