Questions tagged [scripting]
A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.
4,566 questions
0
votes
4
answers
71
views
Mount a partition from a script unless it is already mounted
I would like to mount a partition of an external hard drive from a script using
udisksctl mount --block-device /dev/sda1
and in the end of the script I would like to unmount it.
However, it may ...
5
votes
1
answer
332
views
Making `apt-get` read answers from stdin on graphical Ubuntu
This may seem like a question asked, but I have yet to find anything that works and I start suspecting it may be a bug in apt-get…
So, I have a python installer wrapping around apt-get, whose relevant ...
1
vote
1
answer
40
views
Do I need to define an absolute path to be able to compile the DRM / Panfrost subtree code of JSM on the RockPro64 / Khadas Edge-V / RK3399?
I'm trying to compile the drm-subtree of JSM because I want to enable the panfrost driver on the RockPro64 / KHADAS EDGE-V / RK3399. The code is here:
https://github.com/jsm222/drm-subtree
He improved ...
2
votes
4
answers
147
views
Is it possible to silence the initial call in xtrace, when BASH_XTRACEFD is set?
#!/usr/bin/env bash
exec {BASH_XTRACEFD}>./xtrace.log
declare -p BASH_XTRACEFD
set -x
{ : "how do you hide this in ./xtrace.log?"; } 2>/dev/null # fail
# { :; } "${BASH_XTRACEFD:-...
1
vote
1
answer
42
views
command not running from kde powerdevil
made a simple command to change my power mode to "balanced-performance" (lenovolegion power mode for custom mode), works fine in terminal and running the file, but when listing it as a ...
3
votes
7
answers
1k
views
How to list only the last name.partXXX.rar file?
In Linux in a folder, without subfolders, there are many files like this scheme.
I list them with ls -1.
1yBWVnZCx8CoPrGIG.part01.rar
1yBWVnZCx8CoPrGIG.part02.rar
1yBWVnZCx8CoPrGIG.part03.rar
...
0
votes
7
answers
2k
views
Is it possible to protect a bash script against a hostile environment?
Bash allows to export read-only variables and functions to the environment.
Also, when a bash script is run, Bash sources the file BASH_ENV was set to, unless invoked with -p.
How do you protect ...
10
votes
7
answers
1k
views
Check if multiple files exist on a remote server
I am writing a script that locates a special type of file on my system and I want to check if those files are also present on a remote machine.
So to test a single file I use:
ssh -T user@host [[ -f /...
2
votes
1
answer
79
views
socat filter and replace character for modbus ascii
The goal is to get modbus ascii working with a Wallbox from ABL.
So I placed a RS485 to TCP converter in the box, created a pseudo tty for my application and got the wrong frame.
The answer starts ...
1
vote
1
answer
102
views
Process some Folders and format the output
In Linux there are some Folders.
I want to process each of this Folders with the program myprogramm.
I get a list with ls -1 or much better, sure only Folders with:
find . -maxdepth 1 -type d -printf '...
0
votes
3
answers
608
views
What are the secure ways to use credentials in bash scripts?
I have a third-party service. Its API and credentials let me scrape service data on my local Linux machine. I want to use this API inside a bash script and launch it via cron, but I don't want to ...
0
votes
1
answer
129
views
How to match exact string? [duplicate]
I tried this
grep -rn "application_config_project" .
I got many
application_config_project_name = f"{app_acronym}-application-config"
github_application_config_repo = ...
0
votes
0
answers
52
views
Finding and removing duplicate files: Integrating a unix script with an application that opens a file for viewing?
Does anyone know of an open source application or perhaps how to integrate an existing find dupes script with some OS tool (emacs, vim, Finder.app, mc, etc...) to open a file before marking that file ...
0
votes
5
answers
214
views
Rename a set of files according to a specific scheme, with rename back option
In Linux in a directory there are files, ls -1 shows me this output :
file1.1-rvr
file1.2-rvr
file1.3
file1.4-rvr
file1.5
file1.6-rvr
file2.1
file2.2
file3.1
file3.10
file3.2-rvr
file3.3-rvr
file3.4
...
0
votes
2
answers
97
views
In a text file, finding and deleting lines including (e.g.) "#', or a word? [duplicate]
I am using Ubuntu Linux and Mageia Linux...
I wish to do the following:
in a text file (sample.txt), find and delete every line comprising the symbol '#' (or '?') or a specific word (e.g. 'mobile')
...
1
vote
2
answers
93
views
How to specify ELF shared objects in `LD_PRELOAD` if their path contains a space character?
Paths to ELF shared objects in LD_PRELOAD cannot contain spaces, as space is one of the two list separators, and it cannot be escaped:
LD_PRELOAD
A list of additional, user-specified, ELF shared ...
0
votes
1
answer
96
views
Automating the Pause and Resume of a program at regular intervals
My program involving Numerical Mathematics takes a long time to run (12-15 hours). I usually leave it running overnight and check the results the next morning. However, I want to prevent the over-...
-1
votes
3
answers
210
views
How do I test the existence of a directory accessible only as root?
if [ -d directory ]; then
echo "directory exists";
else
echo "does not exist";
fi
tests for the existence of directory by virtue of the -d test.
Does the -d test return the ...
0
votes
0
answers
70
views
Why are quotation marks and backslashes not working as expected in variables? [duplicate]
I'm trying to pass a command through to ffmpeg, but I'm struggling to get it to work with spaces in the name.
I've tried this:
filters="-vf subtitles='$filename.$format':force_style=Fontsize=24&...
4
votes
2
answers
682
views
Bash script: performance comparison of file reading methods
I'm trying to find the "right" way to read files line-by-line.
I have been using for for line in $(cat "$FILE"); do for a while, and I really enjoy its clearness.
I know that while ...
0
votes
1
answer
409
views
SLURM error and output files with custom variable name
I'd like my log files to be named after a variable. Since this isn't possible:
#SBATCH --output some_software.${var}.out
#SBATCH --error some_software.${var}.err
I came across this work around but ...
0
votes
0
answers
98
views
Opening Vim under script(1) breaks output. Can Vim detect script?
Opening vim while recording with script causes script to go wild (my screen starts filling up with a bunch of crap, some of which says "script", and I also believe it is colored neon green).
...
-3
votes
1
answer
151
views
Creating in Linux files in GB or MB range by various size by read a file [closed]
In Linux with Bash, there is the File numbers_in_one_line.
In this file there is only one line with several numbers, all separated by spaces.
These numbers are the value in bytes for creating files ...
0
votes
1
answer
101
views
How to create splittet random files and join them with dmsetup
In Linux in Bash, there is a script, a part of the script is this
while true ; do
echo
awk -v x=$(<"$TEMPDIR"size_container_in_byte) -v n=$(<"$TEMPDIR"parts) 'BEGIN{...
3
votes
3
answers
464
views
Running a script based on raw events from a specific HID?
bit of a strange issue for you. I have an old 2-in-1 laptop tablet thing that works well enough, except the driver for the touchscreen occasionally crashes, leaving it unusable. I have a simple script ...
-7
votes
2
answers
166
views
How can I pick random items from a list, but some more often than others, in a Bash config file? [closed]
In Linux, using Bash, I have two scripts:
script.sh is the main script, and
script_config.sh is the configuration for script.sh.
In script.sh, I do source script_config.sh to load all the config ...
1
vote
1
answer
102
views
How can a bash script determine how it was started? [duplicate]
I am running various scripts on Debian 12.X currently with the following bash:
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)
I have the following methods/options to execute the script.
...
0
votes
2
answers
178
views
Bash script, execute while command isnt outputting value
I'm trying to write a bash script (very new to writing them btw) on a Linux system, and I basically want it to execute a command every say 5 seconds while another command isn't outputting a value.
So ...
-3
votes
1
answer
66
views
Rename files, remove the first four signs [duplicate]
There are many files in this format:
IMG_20240717_191421.jpg
IMG_20240620_165358_BURST001_COVER.jpg
IMG_20240624_173513_2.jpg
how can they renamed in Linux in Bash to:
20240717_191421.jpg
...
0
votes
5
answers
174
views
Move/mark files and the associated-part too
There is a folder with many files in it:
112.mkv
123.md5
123.mkv
221.mkv
467.mkv
aa1.mkv
abc.md5
abc.mkv
bbc.mkv
dde.md5
dde.mkv
ggh.mkv
....
xxy.md5
xxy.mkv
xxz.mkv
How can I move .md5 files and the ...
1
vote
2
answers
264
views
How automatically open a URL after rebooting in a Debian desktop?
How automatically open a URL after rebooting on a Debian desktop?
1- Running the command by terminal:
xdg-open http://homeassistant.local:8123
OK it works and opens the URL above
2- creating any ...
6
votes
4
answers
622
views
get chain of users created by chaining su calls
While administrating a linux server (a Debian server, for instance), I often switch users. Sometimes, I will chain multiple user switches together:
aluriak$ sudo -s
root$ […]
root$ su aluriak
aluriak$ ...
0
votes
0
answers
48
views
HTPC: Xbox Controller binding home button to Script and original function
Situation: I have a HTPC running Nobara linux (flavor of Fedora) and I have an Xbox controller that is connected to it and will wake it from sleep.
Problem: HDMI-CEC is not supported by my hardware. ...
-1
votes
1
answer
167
views
Best tool to convert xlsx to csv
I need to install something that allow me through a script bash or if I can do it without install any external tool it would be great.
The thing is I read about csvkit but is a tool of python and i ...
-1
votes
2
answers
106
views
set output into variable from grep from input variable
whats wrong with this bash script:
acme2=$(dig txt @$1 _acme-challenge.$1.de)
acme3=$(echo $acme2 | grep "^_acme") ...
1
vote
1
answer
218
views
Patch line receives error
I have a script and patch that I took somewhere to compile an image (linux build root) and I added some lines and now I got one error during patch, the error is like that:
diff --git a/package/base-...
0
votes
1
answer
139
views
I need to run script on remote server which require root access using sshpass and its failing
I need to run script on remote server which require root access using sshpass and its failing with eror script not found. I ran below command.
sshpass -frhelpass ssh user@IP 'echo mypass | sudo -S &...
3
votes
2
answers
158
views
How might I make this expect script consistently work as expected?
I use an interactive wallet spectre-cli of Spectre, a coin similar to
Kaspa in its design.
When I manually want to get the balance of my wallet I need to run
spectre-cli and then connect, open
from ...
5
votes
4
answers
623
views
Getting multiple variables from the output of docker exec command in a bash script?
I would like to execute a script on a host machine (script_on_host.sh), which then reaches inside a docker container in order to grab some data using a second script (script_in_container.sh). The data ...
3
votes
2
answers
124
views
Simulated Execution of Redirections
My shell is the Korn Shell, but I think the problem (and its eventual remedy) applies to other shells as well.
I usually build a "simulation mode" into my scripts to test potentially ...
1
vote
1
answer
187
views
Open pdf files by terminal with fzf and fd
with the following command line, which I turned into an alias, I would like to open the pdf files from my terminal.
alias pdfLoad="fd . '$HOME/OneDrive/DBCalibre' -t f -e pdf | fzf | xargs -0 -I ...
1
vote
1
answer
86
views
What is expr doing when processing arrays?
I have a BASH script problem that I've narrowed down but I can't understand what I'm seeing. I want to get a substring of an array in a succinct way. Here's what I'm seeing in bash, with 'set -x' so ...
1
vote
1
answer
73
views
I have made a startup script but it only can run as an user, not root, how can I make it work?
there are 4 scripts that should be started after reboot as user "appian":
/opt/appian/appian_home/services/bin/start.sh -p Password -s all
/opt/appian/appian_home/data-server/bin/start.sh
/...
2
votes
1
answer
182
views
select in a script
In Linux in Bash in a Script i use this:
#!/bin/bash
while true; do
while true; do
read -r -p 'enter number [4-999]: ' num
if [[ $num =~ ^([4-9]|[1-9][0-9]{1,2})$ ]]; then
...
0
votes
3
answers
241
views
Parsing data in Bash: adding commas after each string
I am attempting to generate a file that I can append to visudo. The task itself is not too important as I'm just trying to dig a little deeper Bash. My current script looks like this:
#!/bin/bash
...
0
votes
1
answer
61
views
Installing lunarvim from script with the questions answered
On their website, you're asked to install their program via a script instead of downloading it via a package repository like most regular apps do.
LV_BRANCH='release-1.4/neovim-0.9' bash <(curl -s ...
-4
votes
2
answers
138
views
How to write in Linux in Bash in shellscript a part that can do something like this
How to write in Linux in Bash in shellscript a part that can do something like this
enter a number
must be in a range from 4-999
if not, ask again to enter
enterednumber * 5 * randomnumber [1-9] (...
0
votes
1
answer
353
views
Startup script won't run on boot
I've been trying to get a very simple startup script but no matter what I try I can't get it to actually run on boot. For simplicity sake I while testing I just wanted to open my Browser, which works ...
0
votes
1
answer
230
views
how make it autostart "startx -- -nocursor" in opensuse/openbox?
i want make it automatically to start with no-cursor: startx -- -nocursor this is worked but this is command..i want to autostart to user: kiosk..
(but i don't want to use "unclutter")
i'm ...
0
votes
1
answer
44
views
Are there any editors for script command that allow to fix typos?
I want to record a gif with interaction of my Linux tool (REPL), but it's time consuming to make it perfect without any mistakes when I type the commands.
So I was wondering of using script command ...