Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

Filter by
Sorted by
Tagged with
0 votes
2 answers
81 views

Test for substring in posix shell .sh script (NOT bash)

I use an .sh script to read the installed firmware of a controller and to compare it with the available firmware (and update on the controller if needed). To make sure the readout works I want to test ...
Serakis's user avatar
  • 11
-1 votes
1 answer
85 views

Flag parameter in bash script misunderstood as file , “no such file or directory"

I’m writing a simple bash script named video2png, using the ffmpeg to turn certain frame of a video into png: #!/bin/bash ffmpeg -ss 30:00 -i "$1" -frames 1 -s 1280x880 -f image2 "$2&...
Wu Eureka's user avatar
0 votes
0 answers
26 views

how to use a remote ssh output as an input into a scp

I have a list of systems and I want to copy a log file out of many logs files , to my local machine which has a specific date of logs. for i in `cat serverlist`; do scp $i:$(grep -lR "2024-01-01 ...
user3038195's user avatar
0 votes
1 answer
25 views

Terminate batch job quietly

What signal code do I use with the kill command to terminate a background job quietly? Or perhaps an environment variable setting in the batch environment? Specifically, the "[1]+ Terminated ...
John-L_.'s user avatar
1 vote
1 answer
51 views

Bash parameter substitution with multi line error message

I'm using parameter substitution with an error message, such as ${var1:?'some message'}. I've incorporated a multi-line error message. Presently, it only functions properly when enclosed within single ...
programmer Erfan's user avatar
0 votes
1 answer
59 views

How to stop the while loop after four hours in shell script, if the file not found?

I am working on the ksh script where I am getting the file from the sftp server & copying to local & checking if the file is available there or not. I am running this on loop if the file is ...
ImSahil's user avatar
0 votes
0 answers
16 views

How can I get a legible name of a Flatpak application given its window ID?

I sort my screenshots into subfolders based on the program I'm screenshotting, so I need something more consistent than window name. I can use xdotool getactivewindow getwindowpid to get the PID of ...
 MiloWinslow 's user avatar
0 votes
0 answers
31 views

How can root get access to SSH_TTY

I think that SSH_TTY is an environment variable set by ssh that holds the device node of the current virtual terminal; e.g. /dev/pts/0, /dev/pts/1 , etc. I know that when I'm logged in to an SSH ...
Seamus's user avatar
  • 2,885
3 votes
1 answer
192 views

How to code defensively in Bash for unhandled runtime errors within logical expressions?

I just encountered an error where a function was missing in my script. I already trap and raise these exceptions to stop the script early, but I noticed that did not occur. Investigating this further, ...
Zhro's user avatar
  • 2,649
0 votes
1 answer
51 views

find with execdir, pipe redirection evaluated too early (quote issue?)

I use multiple GitHub accounts at work, so I need to modify the remote url to add my work account. I have figured out the recursive find -execdir, and how to get/sed/set the remote url, but I cannot ...
Robert Altman's user avatar
0 votes
1 answer
34 views

How to run snmpwalk using linux script

Basically i am new in the field of shell scripting and i want to run snmpwalk using linux script here is the script i have created: echo "Starting SnmpWalk" var = `snmpwalk -v2c CS IP 1.3....
Anubhav Kumar Panda's user avatar
0 votes
1 answer
51 views

Restoring bash prompt $PS1 to default

Is there a bash shell script or command that I can invoke to restore the original value to $PS1? I clobbered it without making a backup copy. If need be, I can always re-install bash, I'm hoping there ...
John-L_.'s user avatar
-1 votes
0 answers
55 views

Tcsh script for finding a corresponding value

I am trying to write a script to find out a pattern.  From a text file which has, let’s say, the following lines: Assertions Success: ...
suvash's user avatar
  • 1
0 votes
1 answer
41 views

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 ...
dejanualex's user avatar
0 votes
1 answer
34 views

How do I check if an IP-address or a network is contained in other network in BusyBox shell?

A BusyBox shell script has a list of IPs to be used as whitelist for a firewall ipset list. The whitelist may contain non routable IP's to be whitelisted. On the other hand firehol_level1 list (...
Pro Backup's user avatar
  • 4,894
1 vote
2 answers
49 views

Ensuring Distinguishable Exit Codes for Shell Scripts

Say I have two shell scripts, a.sh and b.sh, where a.sh calls b.sh somewhere inside. Then, say that b.sh could exit with exit codes 0, 1, or 2. What are some techniques that can be employed to ensure ...
Pacopenguin's user avatar
4 votes
2 answers
778 views

Combine two files as part of a command line parameter

I am trying to use csvgrep (part of csvkit) to extract rows matching one of two files. Unfortunately, there is no command line option that allows two matching files (like grep does). Only, csvgrep -f ...
Robert Altman's user avatar
0 votes
0 answers
24 views

Repeat a command with a variable taken from a file line by line [duplicate]

I am trying to retrieve a string of text from a file which exists on a bunch of remote servers. The servers all have a custom port number so I put those numbers in a file called "port_numbers.txt&...
trebuchet's user avatar
0 votes
0 answers
41 views

dhclient exit hook cannot write to directory

I am using RHEL 8.9 and have created a basic dhclient hook script in which I want to log to a file. The script is able to write to places like /tmp, but not /opt. It can read files from /opt, but not ...
trebor's user avatar
  • 101
0 votes
1 answer
45 views

How to detect if a process runs longer than X seconds, then do something with it?

I’m on debian. I am calling a ffmpeg process to generate a mp3. this gets called from a php script using shell_exec. This works fine 99% of the time. Sometimes, the ffmpeg process doesn’t exit and I’m ...
frumbert's user avatar
  • 115
2 votes
0 answers
71 views

Incorrect folder name created when using cp command in bash

I would like to copy a file from one location to another. When I use the cp command in a terminal it works well, for example I use the following command: cp -r projects/Test/ projects/Personal/ This ...
user601459's user avatar
0 votes
0 answers
24 views

Starting an application with a .desktop file right at system start: Why is it inactive after system start, requiring selection by alt + TAB?

All application startups set by GUI for current user sessions are stored as files at a certain place of per home directory: cd ~/.config/autostart Set an application to start up with every boot by ...
futurewave's user avatar
1 vote
1 answer
50 views

Bash script to open new terminal with path from current?

I am using zsh For example, i am in ~/Downloads, and want to run script, that will run new terminal with this path. What i did. work.sh #! /bin/bash current_path="$PWD" echo $current_path | ...
serii 's user avatar
  • 21
0 votes
0 answers
32 views

Output of python script like if it's typed in interactive mode

I have a python file and I want to obtain the output just like I'm typing the content in interactive mode (like this question https://stackoverflow.com/q/59008423 but with a shell script) I try with ...
Pablo Cárdenas's user avatar
0 votes
1 answer
48 views

How to hide a variable value when set -x is on

I need to use set -x in my script to show the executed commands in my log but there is a variable which is a password, so this password is showed in plan text Is there a way to hide only a variable? ...
Astora's user avatar
  • 429
2 votes
3 answers
732 views

Alternatives to file polling?

In the following code, I have to poll $tmp_input to continue executing the code because wezterm cli send-text is asynchronous. This makes sure that $tmp_input is ready. tmp_input=$(mktemp ./tmp_input....
wyc's user avatar
  • 133
0 votes
0 answers
41 views

How to gracefully handle differences in command options between different versions?

Inspired by What is the difference between “base64 -b0” in macOS versions prior to macOS 13 (Ventura) and “base64 -i” in macOS 13 (Ventura)? Are there common ways to avoid the script breaking on a ...
typo's user avatar
  • 229
0 votes
3 answers
80 views

If-else Parameter substitution

I'm running a series of experiments with bash and want to store the log files in a directory whose name is based on the experiment configuration. Some items in the configuration are boolean (true/...
Green绿色's user avatar
0 votes
1 answer
43 views

In zsh, Home, End, and Del behave differently inside a script than they do outside

I learned after much frustration that having $EDITOR initially set to vim doesn't affect the main shell but does affect scripts and nothing seems to undo this initial state. Unsetting the env var, ...
Walf's user avatar
  • 1,289
0 votes
0 answers
32 views

How do I execute a command but only add a *modified* version of it to the history?

I'm trying to create an analog of the command history, but for the output of the commands, so that I can do e.g. locate filename (which might display several files) and then vim %2 (or whatever) to ...
colinh's user avatar
  • 47
-2 votes
0 answers
39 views

Bash - declaring a variable: "" VS "0" - does it make any difference? [closed]

This is about coding style, maybe efficiency or security, I don't know… Imagine you're bash scripting. Following general best practice you have a set of variables as close to the beginning as ...
futurewave's user avatar
0 votes
0 answers
14 views

mount ext4 usb disk in /run/media/$USER/DISK-LABEL as user but not as root

I have found a couple of script using systemd to mount an usb disk. one udev script one systemd service script (which call the shell script passing the device name, the action to be done ) one shell ...
jcdole's user avatar
  • 1
-1 votes
4 answers
77 views

How to extract some part of the path in shell script?

I have a variable with path /usr/apps/app1/home/usera/run/10/_tmp/folder1/folder1. How can I extract /usr/apps/app1/home/usera/run/10/_tmp in shell script?
noonenine's user avatar
0 votes
2 answers
95 views

What happens when I give the shell a "command" versus a script?

A variant of this question has been asked a few times (here and here, for instance) but I'm afraid that the answers either didn't fully capture my question here or else perhaps assumed more than I ...
EE18's user avatar
  • 233
0 votes
1 answer
56 views

Portable alternative to `script(1)`

When I have to produce a log of a tool that responds to interactive input on the terminal (tee on stdout breaks this somehow), I reach for the script(1) tool, and it works more or less as advertised. ...
user22476690's user avatar
1 vote
0 answers
24 views

find subdirectories from different mount points without symlinks that have the same name as the subdirectory [duplicate]

I struggle to find a working find command, I hope someone has an idea. Imagine the following structure, where path and path{0..1} exist and they are each mounted from a network storage device: dir: /...
Oliver R.'s user avatar
  • 141
0 votes
1 answer
43 views

Adding an account via SSH not working with openssl

I am trying to add a user account to my remote server (running on Ubuntu 22.04) via SSH using below script: #!/bin/bash protect="y" ssh -i ssh_key [email protected] <<END sudo deluser ...
hiddeneyes02's user avatar
0 votes
0 answers
20 views

Reading from FIFO in nc (netcat)

I have a bunch of log files that I'd like to watch as they get updated. I came up with the script below: #!/bin/bash # Check if at least one log file is provided if [ "$#" -eq 0 ]; then ...
farhanhubble's user avatar
0 votes
0 answers
23 views

BASH + dig on list of domains gives wrong input to dig with domains suffixed with '\013' [duplicate]

I have a list of domains, and I want to use dig to check whether those domains have HTTPS records or not. I ran a for loop to do so, and I realized that the reason why I don't have any result is ...
cs.lev's user avatar
  • 1
5 votes
2 answers
124 views

Zsh: Is it possible to use the value of a variable as a substitution pattern?

Is it possible to do something like the following? g=$f:s/$in/$out/; or g=$g:s/$in[$i]/$out[$i]/; I've tried random character combinations like ${~in} and g=$g:ps/ but, as you can see, I'm not a zsh ...
colinh's user avatar
  • 47
0 votes
2 answers
53 views

What is the best way to continuously test connection to example.com on port 443?

I need to make continuous connection attempts to www.example.com at port 443. telnet www.example.com 443 But once done, it will keep getting connected [root@localhost ~]# bash c_telnet.sh Trying 142....
barnyard9's user avatar
0 votes
1 answer
18 views

Increment the sequence when the lines start with specific value in Unix

I want to increment when the line starting has a fixed word else continue with the same number. Input : CH,A11R,Q9Y5X3,SNX5 CD,A12L,Q9Y316,MEMO1 CD,A12L,Q70CQ2,USP34 CT,A12L,Q8N7H5,PAF1 CH,...
vijayakumar ponnusamy's user avatar
0 votes
0 answers
17 views

Zenity --auto-kill is not working on a ghostscript process

I'm with a problem with the --auto-kill zenity option, which function is, according to zenity --help-progress, used to kill parent process if Cancel button is pressed. That's what I need in this line: ...
samueldelorenzi's user avatar
1 vote
0 answers
64 views

How to run this particular command when an user login?

Every time i login i have to run this 2 commands: To be able to make caps2esc program work. But i want to automate this process cd ~/Apps/caps2esc sudo bash -c 'nice -n -20 ./caps2esc >caps2esc.log ...
lapdoggo's user avatar
-2 votes
2 answers
97 views

Password not getting set for this user creation script

The following script is supposed to create a user and generate a random password on an Ubuntu machine: #!/bin/bash #Script should execute with sudo/root access if [[ "${UID}" -ne 0 ]] then ...
Navdeep Singh's user avatar
2 votes
1 answer
85 views

script arguments in bash

I am working on a a script that need to take two script arguments and use them as variables in the script. I couldn't get this working and unable to find out what I am doing wrong. I see the issue is ...
MO12's user avatar
  • 391
0 votes
0 answers
66 views

Understanding bash read variable substitution [duplicate]

First of all, I have little experience using Bash and I apologize for my bad English. Maybe it's obvious. I am trying to understand why Bash drop value of the variable in this oneliner. echo "...
bas1c's user avatar
  • 1
2 votes
3 answers
186 views

How to compare two directories recursively, and for each pair of files with the same name, location, and contents, say which file is older?

In a Linux shell, how to compare two directories recursively, and for each pair of files (including symlinks and directories) with the same location (including the name) in the two directories and the ...
AlMa1r's user avatar
  • 25
0 votes
1 answer
65 views

Getting "gzip: invalid option -- 'x'" error while executing this archival script

The Script is to compress and archive any files greater than 20 MB in a given directory: #!/bin/bash #Variables BASE=/home/sengh/scripts DEPTH=1 #how deep to go in the find operation RUN=0 #Check if ...
Navdeep Singh's user avatar
0 votes
0 answers
44 views

sed not reading directory information [duplicate]

I'm having problems with sed. I can't seem to get this to work. I have a data file (renegade.dat), which contains the following lines: /opt/rg/data/ /opt/rg/misc/ /opt/rg/menu/ /opt/rg/logs/ /opt/rg/...
ignatius's user avatar
  • 401

1
2 3 4 5
328