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
1 vote
1 answer
4k views

bash script for cdo command to run it on different files

I am new in UNIX and I want to apply the CDO (Climate Data Operator) "remapbil" command in order to transform the grid (from a projection to geographical coordinate system). it works perfectly fine ...
25 votes
5 answers
226k views

How can I know if IP Multicast is enabled

I have scripts that run IP multicast tests; however, my scripts are failing on a particular linux machine. I know that I can look at CONFIG_IP_MULTICAST in the kernel configuration file to determine ...
0 votes
0 answers
28 views

Open GUI linux terminal in non-interactive mode

It would be helpful if I can open a terminal and run commands exactly as if they would be run by a non-interactive bash script, to test whether certain commands work in non-interactive mode without ...
3 votes
1 answer
3k views

How do you make a toggle key using Autokey?

I want to use Autokey to toggle the e key on and off in a program called "xyz". So if I press e, the program thinks I'm holding down e. I press e again, it thinks I released it. How do you do this ...
1 vote
1 answer
2k views

how to get multiple command output as variable in awk

I am trying to execute 3 command and get the output as a variable which needs some percentage calculation and display the same as the example. can this be executed as script. First command output $ ...
2 votes
2 answers
95 views

How and why does using redirection or writing files within an if statement affect exit code?

In zsh echo 'a string' > test.txt echo $? 0 and [[ $(echo 'a string') ]] echo $? 0 whereas [[ $(echo 'a string' > test.txt) ]] echo $? 1 another example curl -so 'curl-8.2.1.tar.gz' https://...
0 votes
1 answer
860 views

zsh script cannot find commmands [duplicate]

I'm attempting to run this zsh script: #!/bin/zsh paths=( "/docs/" ) for path in $paths; do dirsearch.py -u "http://10.129.140.251:8080$path" \ -r --csv-report=&...
0 votes
3 answers
10k views

Create bash script for ping

Good evening I would need a script in bash that follows this command: ping -c 4 -i "IP" for 3 times. Each ping must be performed at a distance of 10 minutes and only when it fails all 3 times, it send ...
1 vote
1 answer
18k views

Systemd service fails with exit-code 2: Start request repeated too quickly

I created a ClamAV on-access scanning systemd service, to be permanent so that I can enable, start and then leave it, without having to touch it again. I can manually start the service, and it works ...
0 votes
1 answer
2k views

cannot execute python script as sudo from command line

I have a centos 7 VM and I need sudo permissions to run certain shell commands in a python script. I have a #!/usr/bin/env python3.7 at the top of my script and running it as sudo ./script.py gives me ...
1 vote
0 answers
252 views

How to run an arbitrary command from a Kwin script?

I want to run some commands when the active window changes in KDE. How can I do this from within a kwin script? My use case is that I want to change monitor color preset for some applications, and ...
0 votes
1 answer
29 views

Force Patch character differences to a file

Hello, I have an englishStrings.json file and when I make new edits/ additions to it, I need to copy the new changes to all the other language string.json files. Before making any changes to ...
647 votes
4 answers
492k views

Using "${a:-b}" for variable assignment in scripts

I have been looking at a few scripts other people wrote (specifically Red Hat), and a lot of their variables are assigned using the following notation VARIABLE1="${VARIABLE1:-some_val}" or some expand ...
1 vote
1 answer
22 views

Logout other users from KDE/plasma as root

I'd like to be able to automatically log out users from their KDE/plasma sessions by a script running as root. The log-out should happen "gracefully", i. e. applications should get a chance ...
0 votes
0 answers
36 views

!$ in bash script [duplicate]

Saw the use of !$ on this site, so I made a short bash script "bang_dollar.sh" as below: #!/bin/bash echo -e '\n' touch touche.txt vi !$ This was a copy verbatim of what someone posted ...
0 votes
3 answers
75 views

