Questions tagged [bash]
Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).
3,527
questions
1
vote
1
answer
68
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
34
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
19
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
39
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
180
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
55
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
36
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
28
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
43
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
117
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
34
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
31
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
55
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
30
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 ...
2
votes
2
answers
58
views
Best way to filter output by date range
I need to filter a row of a csv file by a date.
The file is structured as so:
test121smith@example.com active 01/24/11 10:04 07/23/23 16:56
...
1
vote
1
answer
113
views
Calculate seconds minutes and days ago in shell
I have a timestamp that saves a user's last access information like
Time => 14:15:05 PM
Day => 08/23/2023
Based on this saved information, I would like to write a command that returns how much ...
0
votes
1
answer
72
views
How to save input colors in awk?
I've seen many more or less related topics, but all I found discuss how to color awk output. I need to preserve the color that was provided as awk input. For example, now I have:
./some_command
(...
0
votes
1
answer
96
views
Any way to see output of pv when run in subshell?
I'm creating a squashfs file using dd to create a pseudo file - like described here ("under Streaming Compression" heading):
mkdir empty-dir
mksquashfs empty-dir squash.img -p 'sda_backup....
0
votes
2
answers
1k
views
jq: error: X/0 is not defined at <top-level>, line 1:
I'm trying to extract value from the bellow JSON:
% export test='{"a-b-c":"x-y-z"}'
% echo $test
{"a-b-c":"x-y-z"}
% echo $test | jq .a-b-c
jq: error: b/0 is ...
0
votes
1
answer
322
views
expect usage in bash script or bash command in expect script
I have a script below that works except for the expect portion:
#!/bin/bash
#
invdir=/home/john/inventory
for file in $invdir/$1
do
if [ -z $1 ] || [ -z $2 ]
then
echo "You must enter a ...
0
votes
1
answer
136
views
How to back up mysql/mariadb database as mysql root when using unix socket for sql access in a bash script?
I am running Ubunutu Server 20.04. I have secured mariadb by using the unix socket for authentication, which means, I need to enter sudo mysql to be able to access mysql as root.
1)
If I enter
mysql -...
0
votes
1
answer
26
views
How to catch the error output in shell when error code is not enough?
I came across the script with if-else branch with a particular command succeed or not like this:
pg_ctl -D /var/lib/pgsql/data -w promote
if [ $? -ne 0 ]; then
echo: failure
exit 1
else
echo: ...
0
votes
0
answers
21
views
Instantiate AWS cred env vars on the CLI from AWS Identity Center
I've moved to using AWS Identity Center for creds.
I follow the instructions and have a way to set the profile in the linux/mac CLI via a browser. I can then instantiate traditional AWS creds for ...
0
votes
1
answer
50
views
Setting up Slack Alerts for Monit monitoring MySQL
Trying to set up Slack alerts for Monit and MySQL/MariaDB but stuck in writing a MySQL check script. I have the monit successfully working if MySQL is stopped and receive email alerts - but want the ...
0
votes
0
answers
25
views
shut down a script when it's detached from the terminal without kill
I have a bash script task with following requirement:
"Script must be easy to shut down when it's detached from the terminal without having to resort to ps, pgrep, pkill and their like"
With ...
0
votes
0
answers
56
views
Sendmail entry in /etc/aliases that modifies the email header before sending it out?
I'm using Sendmail I want to create an alias in /etc/aliases, that modifies the To: line before sending out the message . I assume I need some sort of script or command that the email is piped into. ...
0
votes
2
answers
66
views
crontab shell script execution not as expected
I have a script named run_logs.sh with the contents:
#!/bin/bash
source /root/.profile
zcat /var/log/apache2/access.log.*.gz | /usr/bin/goaccess - access.log
when I run that script as root (both with ...
0
votes
1
answer
103
views
Unable to List Contents or Create Files in /var/tmp Folder from PHP Executed Bash Script
Objective:
I want to trigger a webhook on a private linux-machine (its a local system not connected to internet), which can delete the spool data generated by CUPS server in /var/tmp folder.
To ...
-1
votes
1
answer
43
views
Copy/Move Entire Line To End Of The Line Above
I have a file that looks like the following:
/path/to/a/very/long/path
0 0 0 0 0 0
I need to move the line starting with a number (this can be any value not necessarily 0) to the end of the ...
0
votes
0
answers
33
views
PROMPT_COMMAND duplicating commands on new sessions
Im playing around with PROMPT_COMMAND variable
Was testing out some ways to save all commands into a log file and got some ways using PROMPT_COMMAND + logger + rsyslog
Example export im using
export ...
0
votes
1
answer
74
views
Loggin bash_history using UTC timestamp when not using UTC as system time
I am aware that it is possible to add timestamps to bash_history.
The examples I've seen so far it always uses the current system time. And here is the problem for me: On the one hand, I like to keep ...
0
votes
0
answers
29
views
Find directories not containing subdirectories with today file date
Can you please help me with a bash string for finding and listing only parent directories NOT containing subdirectories with today file date, so i can delete them recursively?
My Env is CentOS and dir ...
2
votes
0
answers
48
views
is there a shortcut for /dev/stdout like "-" is for /dev/stdin?
is there a bash shorcut for /dev/stdout like there is "-" for /dev/stdin ?
One of the use cases is to get bash history without line numbers. There is simply no option for that in the history ...
0
votes
2
answers
88
views
Command that run fine... but give me an error when "piped" to grep, inside a docker RUN?
Sorry for the title, I really can't explain better. I'm learning shell programming.
I'm trying to detect if Composer has a script named "post-install-cmd". To do that, one can call composer ...
0
votes
2
answers
90
views
Get the actual value of free memory is sun sparc
I am trying to get the current (not the average) free memory size of SUN SPARC remote server, but I don't have the permission to use free -m command or prtconf. So, I used command vmstat 2 and the ...
0
votes
1
answer
335
views
systemd not able to run some bash scripts
(Update with more info May 16, see end of post for journalctl messages)
I've created a systemd timer and service with the purpose of running a handful of bash scripts. In particular I'm aimed at ...
1
vote
1
answer
140
views
/etc/cron.d not running job [duplicate]
I need to run a script as a user to backup my database every night. I added the following cron job in /etc/cron.d/backup-mysql via ansible.
0 3 * * * backup_mysql /path/backup-mysql.sh
I can see the ...
1
vote
1
answer
55
views
How do you compare time date strings not actual dates and times?
I have a bunch of directories with video files that I would like to merge into larger videos. The logic is that the filenames have date time stamps in them that can be used to figure out which should ...
0
votes
1
answer
98
views
Cleaning up WordPress thumbnails; trying to find all thumbnails and delete them on Ubuntu 22
So, I'm trying to clean up some backups I have, and they're getting bigger and bigger because of, mainly, the number of thumbnails generated by WordPress per image. I came close to finding a solution, ...
0
votes
1
answer
173
views
$'\r': command not found error when executing find in a bash script
I wrote the following script; it's modified for simplicity and privacy reasons:
FILES_ROOT='/data/FILES'
BACK_B2B_RETURNS_S="$FILES_ROOT"'/wms-m-company/w2z/b2breturns/backup'
...
0
votes
0
answers
18
views
Exim.conf Redirect email to an another folder
I am trying to redirect/route incoming emails to another folder depending if they are listed inside the /etc/email_list file (ON/OFF). I am unsure how would I approach this, I am clearly messing ...
1
vote
1
answer
23
views
Linux, do I need if, else, or statements to accomplish automation of compiling programs from source [closed]
I am wondering what would be the best way to write a bash script to install packages from source, would it even be needed to go in depth with how to automate the task?
For example let's say I want to ...
0
votes
0
answers
29
views
Automatize using bash downloading deb files and dependencies and later extracting them to a unique folder and compress it to use in a live filesystem
I am developing a Live filesystem and need to be able to download deb files with its dependencies which I manually do using:
apt download $(apt-cache depends --recurse --no-recommends --no-suggests \
-...
0
votes
1
answer
194
views
What does lower case "g" mean in top output?
Can someone please help explain this, I have always used to interprete the "g" in top output to be size in Gigabytes even though the convention is to use uppercase "G" but now I am ...
0
votes
1
answer
124
views
Incremental backup of an entire FTP server with Linux [closed]
I'm looking for a simple way to schedule full + incremental backup of a remote FTP server (that also supports SFTP, but without SSH access) from My NAS that is based on Linux, WITH full SSH access. I'...
0
votes
1
answer
45
views
Is posible to write script that checks for differences between two patterns in configuration files
Linux. I have for example two config files.
First:
criticalexceptions => [
'yum-updatesd-helper: error',
'cups: cupsd shutdown succeeded',
'hda: drive_cmd: error',
'end_request: ...
2
votes
1
answer
461
views
How to load modules on Synology NAS on boot?
I have a Synology NAS (DSM 6.2.4) and I would like to load usbserial.ko and cp210x.ko on boot.
When I run:
sudo insmod /lib/modules/usbserial.ko
sudo insmod /lib/modules/cp210x.ko
The drivers work ...
2
votes
1
answer
430
views
Is sudo -u username command the same as doing sudo -i -u username then command?
Is a terminal prompt sudo -u username command
same as doing
sudo -i -u username then command in the next line?
If no, what is the differences? What are the use cases when doing the first is better or ...
0
votes
1
answer
164
views
Why can't ssh run rbenv in the shell?
I'm trying to run a bash script on a remote server to install ruby via rbenv.
#!/bin/bash
# ssh deploy@192.168.50.2 'bash -s' < configure.sh
echo "ruby 3.2.1"
rbenv install 3.2.1 --...
1
vote
1
answer
254
views
Redirecting stdout and stderr doesn't work with cron
I have the following cron task. Expected behavior is that every output (standard output and standard error output) of this task will be redirected to /dev/null. Unfortunately this doesn't work. Emails ...