Skip to main content

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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
80 views

Linux Bash Script - Yes or No - read answer

little script #!/bin/sh cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 4 printf 'do you like this? (y/n)? ' read answer if [ "$answer" != "${answer#[Yy]}" ] ;then ...
user447274's user avatar
0 votes
0 answers
17 views

Need some help doing a file copying script [closed]

I am not a programmer, I can do basic scripting but this is very far from my skillset. I am setting up an HTPC settop box for a relative that has no internet at their home, no networking either. ...
TGOTR Tech's user avatar
1 vote
3 answers
36 views

Bash: Access variable with another variable [duplicate]

How can I access a variable with another variable, like this? varAble="Hello" varA="\n" varBable="World" varB="END" for part in A, B do echo var${part}ble ...
binaryBigInt's user avatar
0 votes
2 answers
21 views

How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep

I would like to overwrite a Django/app/settings.py text file using the Linux terminal command printf. The settings.py starts with docstrings comments, i.e. """some text"""...
Tommy Gibbons's user avatar
0 votes
0 answers
23 views

SLURM job script - why is the tmp local directory deleted before archiving can occur? How to prevent this?

I wrote a SLURM job script to run a computational chemistry calculation using the CREST program (part of the xtb software package). In the script, I create a temporary directory on the local storage ...
lay lay's user avatar
0 votes
2 answers
78 views

How to write an alias or bash script that renames a single file using the same syntax as the `ren` command of Windows?

I am a long-term a Windows user, so I find the syntax of the ren command both simple and convenient: ren C:\pathTo\myFile\oldFileName.txt newFileName.txt I want to be able to use the same syntax on ...
ps.pf's user avatar
  • 3
-4 votes
3 answers
75 views

show which of a list of filenames do not exist in a given list of directories

I have a long list of filenames like 20231121_150111.jpg... in a text file (one filename per line). And another list of directories. Those directories contain files. How can I check and show which ...
user447274's user avatar
1 vote
0 answers
25 views

Running a program/script before a user logs in on RedHat Linux GUI

I am looking to run a script prior to a user being able to log in on the GUI. Its a basic script, do you accept Ts&Cs Y/N, enter user name, data is captured and stored. Then once complete takes ...
K_Sparky1029's user avatar
5 votes
5 answers
739 views

how to format a text file in bash with dots from right

I have a file on a Linux system with various numbers, all on a single line (numbers_in_one_line.txt): 1941102556 1750145810 2604905 7000793682 5160065824 3000350768 6449300295 3046118928 12693055728 ...
user447274's user avatar
-3 votes
1 answer
88 views

How to split a number into unequal parts in Bash

Hypothetic example: There is a number that I will split into x parts (smaller numbers, in a range you see in the example). I need a way, ideally a one liner for the Linux Bash, to split a large number ...
user447274's user avatar
0 votes
1 answer
114 views

ShellCheck does not detect error? How to fix my snippet?

I likely have syntax errors in the following (POSIX) shell snippet: #!/bin/sh if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; elif tput AF >/dev/null 2>&1;...
Vlastimil Burián's user avatar
0 votes
1 answer
59 views

Bash script to find certain files and add their names to another file

When I find a file whose size is 12kb I want to copy the file name to new file input.xml #!/bin/bash if [ $(find /root -type f -size +12k) ] then grep -r -i -s "the name of file to find it&...
IceDarkness's user avatar
0 votes
0 answers
59 views

keep sudo effective without password after update sudo package itself

I want to write an automation script in Bash that requires frequent use of the sudo command. To avoid entering my password repeatedly after the sudo timeout, I've tried the following: #!/bin/bash sudo ...
anonymous's user avatar
  • 187
-1 votes
2 answers
106 views

how to de-duplicate block (timestamp+command) from bash history?

I'm working with bash_history file containing blocks with the following format: #unixtimestamp\ncommand\n here's sample of the bash_history file: #1713308636 cat > ./initramfs/init << "...
Yuki San's user avatar
0 votes
0 answers
19 views

Remove PDF pages if content is subset of next page

I have a lot of uni-slides where a list of bullet points gets shown page by page until one slide contains all points. For the sake of explaining a topic this is quite nice but for learning I would ...
BillGatesPriv's user avatar
-1 votes
2 answers
76 views

I need to filter out `grep`'s output to find a device's serial number, in order to store it into a variable

I'm working on a section of a script that will find the serial number of a Mac, store it into a variable and rename the device according to the naming standards of my workplace. So far, I have the ...
TheBigDog's user avatar
0 votes
0 answers
16 views

Process names that begin with "-" [duplicate]

I am using a piece of software that includes a scripting language that has builtins that allow me to call system functions, for example I may write the script: system("whoami") and the ...
Themoonisacheese's user avatar
1 vote
3 answers
454 views

How to sort files by size in bash script?

