Stack Exchange Network

Stack Exchange network consists of 175 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.

0
votes
1answer
23 views

Shell Scripting Interactive Functions

Newbie to Shell scripting... I'm looking to have an interactive setup script. It will ask questions and require the user to make a selection before continuing to the next step. The problem I'm ...
0
votes
0answers
20 views

Why does a single process have many PIDs?

#!/bin/bash #fauz-pas num=1 bool=0 while [ "$bool" -eq 0 ] do ps aux | grep "$1" | grep -v "color" | grep -v "grep" > isahawk crazy="$(awk -F" " '{print $2}' isahawk)" ...
0
votes
0answers
19 views

for loop serialization and wait

I need to copy over x amount of directories using aws's snowball client. However, since the client hogs quite a bit of resources, i'd like to serial each execution so that it runs 1 at a time and will ...
0
votes
2answers
27 views

watch aliased cmd doesn't work

When I do $ watch kubectl get pods it works fine but on doing: $ alias p0="kubectl get pods" $ watch p0 gives an error: Every 2.0s: p0 sh: p0: command not found It looks like watch is ...
1
vote
1answer
24 views

How do I use a hexadecimal range when downloading multiple files in Curl?

I know that I can download a sequence of files using decimal numbers in curl: curl site.com/file[000-100].jpg -o "file#.jpg" But I need to download a hexadecimal series of files named file0x000 to ...
0
votes
1answer
49 views

How can I run a script through crontab with a value input for the script?

im trying to run a script with crontab on linux as follow, i create a script for a incremental backup. when i excecute in the command line/usr/bin/diego-backup.sh complete the script creates a ...
0
votes
2answers
32 views

Is it possible to use GPG to decrypt a file to stdout without parasite info (such as key used, prompt for password)

I've been searching for days, but so far, no luck. Maybe I'm searching with the bad keywords. I need to use GPG to decrypt encrypted file in memory, without writing decrypted contents to disk. A ...
0
votes
1answer
19 views

Issue while executing IMPDP command from local server on remote server

I have two linux servers A(local) and B(remote) having SSH key set between them. I am trying to do the following in my shell script (.sh file) Do EXPDP on local server A, generate the .dmp file. ...
0
votes
2answers
17 views

Which directory should custom git bash scripts be saved to in windows so that they can be called from anywhere?

I am learning how to use git bash for Windows and I want to start writing scripts to automate some of the git tasks I do. But where should I store the .sh files so that I can call them from any ...
0
votes
1answer
30 views

Bash scripting: how to iterate through all drives?

I have buildroot readonly bootable image, which is normally loaded via TFTP in PXE enviroment. Filesystem in unpacked into ram and remounted as rw. And accidentally I wished to boot it from a USB ...
0
votes
0answers
25 views

How to get rid of spaces in sh for loop? [duplicate]

I am trying to iterate over a list of files but there are spaces in their paths... This is the code so far (in shell/Bash): for i in $(find path -name pattern); do dosomething "$i" ; done Because of ...
0
votes
2answers
63 views

Automating task

I need to run that command at the boot: xcape -e 'Control_L=Escape'. So I write a script called swapkeys.sh: #!/bin/bash xcape -e 'Control_L=Escape' And I make it executable with: $chmod +x ...
2
votes
1answer
32 views

Conditionally dry run a command block with BASH heredoc

I wanted to have something as simple as that in my script: set_dryrun() { BEGIN='cat << EOF' END='EOF' } [ "$1" == "-dryrun" ] && set_dryrun ${BEGIN} ls -l ${END} So that ...
0
votes
1answer
29 views

Run a Script Each Time Terminal Window Opened

So I have written a simple bash script to run a program called "cmatrix" everytime a new terminal window is opened. I have changed the permissions on the file so it is r-x for everyone, and verified ...
0
votes
2answers
61 views

Bash shell script: recursively cat TXT files in folders

I have a directory of files with a structure like below: ./DIR01/2019-01-01/Log.txt ./DIR01/2019-01-01/Log.txt.1 ./DIR01/2019-01-02/Log.txt ./DIR01/2019-01-03/Log.txt ./DIR01/2019-01-03/Log.txt.1 ... ...
0
votes
1answer
34 views

How can I modify this bash script to output to a specific folder?

I am modifying a script which gpg encrypts all files in a folder. As it currently stands it outputs the modified files to the same folder that the input files are in. However I would like to output to ...
1
vote
0answers
50 views

Umlauts in terminal-notifier MacOS

OSX-Mojave. I have a simple script: #!/bin/bash key="..." text="$(echo $(pbpaste) | sed "s/[\"\'<>]//g")" translate="$(/usr/local/bin/wget -qO - "https://translate.yandex.net/api/v1.5/tr.json/...
-1
votes
1answer
34 views

edit bash script to truncate leading numbers on files when creating folders

for file in *; do if [[ -f "$file" ]]; then mkdir "${file%.*}" mv "$file" "${file%.*}" fi done So I will have tons of files that will look like "012345_randomnameoffile.pdf" and I want to ...
0
votes
2answers
79 views

How can I change the text after the @-sign in my terminal? [duplicate]

How can I change the text after the @-sign? I don't know what it means. It says DESKTOP-HMEEP40.
1
vote
1answer
38 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
40 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
52 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
48 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
39 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
260 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
117 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
45 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
64 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
15 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
62 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
764 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
28 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
63 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
66 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
180 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
102 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
57 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
49 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
111 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
138 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
193 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
225 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
42 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 ...
1
vote
0answers
437 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
42 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
2k 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
534 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
38 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
488 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}' ...