Questions tagged [bash]
Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).
3,553
questions
0
votes
2
answers
55
views
use wget in bash script - how to get downloaded file name? (using content-disposition)
i am using wget to download some file in a bash script. i need to use it like this:
wget -t 20 --content-disposition $link
the problem here is, that i cannot specify the output file since it comes ...
0
votes
1
answer
26
views
getopts does not find missing arguments on multiple options
Bash 5.1.16
The following code doesn't work for me:
optstring=":l:s:vh"
while getopts ${optstring} flag; do
case ${flag} in
(l) listsfile=${OPTARG};;
(s) sourcedir=/${OPTARG};;
...
0
votes
0
answers
84
views
sshpass/rsync fails when not redirecting stdout etc
I am having a weird issue and I just can't seem to find the cause and a solution.
I am on win11/cygwin (sshpass 1.06,rsync 3.2.7)
I call:
/usr/bin/sshpass -p $sshpasswd /usr/bin/rsync --dry-run -...
0
votes
1
answer
25
views
keyboard combination to search forward in bash history
Pressing ctrl-R allows me to search thru command line history
Pressing ctrl-R allows me to go back in command history matches
What is the keyboard shortcut to jump forward in command history matches?
...
0
votes
1
answer
52
views
How to convert text file from BASH to HTML?
I already extract some text from bash using command "systemctl status ddos.service" bellow :
But, when I generate report in html for text that I extract above, it show all text in one line, ...
0
votes
0
answers
62
views
Running ssh-add in bash with both the key and passphrase as arguments
I am trying to run ssh-add by bash script on Alma9 server with restrictions.
The RSA key 4096 is on an SMB share so the file has broken permissions and the key is protected by a passphrase.
As the ...
0
votes
0
answers
107
views
Remove bash permissions for a user
I have to create a user that uses /bin/sh as initial shell. This is something I have already done but, I need that this user cannot access bash under any circumstance.
After searching on the internet ...
0
votes
0
answers
18
views
How to establish VPN connection with two factor authentication from CLI
A VPN connection have to be established on demand from a bash script. GUI needed to enter two factor auth code. If you'll try to execute in terminal:
VPN_NAME=$(nmcli con|grep "VPN"|awk '{...
1
vote
1
answer
143
views
HEREDOC in Dockerfile produces no output
I have this command that I am trying to run in a Dockerfile and it is producing no output to the file:
FROM alpine:3.19 as base
RUN <<-EOF > /root/.npmrc
registry=https://\${...
0
votes
0
answers
28
views
Dynamically Set GitHub Actions Secrets on Docker Container Build/Run Command with bash/shell
I'm in the early stages of building an automated pipeline. Still in the exploring phase. Right now, I'm struggling with setting the environment variables for the container I'm going to run my app and ...
1
vote
0
answers
62
views
Executing a list of commands on distinct lines with bash -c?
I pass a list of commands to a bash script through an environment variable as shown in the example below:
CMDS='
date > date.txt
cat date.txt
date | rev
' script
What is the correct ...
0
votes
1
answer
25
views
Variable substitution not working in CGI script
I am trying to make a CGI script that takes the name and email from a form, decodes the QUERY_STRING variable into the two values, and then does stuff with them ( for now I just decoded the name an I ...
1
vote
2
answers
160
views
DHCP starting before network is ready
I am having a problem with my DHCP server. When it restarts the isc-dhcp-server does not get ready because the network (it uses NetworkManager) is not ready.
I put a sleep command in the isc-dhcp-...
0
votes
0
answers
20
views
-CGI script not getting executed
0
I'm trying to make a simple form where you can introduce you're name and upon hitting the submit button you get redirected to a page where it says "Hello name_that_was_submited!". I did ...
0
votes
0
answers
66
views
cd: permission denied: /a/b/c/d, but can get to d by CDing one directory at a time
I am occasionally running into this weird situation where I when I try to CD into a particular directory, it gives me a permission denied error. But when I CD into it one directory at time (i.e., CD /...
0
votes
1
answer
27
views
argument to pgrep from cmdline returns 2 PID's and argument from global variable value returns 1 PID
1.first case(processName as argument from cmd i.e java)
command from cmd with arguments : ./a.sh getProcessId contains java
code:
getProcessId(){
matchType=$1
#defaulting matchArg to x i.e exact ...
1
vote
0
answers
41
views
crontab -> shellscript -> docker -> redirect output to localfile
I am currently switching from rsync to a borg based backup.
Everything is working, except getting the output of borg to my logfile.
My setup is as follows:
I am trying to do everything in docker to ...
0
votes
1
answer
124
views
pgrep -f from shell script is returning 2 pid instead of 1
code :
function main {
[ -z "$@" ] && { getProcessId "$@" } || "$@"
}
getProcessId(){
matchType=$1
#defaulting matchArg to x i.e exact match
matchArg=x
...
0
votes
1
answer
44
views
sftp download without keyring prompt - without change of .bashrc
For a bash install script, I need to download files with sftp. When doing so, a gnome keyring prompt will open. This can be avoided by some changes in .bashrc or so.
But as my script should run on any ...
0
votes
1
answer
53
views
How can I log when the postfix (for an incoming mail server) enters the stressed condition?
I have a server that I use only for incoming emails it uses Postfix as MTA. I want the postfix logs to indicate when (and if) the MTA enters the stressed mode. I thought about writing a custom bash ...
0
votes
3
answers
261
views
Shell script capturing values from output of command
From a shell script, I run a ping command:
ping -c4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=34.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 ...
0
votes
0
answers
59
views
not able to send mail with attachment from linux ubuntu : 20.04 by using email mailutils (sendmail keyword)
code :
subject="Service resilience service status"
body="Service is down"
from="[email protected]"
to="[email protected]"
attachment="/home/ubuntu/...
1
vote
1
answer
124
views
not able to send mails from linux ubuntu : 20.04 by using email mailutils (sendmail or mail keyword)
code :
subject="mail subject"
body="Hello World"
from="[email protected]"
to="[email protected]"
echo -e "Subject:${subject}\n${body}" | sendmail -f "...
0
votes
0
answers
30
views
_curses.error: cbreak() returned ERR when running jenkins
I'm running pg_activity through a bash script to simulate that pg_activity that can launch correctly without any issues.
Below is my script
#!/usr/bin/bash
/soft/python3.7/bin/pg_activity <<...
0
votes
1
answer
412
views
How to check if a process is running or blocked on lock or I/O?
There are 2 instances of a script reported by ps.
How can I see in the command line if one of those (and which) is blocked on either I/O or on a file lock?
-3
votes
1
answer
69
views
I want to make a sell script to input text into a command in debian
I am sorry if I am having trouble explaining, here is my issue,
I want to make a basic shell bash script say x.sh and I want to run command
change
htpasswd -b -c /etc/squid/squid_passwd root pass
...
0
votes
0
answers
201
views
Bash Script - How to escape JWT in curl correctly
Im trying to just execute some curl commands against an API from within a bash script. I wrote it on Mac OS and the thing ran without issues. I started executing it on linux and found some strange ...
0
votes
0
answers
47
views
list only one Process by name in htop (even when it restarts?)
i am trying to get htop to show me one process.
this is a programm i wrote wich comes up from time to time (so it always has another pid).
what i am trying is something like that:
htop -p $(pgrep ...
0
votes
1
answer
103
views
How to start a sudo-privilage program with screen so that I can re-attach to it later?
Here's the problem I face: I have a program that must run as root. I want that to run in a screen, but here's a twist: for admin reasons, I want to be able to re-attach to it.
I'm writing a dirty and ...
0
votes
0
answers
40
views
Bash script error when trying to create a snapshot
I am trying to create a snapshot using Bash script as below but error occurred.
Environment: FreeBSD,
Version: 13.2,
Script: Bash
#!/usr/local/bin/bash
name="17102023_1234"
zfs snapshot data/...
1
vote
0
answers
134
views
Set GitHub secret keys in bulk – sh file
I’m in the initial stages of building a simple automated deploy pipeline. One of the steps I’d like to implement would be setting the GitHub Actions secrets in bulk, since I have many of them in my ...
0
votes
1
answer
70
views
get user with crontab root
I run myscript.sh scheduled in the root crontab and I need it to detect the non-root user (with which the system starts).
I have tried these variants:
local_user=${who -m | awk '{print $1;}'}
...
0
votes
1
answer
218
views
is /etc/sudoers writable or not
The default permission in /etc/sudoers file is readonly for root and group root as in picture is obvious :
So when you open it with any test editor it can't be written and give error read only.
now ...
0
votes
0
answers
292
views
Systemd service executing a script with error handling
I have the following issue:
I created a systemd service which executes a script. This script contains several commands including psql commands which queries a database and stores the outcome into ...
0
votes
1
answer
42
views
copy many files with big sizes over rsync
I have database server on AWS and the backup of databases are over 1000 files with sizes can reach 5GB,
I am using a script to copy the backup to my data center using rsync, but the copy is slow, I ...
0
votes
1
answer
92
views
Bash script : Print all lines between two pattern in variables with slashes
I have a directory that looks like so :
/path/to/files/data-file.1
/path/to/files/data-file.2
/path/to/files/data-file.3
/path/to/files/data-file.4
/path/to/files/data-file.5
/path/to/files/data-file....
2
votes
1
answer
569
views
Blocking traffic from specific countries. How to kill existing connection?
Using Linux Debian Bookworm.
Problem
I want to block all incoming connections to my server coming from specific countries.
Edit
As someone pointed out in the comments, I really shouldn't be doing this ...
0
votes
1
answer
67
views
su command not set BASH_VERSION value and not load profile
I have a Ubuntu 20.04 LTS server version and have a strange problem creating a new user and use it in the shell from a ssh connection. The steps to reproduce it:
Use he root account to create new ...
0
votes
0
answers
40
views
AWS CodeDeploy - Must be connected to a terminal
I have a CICD Bitbucket pipeline that runs and tries to execute a deployment script.
appspec.yml
version: 0.0
os: linux
files:
- source: scripts/osgi-deploy.sh
destination: /home/...
0
votes
0
answers
44
views
sanitize folder names before creation
How prevent the injection when creating folders with user supplied paths in a unix like system?
Ideally subfolders can be created only in selected or working folder. Although the creation of folder in ...
0
votes
2
answers
202
views
Bash parameter substitution (baparmsub?) Isnt working
[ using bash -cx 'a="_IN_workstation"; b=${a/[a-zA-Z]*[a-zA-Z]/_};echo x.$b.x' does partially work but the lack of parenthesis will skew the match. So this points to the parenthesis ...
1
vote
1
answer
90
views
Bash has problems with cmdline nft cmd vs script
linux mint. uname -r yields 5.15.0-56. dpkg-query -l bash yields 5.1.6ubuntu1.
My script shows this problematic output
when bash -x script invoked:
attrib =' '\''{type nat hook prerouting priority ...
0
votes
0
answers
72
views
Is there any cli to detect directory changes between bash script runs?
For example I have this command
generate-and-deploy-new-version ./site-directory
and I want to run it only if content of the ./site-directory was changed.
if checkchanges "./site-directory" ...
0
votes
1
answer
57
views
Service to monitor Service not triggering
On Ubuntu 18 I have a service :
[Unit]
Description=Gets CSV
OnFailure=pushovercsv.service
[Service]
ExecStart=/usr/bin/vehicles.sh
[Install]
WantedBy=multi-user.target
This works. I am trying ...
0
votes
1
answer
296
views
What is the correct way to check monit status/summary success/failure
I have monit utility on production for monitoring several daemons (our micro-services). I'm trying to figure the best way to unmonitor/monitor my daemons while updating them. So, basically I need ...
1
vote
0
answers
407
views
AuthorizedKeysCommand setup prompts for password
The issue: Even though I've set up AuthorizedKeysCommand and password authentication is stopped when I attempt to log in from my Mac, I am still being asked to enter the password:
OS: Rocky Linux 9.2
...
0
votes
1
answer
93
views
Extract Pages from Other PDF Files into a New PDF File
I would like to extract pages from various PDF files and create a new PDF file from those pages. What tool(s) should I use?
-1
votes
1
answer
38
views
Extract Pages from Various PDF Files into New PDF File [closed]
From
a.pdf, I would like pages 2 and 5
b.pdf, pages 3 and 4
c.pdf, pages 7, 8, and 9
copied into a new PDF file.
All input pdf files are ten pages long.
I'm using bash, and plan to make many ...
1
vote
1
answer
150
views
why does systemd tag my self-made service "thawing" after running it for a few days?
I have found the strange tag of "thawing" running my self-made service using systemctl status XXX like this:
On the contrary, I found it running several threads via htop:
At first I ...
0
votes
0
answers
67
views
psql shell over ssh via bash script doesn't get user input
I'm opening a ssh connection and then go into a psql shell.
This works, I get the prompt.
I can also input commands like "\dt".
But I don't get any output.
As I can get output in general, I ...