I want to loop over all files in directory on macOS and perform some operations on each file, and do this based on their size, going from big to small. To create a list I can loop over I do this: ...
d-b's user avatar
  • 1
0 votes
0 answers
29 views

In Awesome, how to create a symlink to the wallpaper set by Variety?

In Awesome Window Manager, how would I modify the set_wallpaper script from Variety Wallpaper Changer (shown below) to create a symlink in ~/.cache/current_wallpaper to the newly set wallpaper image? #...
guttermonk's user avatar
-2 votes
2 answers
79 views

Extracting role from string in variable [closed]

I have a variable which could either be var=Role or var=AdminRole. I want to be able to do the following: if $var = "Role" then set role variable as $var else if $var = "AdminRole" ...
gdba's user avatar
  • 1
1 vote
2 answers
188 views

Compile a script, add it to system so it runs before (or during) system boot

I really don't know how to go about this so I'm asking you guys here for help Long story short with some background details I have a USB3 2.5gb NIC attached to my Raspberry Pi 5 (this SBC also has its ...
Arelius's user avatar
  • 73
0 votes
1 answer
80 views

Why does find ....-execdir rename miss files? zsh

I'm using zsh on MX Linux 23.2. For years I have tried to figure out why a command like find . -depth -type f -execdir rename 's/_720p//' {} \; skips over files. I know my file manager can't be ...
Terry 's user avatar
  • 35
0 votes
1 answer
27 views

Keep restarting an application in an interactive session after a short time

So I'm aware that this is a somewhat convoluted usecase with probably not many practical applications, so unfortunately I wasn't able to find many helpful pointers so far. Basically, I would like to ...
RobinFood's user avatar
3 votes
1 answer
278 views

How do I programmatically check if a Flatpak package is installed in a shell script?

I'm writing a script where I want to detect whether a given Flatpak package is installed, and take a different code path depending on the answer. How can I accomplish this? Traditional measures like ...
Newbyte's user avatar
  • 1,088
0 votes
1 answer
44 views

SIGTSTP(Ctrl-Z) not working for script started by script command

Note: script refers to the script command, which logs stdin and stdout to files. I was trying to run a script with the script utility to save output for later inspection while preserving text colors ...
GoDaft WithEBK's user avatar
0 votes
0 answers
38 views

Better understanding accels/nemo file syntax to add keyboard shortcuts for custom Nemo scripts

I carefully followed the instructions to add keyboard shortcuts to custom Nemo scripts as explained in this Ask Ubuntu answer and this Stack Overflow answer. Although this technique works great to ...
End Antisemitic Hate's user avatar
1 vote
2 answers
71 views

Mass Update of SSH Keys

I recently upgraded our Master Server from Oracle Linux 8.8 to Oracle Linux 9.3. Unfortunately, on a lot of our systems we still use RSA keys for ssh authentication, and they are not working anymore ...
Luke's user avatar
  • 21
0 votes
4 answers
109 views

Remove subdomains or existing domains

I have a list of domains, a sample is: account.google.com drive.google.com google.com bgoogle.com yahoo.co.uk stats.wikipedia.org media.wikipedia.org files.media.wikipedia.org bible.com I would like ...
ellat's user avatar
  • 37
0 votes
1 answer
59 views

Running sudo, changing dir, staying in sudo, staying in dir after the script finished

I often find myself typing the following commands: sudo -i cd workdir I would like to create a script and name it a single letter. e.g. a so that when I run a the effect is identical to typing the ...
Andrew Savinykh's user avatar
-2 votes
2 answers
104 views

Tool(s) for echoing to a bash script only once if script is run more than once

Edit: It's unfortunate the downvotes. This isn't my problem. This is how Linux wants things done and the myriad of tools that have ad-hoc and inconsistent install scenarios. Me asking this question is ...
bmitc's user avatar
  • 107
0 votes
1 answer
42 views

How do I copy directory structure as symlinks inside other directory

I am looking for an easy way to backup all my dotfiles in a git repository. Solution that I'm aiming for: have git as my source of truth for my dotfiles contents in my home directory backed up files ...
Artem Sevos's user avatar
1 vote
0 answers
37 views

SSH authentication

I am trying to make ssh on VM have an authentication before the user is connected to the session. Right now I have an Azure MFA app, that when the user authenticates, it shows a password. I want this ...
Tavleen Aneja's user avatar
1 vote
1 answer
43 views

Mounting directories on demand or until logged

As from object, I want to mount some directories (with binding) at login and possibly unmount them at logout. At the beginning I tought about autofs, but it dynamically creates mount points, that's ok ...
Daniele's user avatar
  • 468
-1 votes
3 answers
125 views

cron "@reboot" schedule not executing network configuration script

Version: Ubuntu 20.04.6 LTS In my crontab I have the following: @reboot /home/<user>/startup.sh Other output: <user>@eveng-gcp-v3:~$ ls -la | grep start -rwxr-xr-x 1 root root ...
Strider's user avatar
1 vote
0 answers
138 views

What's going wrong in this Knock script?

It seems by the article How to read an ACSM file on Linux? that knock is not supported anymore, but some variants seem to be working. I did before running the script masi@masi:~/Downloads/knock-main$ ...
Léo Léopold Hertz 준영's user avatar
1 vote
2 answers
50 views

Script to select which result/value to be copied to a text file using AWK

Can someone help me with the last step in my bash script. You helped me already getting this far. #!/bin/bash find . -type f \ -name '*.mp4' -o -name '*.mkv' \ -o -name '*.avi' -o -name '*....
dave999's user avatar
  • 25
1 vote
2 answers
44 views

How to calculate the Ratio of video file size and video duration of each file in a directory and subdirectories

I want to make a BASH script in Linux. So far I have the following #!/bin/bash for file in $(find "/home/drive1/videos" -type f -name '*.mp4' -o -name '*.avi' -o -name '*.mov'); do size=$(...
dave999's user avatar
  • 25
0 votes
1 answer
26 views

Thunar custom actions - how to import selections into zsh script

Xubuntu 22.04 Thunar 4.16 I am working on a script that works similarly to detox but does not require root privileges as it will only be allowed to operate on files or folders in the user's home ...
Terry 's user avatar
  • 35
2 votes
2 answers
48 views

How to source environment variable in command line with && combiner?

For a NodeJs app, I wrote the following script to deploy the app: "scripts": { "deploy": "source private/create_env.sh && ./deploy.sh", } private/create_env.sh ...
Alphonsio's user avatar
1 vote
0 answers
879 views

SSH StrictHostKeyChecking non-interactive

Since v9 of OpenSSH StrictHostKeyChecking is the (IMHO sensible) default. This makes that when the host key changes SSH refuses to connect until the host key in the ~/.ssh/known_hosts file is changed. ...
bakunin's user avatar
  • 531
0 votes
2 answers
80 views

Remove invalid characters from recursive Linux filesystem

I have a huge filesystem full of folders/files using invalid characters. I have found one command that almost does what I want and it came from this thread - https://stackoverflow.com/questions/...
JandP's user avatar
  • 1
1 vote
1 answer
73 views

How to display text for non-interactive login shell

What I need: I am trying to change /etc/bashrc in such a way that shell could display specific text when the following ssh command is entered ssh user@ip "whoami" But I don't understand ...
Judith5230's user avatar
0 votes
1 answer
91 views

How to run snmpwalk using linux script

Basically i am new in the field of shell scripting and i want to run snmpwalk using linux script here is the script i have created: echo "Starting SnmpWalk" var = `snmpwalk -v2c CS IP 1.3....
Anubhav Kumar Panda's user avatar
0 votes
0 answers
23 views

Script for ubuntu with 2 IPv4 so that auto choose which direction to go through

I have a PC with two IPs, for an internal network with IP 10.X.X.X and another for an external network with IP 192.168.X.X I have two network configuration profiles, one for each. If I am on 10.x.x.x ...
B_ Gamer's user avatar
0 votes
1 answer
118 views

openssl connect in a script

I'm using openssl s_client -connect to extract the dates from a cert. I want to integrate it into a bash script, the problem is that the command opens the connection to the server and waits for the ...
dejanualex's user avatar
1 vote
2 answers
52 views

Ensuring Distinguishable Exit Codes for Shell Scripts

Say I have two shell scripts, a.sh and b.sh, where a.sh calls b.sh somewhere inside. Then, say that b.sh could exit with exit codes 0, 1, or 2. What are some techniques that can be employed to ensure ...
Pacopenguin's user avatar
0 votes
1 answer
29 views

Ubuntu/Orange Pi5 retrieve open tabs on Chromium (kiosk mode) via terminal - Powershell

I have a problem as of late where I am developing some PowerShell script to manage and update some digital displays. Please see below for my work in progress (By no means done). I am struggling to be ...
M.Atkinson's user avatar
0 votes
0 answers
50 views

rTorrent XMLRPC command help - schedule pause/restart of all torrents

I would like to create a XMLRPC command and add to rtorrent.rc to schedule pausing and resuming all torrents. Reading the docs I figured out the following but something is missing and the command ...
Cez Mal's user avatar
3 votes
5 answers
407 views

How to filter big CSV-file by highest humidity per day?

I have millions of rows of this data, so I cannot do this operation by Spreadsheet. You see some data rows are without data so those should be skipped. The data is in .CSV format. Any Unix tools are ...
Léo Léopold Hertz 준영's user avatar
0 votes
1 answer
57 views

Zsh: What is the idiomatic way of terminating lines in a script? (semicolon, new-line) [closed]

I'm fairly comfortable with putting semicolons, newlines and ampersands where they're needed. But what is the "correct" way? Is it just a matter of style/personal preference, or is one in ...
colinh's user avatar
  • 47

1
2 3 4 5
90