Skip to main content

Questions tagged [bash]

Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

Filter by
Sorted by
Tagged with
3 votes
2 answers
5k views

Use Logrotate to truncate log files after every entry or clear last 'n' entries

i have created a logrotate config file: touch /etc/logrotate.d/.test with the conficurations: /home/myUser/test*.log{ size 0 hourly rotate 0 nocreate nocompress ...
18 votes
5 answers
15k views

Check if directory exists using home character (~) in bash fails

Why does the following bash check if a directory fail? if [ ! -d "~/Desktop" ]; then echo "DOES NOT EXIST" exit 1; fi ~/Desktop does indeed exist. This is on a Mac by the way. The problem is ...
0 votes
0 answers
35 views

How to Dynamically Adjust Rate Limits Based on Concurrent Connections in Nginx?

I am currently facing a challenge with dynamically adjusting rate limits in my Nginx configuration based on the number of concurrent connections to my web server. Problem Statement: I have set up a ...
1 vote
1 answer
70 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
145 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 ...
1 vote
2 answers
124 views

Storing top output to a file continuously

I'm currently using top to gather the most resource intensive processes and sending them to influxdb. Currently, the command is like this: top -bn1 -c -w250 Which basically runs top a single time (-...
2 votes
3 answers
330 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: [email protected] active 01/24/11 10:04 07/23/23 16:56 ...
0 votes
2 answers
145 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....
0 votes
2 answers
673 views

Convert $no_proxy to gsettings ignore-hosts

In order to use Chrome in Ubuntu and have it respect some hosts in $no_proxy, I need to set those comma-separated values with gsettings set org.gnome.system.proxy ignore-hosts <no-proxy> where ...
2 votes
5 answers
2k views

In bash how do you delete a partial word similar to ctrl-w

Say I have a directory with one file in it mylongfilename.blahdeblah.txt now the keystrokes mv [tab] [tab] will result in mv mylongfilename.blahdeblah.txt mylongfilename.blahdeblah.txt on my command ...
0 votes
1 answer
6k views

Value should be a JSON object error in Zabbix

I have the following script:- #!/bin/bash echo "{" echo "\"data\":[" grep -hoR server_name.* /etc/nginx/sites-enabled/|sed 's/[^ ]* //'|sed 's/.$//'|awk -F"/" '{ print "{\"{#URL}\":\""$1"\"}," }'| ...
5 votes
2 answers
2k views

Sort df Output by Mount Point

I need to get the output of df -h sorted alphabetically by its mount point in the Mounted on column. However, df -h currently outputs similar to this: $ df -h Filesystem Size Used Avail Use% ...
0 votes
0 answers
15 views

Packer not running any shell scripts

I have a provisioner to run a shell script, as per all the docs I found on the line, but nothing seems to actually run anything, it just sits and exists after a minute or two. "provisioners"...
1 vote
0 answers
1k views

TMUX not creating sessions from CRONTAB

I'm having a heck of a time getting a tmux session to be created from a script executed by crontab. The script executes and the session is created without fail from just running it but if I run it ...
2 votes
3 answers
4k views

Creating a RFC 1123 compliant date for HTTP header creation on the CLI

I'm trying to create a HTTP 1/1 compliant date header using standard unix date(1) in order to post this to a RESTful server using curl or similar. Any ideas what format to pass to date(1) to get this ...
0 votes
2 answers
105 views

Bash: build command string with quotes and invoke it directly

In bash, this sequence doesn't work the way I thought it would: > command="echo \"foo bar\"" > $command "foo bar" Using eval instead: > eval $command foo bar ...
0 votes
1 answer
35 views

CRON bash script certbot renew hangs

I have this script in /home/user/renew.sh ( cd /home/user/website/ && docker compose run --rm certbot renew --dry-run && docker compose kill -s SIGHUP webserver ) sudo crontab -e */5 *...
3 votes
2 answers
7k views

FreeBSD: how to syncronize the system clock with the hardware clock in bash?

I am writing a script that synchronizes the system clock with the hardware clock (aka RTC, or CMOS clock) assuming that no Network Time Protocol (NTP) daemon is running. I am running in a virtual ...
377 votes
20 answers
613k views

How do I get the current Unix time in milliseconds in Bash?

How do I get the current Unix time in milliseconds (i.e number of milliseconds since Unix epoch January 1 1970)?
161 votes
19 answers
299k views

What's the best way to check if a volume is mounted in a Bash script?

What's the best way to check if a volume is mounted in a Bash script? What I'd really like is a method that I can use like this: if <something is mounted at /mnt/foo> then <Do some ...
74 votes
8 answers
111k views

How to read in N random characters from /dev/urandom?

read /dev/urandom 3 The above is not working..How can I read random bytes from /dev/urandom in bash?
245 votes
10 answers
355k views

How to run a command multiple times, using bash shell?

Is there a way to run a command (e.g. ps aux|grep someprocess) for n times? Something like: run -n 10 'ps aux|grep someprocess' I want to use it interactively. Update: The reason I am asking this is,...
77 votes
6 answers
53k views

How can I check in bash if a shell is running in interactive mode?

How can I tell (in ~/.bashrc) if I'm running in interactive mode, or, say, executing a command over ssh. I want to avoid printing of ANSI escape sequences in .bashrc if it's the latter.
15 votes
7 answers
36k views

Log commands executed over SSH

I would like to log all commands executed over SSH. Say, ssh [email protected] COMMAND I want to log "COMMAND" on server.com I did search extensively but could not find anything. There ...
64 votes
7 answers
129k views

bash: variable loses value at end of while read loop

I have a problem in one of my shell scripts. Asked a few colleagues, but they all just shake their heads (after some scratching), so I've come here for an answer. According to my understanding the ...
0 votes
1 answer
77 views

Unable to query or rm file from an smb mount, but it appears using ls

Problem I have a file that cannot be removed or queried in, but it does appear using ls and does not allow overwriting it. # ls -l -rwxr-xr-x 1 root root 151040 Mar 22 21:55 export.mb -rwxr-xr-x 1 ...
10 votes
4 answers
30k views

How to create extra root user? [closed]

I have tried making a root2 user which should have the same permissions as root by doing useradd -g root root2 passwd root2 usermod -G root root2 usermod -aG wheel root2 but root2 can still not cat /...
1 vote
2 answers
4k views

bash wait for service to start

I'm having trouble with the first part of the bash script, I need to wait for server mysql to start before executing mysqadmin commands... I cannot reliable get it to work! #!/bin/bash if [[ ! -f /...
0 votes
4 answers
11k views

how to use quoting and escaping with bash

I was given a list of urls that are generating 404 errors as reported to us by google. I can test a url with curl (from the command line ) like this: curl -k --user-agent "Googlebot/2.1 (+http://...
14 votes
5 answers
6k views

Handy parsing for numbers with unit suffixes?

Let's say you have data with quantities in human-readable format, such as the output of du -h, and want to further operate on those numbers. Let's say you want to pipe your data through grep to do a ...
0 votes
3 answers
6k views

cURL POST bash script adds single quotes to variables with spaces

The first 3 variables will always have no spaces. The fourth "slacksitename" has spaces ip=“x.x.x.x" record_name=“demo.xyz" slackuri:”WEBHOOK" slacksitename:”123 Main St" ...
2 votes
3 answers
5k views

.bash_history permissions mysteriously changed

So my ubuntu user's .bash_history just won't show up when I hit history. So I check permissions and the .bash_history in /home/ubuntu is now owned by root. Any idea what might've happened? I ...
0 votes
0 answers
24 views

Kubernetes (CRI-O) cannot ping to any host

Cannot ping to any host from kubenetes pod. Needed functionality: Ping between 2 kubernetes pods Expected result: Successful ping between 2 pods. Current output: pod/kube-server-rtt-3 created pod/kube-...
6 votes
2 answers
7k views

How to programatically find default ssh key?

In most of my experience, by default, ssh will look in ~/.ssh/id_rsa(.pub) for the default key pair. Ocassionally I try to write scripts to take advantage of this default key location, but I end up ...
0 votes
0 answers
38 views

How to extract umask value from new instance bash shell with single command?

I can extract umask value from new instance bash shell with this method : [ansible@rhel8 ~]$ umask 0027 [ansible@rhel8 ~]$ bash [ansible@rhel8 ~]$ umask 0002 [ansible@rhel8 ~]$ But for me this is ...
41 votes
11 answers
116k views

How do I read multiple lines from STDIN into a variable?

I've been googling this question to no avail. I'm automating a build process here at work, and all I'm trying to do is get version numbers and a tiny description of the build which may be multi-line. ...
1 vote
1 answer
5k views

PyCharm on Windows 10, how to use WSL ubuntu bash to run shell scripts?

I have installed PyCharm Community Edition on Windows 10, my Windows also has WSL Ubuntu installed. We know that PyCharm on Linux can create and run shell scripts because PyCharm use the /bin/bash on ...
0 votes
1 answer
74 views

Check if package exists in repository that is not on my sources.list?

TL;DR: How can I check if a package exists in a repository that's not on my sources.list? What I want: Most answers I'm finding assume the repo I need to check is already in my /etc/apt/sources.list. ...
0 votes
1 answer
65 views

cd command not recognized by a systemd service script

Hi run Debian OS and I have a shell script that runs sphinx search. The script runs fine if I run it from terminal as below: sh /home/myuser/sphinx/run_sphinx.sh Here is the content of run_sphinx.sh #...
1 vote
0 answers
29 views

Run a script when a user is created by SSSD

Basic setup: I'm running an Ubuntu VM which is joined to MS AD. SSSD handles user creation when people log in using their AD credentials. The only login method for the users is via xrdp. When a new ...
15 votes
6 answers
15k views

How can I easily convert HTML special entities from a standard input stream in Linux?

CentOS Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example: "test" &...
5 votes
1 answer
4k views

Change Alpine Linux default shell

Alpine defaults to ash as the login shell, I want to change it to bash. What I did so far: installed bash by sudo apk add bash installed shadow by sudo apk add shadow I changed my user's login shell ...
0 votes
2 answers
32 views

Replace text with sequence of numbers

I have 2250 metadata files that need to have a unique number starting at 0 going to 2249, as the line below. "name": "KF # RENUMBER", I've used the perl command (perl -pi -w -e 's/...
1 vote
2 answers
7k views

Escape all characters that shell or sqlplus need escaped in any password given

You may try for yourself by creating this user: CREATE USER "karl" IDENTIFIED BY "/?'!@#$%^&*()_+=-~`" (Maybe there are other symbols I should have included for my testing, but that seemed ...
0 votes
1 answer
5k views

How to get the permission of `/run/user/1000/gvfs` when system is newly installed?

System is newly installed debian 10. I cannot get the permission of /run/user/1000/gvfs properly,changed from d????????? ? ? ? ? ? to dr-x------ when cd /run/user/1000. me@pc:~$ ...
0 votes
1 answer
108 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
2 answers
253 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 ...
1 vote
2 answers
345 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-...
1 vote
2 answers
1k views

Hashicorp Vault How Do I Login Headless From STDIN Using Bash Shell?

Given a Bash Shell say in a Docker container running on Gitlab, for example, how would I get the password to get passed in? When I login with this: $ vault login -method=ldap username=myusername It ...
0 votes
0 answers
109 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 -...

1
2 3 4 5
72