Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

Filter by
Sorted by
Tagged with
0
votes
2answers
15 views

Trying to make directories using brace expansion

Maybe this is a pretty silly question. I'm a beginner at bash scripting and I'm not able to properly while trying to execute the command. #!bin/bash noise={5,10,15}dB mkdir $(echo $noise) I want to ...
-1
votes
2answers
20 views

Changing permission on multiple files within bash

I am trying to write a script to change the permissions of a number of other scripts, in multiple locations, to be executable. I've searched all over and can't seem to get the syntax correct. It is ...
0
votes
2answers
30 views

failed to set environment variable - what happened?

I tried to set an environment variable and made an error in the input due to a new keyboard I'm not used to. In the input (and output) below, did I accidentally start a job of some kind? I'm ...
0
votes
1answer
41 views

bash: cannot create temp file for here-document: No space left on device

While this may be the same question as others have asked with the same issue I am hoping someone can help me out regardless as I am out of my depth. I have a Seedhost server with Swizzin installed ...
0
votes
0answers
46 views

Why does the second echo statement not get run?

Working with libbitcoin BX. Running from the commandline, this produces the expected output: [user@laptop bin]# ./bx seed 7312e7b4adcf0c94ef45071f34884a0b3dedd3ac9fffc593 [user@laptop bin]# However,...
0
votes
1answer
42 views

Move 20,000 files from one directory sequentially and so on

What I am trying to accomplish is I have a directory with lets say 176,000 files. I want the script to split the 176,000 files into folders with lets say 20,000 files each and the last one containing ...
1
vote
1answer
21 views

inotify: Echo which file has changed in directory

I've just learnt how to constantly check if file is modified: while inotifywait -q -e modify filename >/dev/null; do echo "filename is changed" # do whatever else you need to do done If I ...
0
votes
1answer
43 views

How to bash a Copy files from large text file with source and destination values in it?

I'm trying to write a script that will copy all file listed in a text file, around 3 million lines, which contains two columns, the source and the destination with a new filename: path/to/source/...
0
votes
1answer
18 views

Problem when running multiple Gunicorn scripts using systemd

I want to automatically run multiple gunicorn servers which is generally are flask servers whenever my system reboot or start and also in background The problems Even though I could run the ...
0
votes
6answers
70 views

Bash script to check for file extentions in directory

#!/bin/bash #Number for .txt files txtnum=0 #Number of .sh files shnum=0 for file in "SOME_PATH";do #if file has extension .txt if [[ $file ==* ".txt"]] then #increment the number of ....
-1
votes
1answer
27 views

Match system path with awk in if statement

I am trying to catch if the file system was mounted on a directory tree with: mount | awk '{ if ( $3 == /mnt/pxe ) print mounted }' But the string is not catched even though mount exists. The mount ...
0
votes
1answer
35 views

Encode file content and echo it as one line

I am trying to echo the content of key and certificate files encoded with base64 so that I can then copy the output into other places. I found this thread: Redirecting the content of a file to the ...
0
votes
1answer
42 views

set file as latest file

I'm downloading the file every 30 minutes. I compare this file to a manual file that I was created (for first time downloaded and manual file are same). If downloaded file have some difference then ...
4
votes
0answers
59 views

What are exactly shells levels?

My understanding of shell levels and sub-shell was that: Sub-shells are forks (but not execs) of the shell process created by ( ... ) constructs. $SHLVL counts shell execs. $BASH_SUBSHELL counts sub-...
0
votes
1answer
42 views

How can I make the name of my output file the same as the input one in a bash script?

I am working with files that are named after dates, such as "2020-02-24-16-13.h264". I am trying to get MP4Box to process all of these files in a bash script, but I can't figure out how to name the ...
0
votes
1answer
42 views

Remove argument from $@ if it is an option

I have a script where I need to loop through the arguments passed, and if an argument starts with - I need to put it in a string opts and remove it from $@. This is what I have so far opts="" for arg ...
-1
votes
1answer
19 views

Unable to pass an argument to a function

For my homework, I need to have a function in my code to earn extra credit. I have a script that takes the second argument and makes a folder from what is passed. The code works with the argument ...
1
vote
0answers
21 views

What is different between piping and here-strings for the `read` builtin? [duplicate]

