Questions tagged [bash-scripting]
Bash scripting is making scripts in the Bash shell language.
937
questions
0
votes
0
answers
15
views
How to combine 2 rsync outputs into 1 command?
using:
neofetch --stdout |grep 'OS:'
OS: Kubuntu 22.04.3 LTS x86_64
Shell: bash 5.1.16
rsync --version
rsync version 3.2.7 protocol version 31
variables, SourceDisK1 src1 and destination ...
0
votes
0
answers
54
views
Perform lookup on two files
I have a csv file that get's SFTP'd to a RHEL box I have setup. It then gets transformed a little before another process SFTP's in and grabs it sending it off to be imported to a DB of a 3rd party.
I ...
1
vote
2
answers
125
views
How can I use Windows command line to delete all files in a particular directory that were created on a specific date?
I accidentally blew up a tarball on my PC and now have something like 2 million unwanted files in my Documents folder. Windows Explorer crashes if I try to use it to view the contents of that folder, ...
-1
votes
1
answer
105
views
Echo all the output from a ls command
I have the follow files in my folder:
a.jpg b.jpg c.jpg
And I have the follow script:
#!/bin/bash
echo $1
If I run:
script.sh $(ls)
My output is:
a.jpg
But I want to be:
a.jpg b.jpg c.jpg
So, Why ...
0
votes
1
answer
59
views
Complex find statement
Have a script that I use to purge old backup directories. All the directories are named YYYY-MM-DD. The backup directories have links in them as the backups are incremental using the rsync --link-dest....
0
votes
1
answer
53
views
rm not removing directory
Having a strange issue. Using a script to go through our backup folders and delete any folder not named like the 1st of the month (2023-05-01) and older than 60 days.
It works in the sense that it is ...
1
vote
0
answers
26
views
How do you set qpdfview display options in a bash script?
Pseudocode:
qpdfview **--continuous --2page-w-cover --zoom=167%** document-one.pdf#54
(or document-one.pdf#src:foobar.tex:42:0) & disown
printf ' \n \n Some nice message \n \n '
read -p "...
0
votes
1
answer
21
views
track filechanges on shared hosting account
So I like to keep track of added files but also edited files.
find /home/user/public_html -type f -mtime -6 ! -path '*/exclude1*' ! -path '*/exclude2/etc*' -exec ls -ls {} \; | mail -e -s "File ...
1
vote
1
answer
63
views
Incrementing of value not working inside "find"
I have a bash file that does a global update to files with a given name. I have used this script for several decades without any problems. I became curious as to how many files were being updated and ...
1
vote
1
answer
331
views
Ffmpeg: suppress warning when writing to a single image
Somewhere in the more recent versions, ffmpeg started printing this warning when I process png files:
ffmpeg -i "src.png" -vf "$vf" "dst.png"
The specified filename './...
0
votes
0
answers
24
views
executing bash script on rotation with iio-sensor-proxy
I have a Tablet-laptop where i want to disable a gnome extension when the screen is rotated.
Auto-rotation works via iio-sensor-proxy.
it would be stupid to poll monitor-sensor constantly for resource ...
0
votes
2
answers
62
views
Bash printf: what does format specifier %P mean?
The printf statement :
find directory1 -type d -printf "%P\n" | sort > file1
in the answer https://superuser.com/a/166322/856910 includes a format specifier %P. From the output of this ...
1
vote
2
answers
64
views
How do I run a bash script automatically everytime I hit CTRL + S?
I'm making frequent changes to a bash script and everytime doing "./demo_script.sh" is repetitive.
Is there any way that it can automatically execute as soon as I hit CTRL+ S on keyboard?
1
vote
0
answers
102
views
Sed editing of large text file much faster than native bash substring replacement?
I have a ~19MB text file which I would like to perform many find/replace operations on. I originally wrote the script to loop over inplace sed operations e.g.
sed -i "s|$pattern|$replacement|g&...
0
votes
1
answer
23
views
Adding a user to an ubuntu linux group within a shell script
I'm writing a bash script to set up a docker application along with configuration etc. It's intended to run in a fresh Ubuntu install and be fully automated - just hit return and wait (albeit ...
-2
votes
1
answer
125
views
Trap signal in Bash Terminal of linux
What it means to trap a signal?
How to trap certain signal by its name or ID in bash?
This below is the trap code. How to edit it so that it traps certain trap codes like 9, 20, etc.
#! /bin/bash
...
1
vote
0
answers
69
views
Running a bash script that calls R from within i3 does not work, but running it directly from the terminal works. Not sure if issue is i3 or not
I have a bash script that calls on R, and is mapped to a keyboard shortcut in my i3 config, like this:
bindsym $mod+q exec --no-startup-id test-r-not-working-from-within.sh
Here is a simple example ...
2
votes
1
answer
233
views
List only bottom level directories using find
So, let's say I use find to search a directory for folders.
find "/home/user/Documents" -type d -print
While this does list all the directories in said location, I only want to get the ...
0
votes
3
answers
142
views
How to check in Bash if there is a file with an asterisk it its name
I've got an error in a Bash script that creates files with an asterisk ("*") in the name. I do not want this, so I'm trying to test at various points in the script if such a thing exists ...
1
vote
1
answer
98
views
Can't input text in Bash function called with key binding
I have added a simple function to my .bashrc file and bound it to a key combination using the bind command. The function prompts the user for input using read, like this:
myscript() {
read -p &...
0
votes
0
answers
84
views
Clam av automation issues (not performing auto scan ) in bash script
To automate ClamAV and monitor a specific directory for new file uploads, including all files and folders, excluding encrypted zip archives from scanning, I attempted to implement inotifywait with the ...
0
votes
1
answer
52
views
Glob expression as an argument can not be printed
I am trying to write a simple bash script which would print the argument provided as an input to the terminal.
echo "${1-nothing}"
I have tried using $@ or without quotes. If I enter * as ...
-1
votes
1
answer
47
views
I need help finding the error in this bash script
I'm attempting to test my code, but I keep getting errors w/ everything I try. I will attach my code and the current error I am receiving. I am unsure what to change or adjust w/o changing the code ...
1
vote
1
answer
175
views
Can I and how to use `script` in a bash script
This must be the most frustrating research I've ever attempted (so far). So, there is script(1). I've been trying to add it to the start of a bash script I have (I was looking for a way to log every ...
0
votes
1
answer
56
views
Geany – display file path line
I’m a new Geany user. I code shell scripts on Linux.
How to display "files path line" like this Geany image below ?
I can't find any options in the Geany settings.
Do I need to install a ...
0
votes
1
answer
68
views
Ubuntu - Deleted service still working
I created an .sh file for my remote laptop that would play an alarm file through ffplay and send me a telegram message whenever the power plug got disconnected. The file worked great when I ran it in ...
0
votes
0
answers
44
views
Bash - compare file path to list of forbidden paths
I was using:
for file in $(find "$1" -maxdepth 10000 -xdev -ignore_readdir_race); do
to load files from the internal drives as a means of warming up the ZFS ARC. $1 is the starting ...
-1
votes
1
answer
116
views
I want to find one user using regex from the text file which is in json like format. Find the user with regex and remove it with surrounding text
Find the user from the below text (highlighted testUser)
define name{
name **testUser**
aliasName Test User
emailID ...
1
vote
0
answers
122
views
ssh.localhost.run tunnel configuration command on Shell
I am currently writing a shell script for automating.
Manually, I will create a new session ssh.localhost.run by input Tunnel information on PuTTY like this
Full steps:
host name "ssh.localhost....
0
votes
0
answers
576
views
How to take file name from yt-dlp and use it as ffmpeg output file name?
I'm trying to get the output name to be the same as the input name while using the pipe command in ffmpeg.
Example:
The file is called 1-Minute Audio Test for Stereo Speakers & Headphones [...
2
votes
0
answers
200
views
xss-lock turns the screen black before running the lockscreen script
In my i3 config I have this line to lock the screen using i3lock.
exec --no-startup-id xss-lock --transfer-sleep-lock -- ~/scripts/lockscreen.sh
The script checks if I am watching YouTube or ...
1
vote
1
answer
700
views
"read" not working if called inside bash while loop
Why the read function inside this while loop not working? if i uncomment echo (and comment read) it prints several times, but if the "read" is uncommented it just exits function. Same "...
0
votes
1
answer
35
views
How to transform nested subfolders into a single subfolders
Whats a good way of “collapsing“ subfolders of a specified directory into a single folders whose name is a join the subfolders?
So given this directory structure…
./zero.csv
./reports/r1/a/b/c/one.csv
...
1
vote
0
answers
89
views
How to generate help/usage description from getopt?
Is there a way to generate the "help" or "usage" message of a command from getopt?
Something like this:
ARGUMENTS=$(getopt ... -- "$@")
echo $(help "$ARGUMENTS")...
0
votes
0
answers
90
views
Bash script running with automator doesn't stay running
I've created an automator script to run Live server on the selected folder.
Although it's not returning any errors (or I can't see) It's not working either.
#!/bin/bash
~/.zprofile live-server --port=...
0
votes
1
answer
35
views
Assign to variable in BashScript
This command gets all the users from the logs. It works great
grep $srcIP $cFilename | grep "Username: " | awk -F"Username: " '{print $2}'| awk -F"," '{print $1}' | ...
0
votes
1
answer
171
views
How to know what file is currently playing in ffmpeg concat playlist?
I have a Docker Alpine Linux container with ffmpeg streaming bunch of video files to YouTube.
Videos are injected through ffmpeg -f concat -i mylist.txt where mylist.txt contains video file paths.
I ...
0
votes
1
answer
37
views
how to use 'sed' in bash to delete a line from a specfic point on?
so i have these lines for example:
name,lastname,[email protected]
name2,lastname2,[email protected]
i need to delete the '[email protected]' in every line
essentially i want to make sed do "delete ...
0
votes
2
answers
110
views
Highlight filename in "find" command
I have this command which works great
find . -type f -name *.txt -exec grep -li blah {} \;
Let's say the output will be:
/tmp/folder1/file1.txt
/tmp/folder2/myfile.txt
/tmp/thisfile.txt
If I was to ...
1
vote
1
answer
578
views
Connect to GNOME Online Accounts with commande line
I write a bash script who perform post-installation configuration of my Fedora Workstation.
I would connect my Nextcloud server with GNOME Online Accounts.
Is it possible to make that with command ...
0
votes
1
answer
440
views
Create a csv file
I want create a file with two tables.
For example:
I have this:
cat 1.log | cut -d: -f 9 | sort | uniq
teste
teste2
teste3
and i have other command:
cat 1.log | cut -d: -f 6 | cut -d " " -...
1
vote
1
answer
461
views
Why is the scale filter ignoring the out_color_matrix option?
I'm testing on an input that has none of its colour metadata set:
ffprobe -v error -show_streams "input.mp4" | grep color
color_range=unknown
color_space=unknown
color_transfer=unknown
...
0
votes
1
answer
174
views
tar: samtools-1.9.tar: cannot open: no such file or directory
I am trying to run the command to install samtools on ubuntu but I am facing a problem here whenever I try to use tar.
Input : /c/Users/Hamza Bilal$ tar -xvf samtools-1.9.tar.bz2
The Output I get ...
0
votes
1
answer
146
views
Bash script vs command line
I have started working on bash scripts.
I have just observed a difference between executing a command line and executing the same commands but inside a script. In particular the command line is:
for a ...
0
votes
1
answer
49
views
FFMPEG MultiPlex all video's to all audio's
(windows 10 64)
I have seen & read MULTIPLE (50+) answers to forms of this question but not for what Im trying to do.
I have a folder with 30+ short clips (few seconds each) mp4's
I also have a ...
0
votes
0
answers
27
views
I cant get the file to be read
I am trying to get the the read command to read from the file and put it in a directory. shellcheck says the program is fine, but I keep on getting a "bad file descriptor" message, and it is ...
1
vote
1
answer
437
views
Reload user's group in a script
I'd like to create a new group in a script, assign the current user to it, reload the user's groups and continue executing commands that require the new group.
In this related question I found nice ...
0
votes
1
answer
41
views
What are the diffferences between my bash while loops? [closed]
File:
cat csvfile
apple,1
orange,2
banana,3
Code:
head -2 csvfile | while read line
do
f1=$(echo $line | cut -d ',' -f1)
f2=$(echo $line | cut -d ',' -f2)
echo "$f1 -> ...
0
votes
1
answer
1k
views
Read from stdin while piping to next command?
How can you prompt a user for input, when the output is being piped?
> (echo -n 'input data: '; read TEST; export TEST) | echo "done: ${TEST}"
This does not show the "input data&...
0
votes
0
answers
19
views
I have simple script that i put in rc3.d and give it S99name but not running after reboot
#!bin/bash
echo "Hello World" >> /root/ispis.txt
I put these script in rc3.d and create sym link to init.d folder. ln -s ../init.d/hello /etc/rc3.d/S99hello. Here is look of rc3.d. ...