Does `return 0` equal `true` (in sourced script to shell's environment)?

I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as ...
6 votes
2 answers
2k views

How does bash interpret the equal operator with no surrounding spaces in a conditional?

The following script does not behave as I would have expected. Adding spaces around the '=' in the conditional made it perform how I wanted, but it got me thinking, what is it actually doing inside ...
1 vote
1 answer
34 views

startup script remain running in background

I use severals window managers as icewm openbox wmaker and others For these i have one generic startup In one line i have (to load in traybar one volume control applet according wich is installed in ...
1 vote
1 answer
2k views

Save cached video on firefox?

I found a script on the internet that allows me to save cached flash files. https://github.com/janosgyerik/shellscripts/blob/master/bash/save-flash-linux.sh This would allow me to run the command ...
0 votes
2 answers
37 views

Getting only used memory from free command every few seconds

It was explained e.g. here: Get separate used memory info from free -m command how to cut the output of free command. But I want to do this every few seconds and log it to a file. So I tried: free -g -...
1 vote
1 answer
57 views

How to extract the URL from cURL response in bash script and use this URL to run another cURL command

We have this sample curl command that retrieves data as output. Aside from that, that output also contains another URL that can be used again to perform curl command to get the next data. Please help ...
49 votes
4 answers
64k views

Bash shell script output alignment

My script: date echo -e "${YELLOW}Network check${NC}\n\n" while read hostname do ping -c 1 "$hostname" > /dev/null 2>&1 && echo -e "Network $hostname : ${GREEN}Online${NC}" || ...
24 votes
3 answers
25k views

shorthand for feeding contents of multiple files to the stdin of a script

Let's say I have a script called script, that reads from stdin and spits out some results to the screen. If I wanted to feed it contents of one file, I would have typed: $ ./script < file1.txt ...
11 votes
2 answers
16k views

Run script in the host when starting virtual machine with virt-manager

This is related to my question on Ask Ubuntu: Add physical partition to QEMU/KVM virtual machine in virt-manager (see "Updates" near the end, if needed). Is there a nice way to run any arbitrary ...
1 vote
2 answers
2k views

Command to merge all terminal windows?

Is there a terminal command that merges all open terminal windows into one window with tabs? Been searching all over the place, but have yet to find any solutions.
1 vote
2 answers
3k views

Linux script for file change email notification ( not inotify or any other utility)

I'm looking for linux script (not inotify tool or any other utilities ) which notifies me via email whenever file contents are changed. I have managed sample script via google, but i have to run it ...
0 votes
0 answers
84 views

systemd: controlling timing of execution in *.service file

I've managed to get my script to run on shutdown or restart, however, I get an error, which is I think is caused by the script being run too late. The *.service file is: [Unit] Description=My special ...
21 votes
8 answers
162k views

how to execute a bash command in a python script

How can I launch a bash command with multiple args (for example "sudo apt update") from a python script?
1 vote
1 answer
2k views

Python script: wait until job in tmux session has completed

I am trying to continuously run a python script with random parameters from another python script, where each run is in its own tmux session. A very simplified overview of what I'm trying to do goes ...
0 votes
1 answer
25 views

Return the root partition name with lsblk or similar when the partition is encrypted

This is my lsblk output: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS nvme0n1 259:0 0 465.8G 0 disk ├─nvme0n1p1 259:1 0 512M 0 part /efi ├─nvme0n1p2 259:2 0 420G 0 ...
5 votes
5 answers
12k views

Comparing multiple options in a bash (string)

I'm trying to enable only certain options when using the read command, and to exit the script if a wrong possibility was entered. Tried many possibilities (array, variables, syntax change), but I'm ...
18 votes
3 answers
62k views

Bash: calculate the time elapsed between two timestamps

I have written a script that notifies me when a value is not within a given range. All values "out of range" are logged in a set of per day files. Every line is timestamped in a proprietary reverse ...
0 votes
1 answer
2k views

How to copy files to the timestamp generated directory?

Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to ...
20 votes
6 answers
53k views

How can I check that a remote computer is online for ssh / script access?

I'm writing a script that will backup data from my laptop to an Ubuntu server. To do so, I'm looking for a (ba)sh command to test if the server is available before starting the backup. something like ...
4 votes
1 answer
2k views

GRUB 2 scripting: convert device name in GRUB notation into a Linux device name

I'm trying to use partition labels (or UUIDs, that does not matter) to select root partition without use of an initrd/initramfs. With initramfs, this is fairly easy: root=LABEL=... or root=/dev/disk/...
0 votes
1 answer
24 views

Fedora linux VNC scripting help

I'm trying to make a bash script for a school project which i am using a Fedora system which requires me to launch VNC viewer(TigerVNC), automate any password entry so that no passwords will have to ...
0 votes
1 answer
151 views

How to auto-detect filetype in pastebinit?

I use pastebinit to share snippets. As you can see, it has a -f switch so the rendered webpage highlights the uploaded file depending on the format of the file (like -f python or -f bash). Now, I want ...
2 votes
3 answers
2k views

parted: create swap partition on gpt disk (one liner) not working

I am trying to create a swap partition in my script using parted based on the Arch Linux guidance. https://wiki.archlinux.org/title/Parted#Partition_schemes Somehow it is always sort of skipping the ...
-2 votes
1 answer
63 views

"for" loop is not executing on the remote server using SSH

The below "for" loop works locally on the same server. But when triggered through "ssh" protocol on remote servers, the output is not received. Please, can anyone suggest how to ...
0 votes
2 answers
66 views

How to copy every N file when serialization is not consistent

I have a directory containing 101695 files ranging from img001.jpg to img101693.jpg and I want to move every 100th image to another directory. I have found some similar posts such as How to copy every ...
1 vote
2 answers
164 views

ranger chain commands in config

I am using ranger as my terminal file manager and now that I understand the basics, I wanted to get a bit deeper into customizing the rc for my purposes. One thing I like to do is to map a command to ...
4 votes
2 answers
80 views

How to make the (N) patterns of the zsh eatable by bash?

I am trying to develop a script which runs (and, ideally, does the same :-) ) in zsh and Bash. Problem is, that at a point, the zsh-specific part contains a pattern ending with (N). So: this_pattern*(...
0 votes
1 answer
2k views

Run this PHP file via Cron Job

Here is the script: <?php //Create back files? define('CREATE_BACKUPS', FALSE); if (!is_dir($argv[1])) { echo "You must enter a valid path such as /home/apresv/public_html or apresv/...
0 votes
1 answer
2k views

Problem redirecting output to log file and console in bash script

I have a shell script which sucessfully redirects all output to a log file and stdout (console) at the same time. However, when it exits it seems to wait for some user input from the keyboard (...
-1 votes
1 answer
62 views

Bash script via .desktop save to variable external filename with fullpath

ok i try to make the most resumed the points i want to do. Sorry for the repetions i don't know how make this question more objectively The first i am making a script for launch "mupen64plus"...
-3 votes
2 answers
9k views

Add execute permission to all subdirectories of the current directory

How can I add execute permission to all subdirectories of the current directory for the owner, the group owner and all other users except files? I wanted to create a script to do this but I don't know ...
8 votes
1 answer
643 views

Looking for a more permissive alternative to GNU getopt for wrapper script

I often find myself writing shell functions or shell scripts that are meant to be wrappers around other commands. It is also frequent that I want such a wrapper to support a few flags/options. The ...
1 vote
0 answers
47 views

gtar recursively untar but leave in top directory

I am trying to recursively untar a whole lot of directories that have .tar files in them, but without creating any new subdirectories. I am successfully able to do one at a time with this command gtar ...
1 vote
3 answers
2k views

Searching /usr/dict/words to find words with certain properties

I would like to write a script to search through /usr/dict/words to find all words that meet some criteria I specify. For example, finding all palindromic words (like "racecar", "madam", etc.) or ...
3 votes
3 answers
22k views

Linux Bash Shell Script Error: cannot execute: required file not found

I have two similar scripts with different names. One works fine but other throws error. Can anyone please tell me what is the issue? This is my test.sh scripts which works fine [nnice@myhost Scripts]$ ...

1
2 3 4 5
89