I thought that piping from echo was equivalent to here strings, but the REPLY variable of the read builtin command is only set (or in scope I guess) when using here strings: echo foo | read;echo $...
6
votes
2answers
432 views

Is possible to define a bash script to run interactively by default?

I have written some scripts and stored them in my ~/bin folder. I'm already able to run them just by calling their title during a shell session. However, they aren't running interactively (I mean, my ~...
0
votes
1answer
55 views

Suppose I have 10 files in a parent folder called abc

1fyr.pdb 1r0p.pdb 1r1w.pdb 1shy.pdb 1ssl.pdb 2g15.pdb 2rfn.pdb 2rfs.pdb 2wd1.pdb 2wgj.pdb I want to copy certain lines from those .pdb that starts with the word ATOM and create a new file with a new ...
1
vote
0answers
10 views

Usage of cvlc with coproc

I'm trying to feed to file descriptor .mp3 files the with the dummy interface of vlc, i.e., cvlc, in order to add to a playlist on the fly or override the entire file descriptor with new data (new ....
9
votes
4answers
1k views

Renaming a file in Bash using regular expressions

I have a file named 35554842200284685106000166550020003504201637715423.xml and I simply need to rename it to 42200284685106000166550020003504201637715423.xml (remove everything before the last 48 ...
0
votes
1answer
19 views

Stripping portion of file names

Example files: 1_this is_file one-xhdjsnsk.mp4 2_this_is file two-hdksbdg.mp4 3_this is_file three-hsislnsm.mp4 4_this is file four-gwywkkd.mp4 How do I strip everything from '-' to '.' so the ...
0
votes
1answer
31 views

find does not work, locate does

So I have this bit: systemctl list-unit-files | grep --ignore-case networkmanager | grep --ignore-case service | cut --fields=1 --delimiter=" " Which gives as output: NetworkManager-dispatcher....
2
votes
2answers
45 views

Remove all files/directories except specified ones in multiple levels

Is it possible to do the below with one line? shopt -s extglob rm -r !(folder1|file1|folder2) rm -r folder2/!(subfolder) rm -r folder2/subfolder/!(onefile) For example, something like this? rm -r !...
0
votes
1answer
26 views

Give a “non-user” account access to ssh

I'm running a python application (a monitor) called Tautulli. This application are running under the user tautulli. Now, the app is performing different functions depending on other stuff. The ...
1
vote
2answers
39 views

bash shell history mechanism not reliable?

My typical work flow at the bash prompt consists in typing commands and retrieving them using the Ctrl+R "literal" mechanism. I have noticed over possibly the last couple of years that there are ...
0
votes
1answer
29 views

How do I change a value in a line of an existing script to reflect the (numerical) folder name?

I'm running a job where I have multiple folders (labelled 0 to 41), each containing an identical script which need the ninth line edited: #SBATCH -J aXau19 X should correspond to the name of the ...
0
votes
2answers
60 views

Edit script to email output?

I'm basically trying to put two scripts I found online together. The first, in two parts, checks if a directory exists, if not creates it then goes on to take a picture through the webcam if an ...
-1
votes
0answers
26 views

No history and path/bash completion on some systems

For some reason, I don't have a history of commands in the terminal and neither can I complete paths or commands. Pressing arrows also show symbols like ^[[D and ^[[C. The shell is bash and .bashrc ...
-2
votes
0answers
65 views

Track daily, weekly, monthly computer usage? [closed]

I am looking for a simple program to run in the background and track my computer usage (number of hours) with simple reporting for daily, weekly and monthly time frames. My environment: Fedora ...
0
votes
0answers
13 views

iotop shows no disk write activity for cp command writing to USB HDD

I have the following cp command running: cp -avR source-dir/ /media/username/USBHDD/ source-dir contains a mixture of small (kilobytes) and large (gigabytes) files. I'm running iotop like so: ...
0
votes
0answers
32 views

Using timeout to escape a command also stops the for loop it is inside

I have a script that uses the package airodump-ng to do some wireless monitoring. It iterates through a list of mac addresses and scans them. I am using timeout to send an exit code to airodump ...
0
votes
1answer
31 views

How to pass a subprocess to a command with bash

I'm trying to pass multiple outputs to a command using sub-processes. This is (a shortened version of) my command: cat "$1" one=cat "$1" The output of command <(echo "foo") is foo /dev/fd/63: ...
8
votes
1answer
100 views

Can I customize the “You have new mail” message

I'm trying to modify the You have new mail message that is shown below MOTD when you login via SSH. My goal is to make that message more visible (bright color would be great) so it gets my attention ...
0
votes
0answers
43 views

bash: problem with looping through array of directory paths

Array arr1 contains two directory paths extracted with find command: echo "${arr1[@]}" /archive/logs/2020/02 /archive/raw/2020/02 I am testing if I can loop through the array arr1 with this code: ...
4
votes
5answers
192 views

Move specific line from a position to another

I'm using the ubuntu terminal, I need to move a specific line in a file ( 11th position ) to the first line and then transfer the final result into a new file. The original file contains hundreds of ...
18
votes
1answer
2k views

What does <$( )> do

I saw the syntax in this question: Birth is empty on ext4 sudo debugfs -R "stat <$(stat -c %i /home/user/path/to/file)>" /dev/sda5 I know command substitution $() and ``. I kind of vaguely ...
0
votes
1answer
55 views

Trying to run .sh script from curl

I am having trouble running a shell script. So for context, I am using bash <(curl -s -L https://test.com/detect.sh) --argument1=true When I run this command in my Ubuntu environment, it works ...
1
vote
1answer
72 views

How to run a previous command (that uses an alias) with sudo, both in command line and with an alias

(Note: This is not a duplicate question.) On the command line, you can simply use sudo !! to run the previous command with sudo. However, how would this be done if the previous command uses an alias? ...
0
votes
1answer
52 views

Run two commands one after another in bash

I am facing problems running two commands one after another in bash. When i run source2() { '/home/ds/Documents/scripts/Untitled Document 1.sh' && imgpath="$(ls | grep "^unsplash")" } ...
1
vote
1answer
23 views

Script that e-mails predefined message to multiple users

I want to create a script that asks the user for his username and check if its valid by verifying the user home directory exists. If the username exists it should send an email to the user from a ...
2
votes
0answers
95 views

apt-get update no longer works after rebuilding corrupted PATH variable

I royally screwed up my PATH variable last night, thankfully a user called Icarus helped me rebuild it here. However it's not fully fixed and I receive the same (or maybe very similar) error that I ...
0
votes
0answers
27 views

Delete at most one file matching a pattern

In bash, I would like to remove the first file which conforms to a pattern (say *.txt). rm *.txt Will remove all. Is there a simple way to just remove the first?
0
votes
1answer
83 views

Bash, command as function is not working, but manually is OK

I need save mysql dump from remote machine to file on local, so connect via ssh to remote machine, run mysqldump on remote machine and save it to file on local, where script is running. I have 2 bash ...
1
vote
0answers
21 views

HTTP logs using tcpflow with grep, redirecting to a file don't work (empty file)

I want to log some specific HTTP requests that have a keyword, that are coming to a specific port. tcpflow works fine, but I can't write filtered results to an output file. I don't understand why ...
-1
votes
3answers
53 views

Get a part of a folder name as variable

I have 2 folders names that have 2 ids like "ABFD00" and "KASD02". Now I need a little part of the folder as a variable (00 and 02) to use it in a command. Like: sapcontrol -nr $sid -function ...
0
votes
2answers
52 views

How can i store commands as a variables and execute them randomly in bash?

How can i store commands as a variables and execute them randomly in bash? command1=" convert -size 2000x1000 xc:none -gravity center \ -stroke yellow -pointsize 50 -font Courier-BoldOblique -...
1
vote
1answer
16 views

How to set alarm/alert if my system cpu usage reaches a particular threshold?

I have written a shell scripting for monitoring the system CPU usage and memory usage. I need to know how to send notification to mail that my system reached particular threshold (example:- 90%). My ...
-1
votes
4answers
48 views

bash: trying to put the output of “find” into a variable by using “$()” but it does not work

The purpose of my script is to provide a full path to the last sub-directory, based on the value provided by the user input. For example, the following script: ./script.sh TICKET-1234 should output ...

1 2 3 4 5 375