Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash-scripting]

Bash scripting is making scripts in the Bash shell language.

1
vote
1answer
23 views

Why does command substitution not work in braces but replacing it with the actual number works?

I'm using the following command to try to max out the number of cores on my server: for i in {1..`nproc --all`}; do while : ; do : ; done & done For some reason, it only ever uses one core, even ...
0
votes
1answer
18 views

Print all commands in a bash function

I am trying to debug a bash function. Is it possible to print all the commands executed by a bash function? I know that it is possible to print all the commands by a bash script by changing #!/bin/...
1
vote
2answers
44 views

Changing directory in script doesn't change directory — why?

I've seen this answer since searching for this, but initially I wrote this script: for i in `seq 1 $1`; do cd ../; done; It doesn't change directory. Why is this, running as ./updir.sh 5
0
votes
2answers
31 views

How can I get quotes to show up when I'm using AWK to find and replace?

Currently I'm using AWK to find and replace a portion of the first three occurrences of a string. The string is formatted as such, and there are many of these strings in the file: func(tempID="...
1
vote
1answer
35 views

How to handle a .js extension correctly in bash script?

I have the following bash script. while IFS= read -r filename; do [[ $(md5 path/to/"$filename-orig") = $(md5 path/to/"$filename") ]] || echo $filename differs; done < path/to/list-of-files-to-...
0
votes
1answer
28 views

Issue with replacing Json variable with shell script value using curl

#!/bin/bash #CONFIG_FILE_PATH is the path of the json file as argument while running the script CONFIG_FILE_PATH=$1 CUST_NAME=$2 curl -X POST -i -H "Accept: application/json" -H "Content-Type:...
0
votes
1answer
19 views

Restart on crash script check

I'm trying to make a shell script that checks to see if 2 different processes are running and to restart them if they aren't. I just want to keep it simple. Is this the correct way because it doesn't ...
0
votes
2answers
37 views

cmd.exe launched from another cmd.exe

I'm doing a script that I start with bash.exe from Cygwin on Windows: C:\bash.exe my_script.sh It changes my Python Virtual Env depending of some conditions. For those who know Virtualenv, I need to ...
0
votes
0answers
19 views

how to copy public key using ssh-copy-id silently

I am copying my public key to another machine using ssh-copy-id. $ sudo ssh-copy-id -i /home/vagrant/.ssh/id_rsa.pub vagrant@datanode1.com /bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/...
0
votes
1answer
9 views

How to determine xsetwacom default settings for connected devices

Since xsetwacom will only apply settings temporarily, I would like to write a startup script that applies preferences for my Tablet. I'm wondering if there is a way to determine all possible settings ...
1
vote
1answer
60 views

Extract a value from a text file in a specific position

I have a file containing tons of information. It looks like this: =============================================================================== NSTEP ENERGY RMS GMAX ...
1
vote
1answer
34 views

Match files on line beginning

When giving parties, I record everything my guests eat.[1] Note: I've inserted a few tabs to make everything readable. party1.txt: Bernhard Apple Jeremy Cake Liz Cake Daisy ...
0
votes
1answer
108 views

Bash script need to convert string to date

Hello I have this bash script for checking the integrity of backups. I need to edit it as I have to make warn me when the oldest backup is more than 60 days (as we delete those). Now the date is ...
0
votes
1answer
27 views

Automate a process using bash script

I have a unimrcp client process (ucp) and I want to spawn multiple ucp using shell script. Whenever I spawn a ucp, it returns a command line using which I can access different functionalities in ucp. ...
1
vote
1answer
59 views

Why is my simple bash script is not running?

I am just writing a simple Bash script on CentOS 6.2: [root@hadoop1 ~]# vi bash_startup #! /bin/bash export r=1 Backing to the command line: and running using ./bash_startup [root@hadoop1 ~]# echo ...
0
votes
1answer
55 views

Using `ls` to show real name of file owners

Unix users can have their real names listed in /etc/passwd/. The finger command can display the real names. Can ls -l show these real names of file owners next to the files? If ls cannot do this ...
0
votes
0answers
75 views

Lookup-table text replacement in bash

We have weird usernames in our Linux system (like user0001). I would like to pipe results of ls -l through a lookup-table replacement of the weird usernames by their real names. I can make such a ...
2
votes
1answer
90 views

How to get IP address and the connected interface name in bash

PC with onboard linux has several network interfaces, e.g. two ethernet cards and one wifi adapter (numbers and types may vary). Each of that interfaces could be connected to a network (and could be ...
0
votes
2answers
42 views

Linux : double-quote variables and for file loop

In another question, I was advised to "double-quote $variables" in my script to avoid errors. After reading a lot of info about double-quotes, I presume I can/must exclude wildcards from double-quote ...
0
votes
1answer
47 views

Linux : secure recursive delete within scripts

I'm working on automated scripts running on a Linux box (Debian). Those scripts are started from a scheduler and are manipulating files within their own directories. At the end of the scripts, I need ...
2
votes
2answers
109 views

Find filenames with uppercase extension

How can I find all the files with their extension in uppercase in recursively in a directory. I've tried : $ find -name "*.[A-Z][A-Z][A-Z]" Seems to work but of course this does not check files ...
0
votes
2answers
66 views

Remove duplicate files by comparing them with MD5 RECURSIVELY

i want to delete duplicate files based on their MD5 value. I already got the script down below but how do i modify it so it works recursively? So for example i have folder containing 3 subfolders A B ...
2
votes
1answer
31 views

How to rename file during copy in command prompt

I want copy a file from a folder to another while changing the file name. How can I do this? For example: copy 1.txt to C:\new folder with this name: 2.bat.
0
votes
0answers
68 views

How to use a bash variable for the @filepath in a curl command

I am trying to write a bash script to run a series of curl commands. The command I am trying to run is this: curl -XPUT $URL'/test/' -d @$DATA_DIR/index-settings.json This is my bash script #!/bin/...
0
votes
1answer
38 views

How do I automatically generate symlinks?

Not sure if this is the right spot to post this (if it isn't, sorry) Due to some restrictions (and preferences) I'm finding myself at a dead end. Machine is running ProxmoxVE (Debian/QEMU based ...
0
votes
0answers
172 views

What are all of the globs I can use with grep in bash?

Linux and Unix-like shells like bash allow for the use of globs to approximate filenames and make file searching easier. I'm aware of the wildcard glob (*). What other globs exist in bash that I can ...
0
votes
1answer
29 views

Catching a bash command error in a variable

I'm using psql(PostgreSQL) command in a bash script: function create_database () { sudo -u postgres psql -c "CREATE DATABASE $1 WITH OWNER $2;" 2>ERROR if [[ $? -ne 0]; then ...
6
votes
1answer
1k views

Get filename without extension in Bash

I have the following for loop to individually sort all text files inside of a folder (i.e. producing a sorted output file for each). for file in *.txt; do printf 'Processing %s\n' "$file" ...
0
votes
1answer
173 views

Regex to check if a string contains only letters(lower/caps), numbers and some special characters

A string that I obtain using readform user can contain: letters numbers _ For another string the rules are the same as above plus: starts only with letters I'm starting from this: if [[ $A = [a-...
1
vote
1answer
37 views

Using bash scripting How do I check if a string is inside another string

I'm using bash scripting to execute psql(database) commands: The command returns an answer that contains or not the database/table name. How do I check if my database/table is in the returned answer?...
1
vote
1answer
203 views

How to programmatically check if database and/or user exists in a PostgreSQL database using Bash?

I want to write a bash script that creates multiple users and a database. First I want to check if user exist, so I tried sudo -u postgres psql -c 'SELECT 1 FROM pg_roles WHERE rolename=${VAR_USER}' ...
2
votes
0answers
39 views

Sort with case-sensitivity in macOS in the Terminal

I am trying to use the answer in GNU Sort by case-sensitive to sort a file in my Mac OS. My file.txt looks like this: "Best" "A" "BEST" In the second answer to the mentioned question, it says that ...
2
votes
3answers
61 views

Script that compares 2 file's sizes and gives a warning message

I am a complete noob in scripting, but I need a script that will compare the sizes of two files and give out a warning if one of those files is 10% bigger than the other. So far, I came up with this :...
1
vote
1answer
179 views

Bash variable interpolation confusion

I'm trying to understand Bash variable interpolation. I want to use readlink to show the path a symlink points to. If I use a string it works. $ echo "$(readlink -- ~/.gitconfig)" /Users/jord/....
-1
votes
2answers
557 views

Sorting files by “line content” frequency - print duplicates

Imagine there is a file - a b b b b c c d d d I want the output to be sorted based on frequency (I want the duplicate lines to be printed as well) as - b b b b d d d c c a
0
votes
0answers
67 views

Error opening GTKWave: “The domain/default pair of (.GlobalPreferences, AppleLanguages) does not exist”

So I downloaded a program called GTKWave using the following commands: brew tap homebrew/cask brew cask install gtkwave The gtkwave.app is in my Applications folder. A symbolic link gtkwave was ...
0
votes
0answers
286 views

Handbrake batch convert script assistance to set output extension specified by the official presets

With the help of numerous discussions on SE network and other places I finally managed to a working script that works well except the Matroska presets. I understand the problem is the script itself, ...
1
vote
1answer
208 views

How to use return value of a Bash command such as “ifconfig” to be used as an argument for an if statement in Bash script

I'm relatively new to Bash scripting but I'm very familiar with Python and many Bash commands. I was wondering if it's possible to use a command such as ifconfig eno1 and use the output as a condition ...
0
votes
0answers
43 views

Sed doesn't works over variable

I'm trying to combine find -exec command with a function that should strip the relative path and copy to another place (with same tree). The script looks like the follows: function makeLinks(){ ...
0
votes
1answer
56 views

Script for deduplicating files and folders with a particular suffix

A botched OneDrive restoration has left me with many files and folders with a " (1)" or " (2)" suffix. I would like a script (Bash is fine as I have MinGW + Cygwin, or PowerShell) that would parse ...
0
votes
0answers
30 views

Shell script to get ip of list of domain names: connection timed out; no servers could be reached

I have the following script from some sources in the web that should execute command host to get the IP address of a domain name in file myfile.txt. The script is: #! /bin/bash while read hostname; ...
0
votes
1answer
70 views

/etc/profile.d script interfering with a service starting, and considerably delaying ssh availability after reboot

I have created a script in /etc/profile.d (centos6), not related to puppet in any way, instead it just copy's some files to a users dir. Somehow, on a puppet enterprise master server, this script is ...
0
votes
1answer
107 views

How to start an interactive bash with su

I do not have sudo su over a username, however I have its password. I want to have an script that passes the password and gives me an interactive bash. I have tried this: echo mypassword | su - ...
0
votes
0answers
43 views

how make multiple redirection with command and fifo

I need to write a bash script in a linux machine with the follow redirection. echo commands > cmd_receives_commands > fifo > awk_parser > tcp_socket I verified that for the "tcp_socket" ...
0
votes
0answers
72 views

Find command script, gpg decryption, and proper shell path

I wrote a script to encrypt and decrypt symmetrically with find, gpg and inotify. paste a file to samba server, I rename it Encrypted-*, inotify triggers find & runs the commands, encrypts, ...
0
votes
1answer
23 views

Bash list/process files in a specific order

#! bash I've tried a few things I've seen on google but nothing seems to work. I don't see how this should be a high challenge but maybe it just isn't possible? I have a list of files in a folder ...
2
votes
1answer
48 views

Duplicating stderr output and merge with stderr in bash without changing order

I want to write both stderr and stdout to a log file, and print stderr to the terminal (or default output device). Motivation: I have a command in my crontab, and I want to log all of its output to a ...
0
votes
1answer
194 views

can't increment a variable inside a loop in a bash script

I am running a bash script in Ubuntu 18.04. The script needs to run a python script 10 times. I did the following testbash.sh script: #!/bin/sh count=1 while [ $count -le 9 ] do python /home/e/...
0
votes
1answer
283 views

How create name value pairs array from command line arguments?

Consider example: bash myScript.sh --name1 valule1 --name2 value2 Inside myScript.sh: java -jar someJar. jar --name1=valule1 --name2=value2 E.g. array --name1 valule1 --name2 value2 needs to ...
0
votes
3answers
1k views

Groovy syntax not working with backslashes

I'm trying to use a backslash on the command bellow at groovy syntax: find /path/folder-* -type f -iname "file*" -exec rm -f {} \; When I try to build this command on a Jenkins pipeline give me an ...