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
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 ...
user56834's user avatar
  • 125
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://...
pming's user avatar
  • 23
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 ...
Freezer Fridge's user avatar
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 ...
jumboshrimps's user avatar
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 ...
Torsten Crass's user avatar
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 ...
Vlastimil Burián's user avatar
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 ...
cefer's user avatar
  • 11
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 -...
Aleksander's user avatar
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 ...
swijt's user avatar
  • 11
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 ...
Polizi8's user avatar
  • 175
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 ...
Kenny LL's user avatar
-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 ...
ShyamNarayan's user avatar
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*(...
peterh's user avatar
  • 9,517
-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"...
Inukaze's user avatar
  • 47
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 ...
kjo's user avatar
  • 14.8k
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 ...
bk_32's user avatar
  • 111
0 votes
1 answer
63 views

Is it a good idea to put "export BASH_ENV=~/.bashrc" in my .bashrc?

Let's say my Bash has some extensive ~/.bashrc customization that aids me not only in interactive use, but also in scripting (aliases, functions, variables, etc.). I would like to have this available ...
Sebastian Carlos's user avatar
-1 votes
1 answer
31 views

Iptables not working properly in ubuntu VM under utm app

I want to setup my ubuntu machine like this so that it only opens youtube.com and pw.live website and block all other outgoing traffic. What I have done so far is created ip_table script below inside ...
bigDaddy's user avatar
0 votes
0 answers
24 views

Avoid cumulative sum by Unix shell script -hdfs file copy

We are copying Hdfs directory (contains files) from 1 location to other however there is only 1 Target directory. For 1st iteration it gives correct count of file size and counts of files as in 1st ...
user2429695's user avatar
0 votes
1 answer
44 views

Write a script to obtain the date of the last month [closed]

I would like to obtain the date of the previous month as output and store it in a variable using a bash script. For example, if today's date is 07/04/2023, I would like the output to be 06/04/2023.
Ganesh Hite's user avatar
-4 votes
1 answer
73 views

endless loop in until loop for unix script

I am doing a unix script using until loop.The idea of my script is it need to continuously verify the url status whether is up or down.When its up, it will exit the loop. In my script, I will use curl ...
attack's user avatar
  • 9
3 votes
6 answers
741 views

Update crontab rules without overwriting or duplicating

I'm trying to figure out a good solution to the following problem: crontab contains some default rules (A,B,C) I have a setup.sh script that should append rules from a file my.cron to crontab (...
Tabish Mir's user avatar
0 votes
0 answers
42 views

What program can I use to invert the state of Shift?

I want the Shift key to behave as if it was inverted, when it is not being pressed, it's state should be set to 'pressed' and when it is being held down, then it's state should be 'released'. This ...
Sabudum's user avatar
0 votes
1 answer
38 views

How to validate if the log started flowing after restart of a service?

I have an use case where in part of validations one step is to verify whether the log file has started flowing after the service restart? How it can be achieved easily?
Varja's user avatar
  • 69
6 votes
2 answers
1k views

This 'while' loop countdown with sleep doesn't work

I'm having some issues with a bash script, but I don't know why. The script is meant to convert the input (in minutes) to seconds and then start counting down until it reaches zero, at which point the ...
NeG's user avatar
  • 61
-1 votes
1 answer
104 views

How to check for passed options using getopts in a POSIX shell? (Report, count, and discard.)

How to check for passed options using getopts (man page) in a POSIX shell? (Report, count, and discard.) My idea is this: Many of my scripts take no options (not even -h for help, I am transitioning ...
Vlastimil Burián's user avatar
0 votes
0 answers
42 views

Sendmail entry in /etc/aliases that modifies the email header before sending it out?

I'm using Sendmail I want to create an alias in /etc/aliases, that modifies the To: line before sending out the message . I assume I need some sort of script or command that the email is piped into. ...
user1993015's user avatar
0 votes
0 answers
34 views

How to properly format the command argument for sudo? [duplicate]

I have a command that is similar to this minimal example: $ sh -c 'echo "1=$1"' _ foo 1=foo $ When I want to run it through sudo, it stops working: $ sudo -i -u user -- sh -c 'echo "1=...
finefoot's user avatar
  • 2,960
0 votes
1 answer
55 views

Is there any way to permanently have shell aliases on an imutable system

I'm on blendOS https://blendos.co/ which is an immutable operating system which means I cant just add a file to /bin/ like you would do normally to add a custom command right now I'm keeping it simple ...
HunterLyre's user avatar
0 votes
1 answer
129 views

Automatically resize rofi menu height

I want rofi to automatically resize menu's height to the number of available options. There is an option -lines but with it I could only pass constant number. So for each call I'm forced to execute ...
anlar's user avatar
  • 4,096
0 votes
1 answer
21 views

Would it be feasible to create a script that can right click the mouse at a very specific location when an even more specific number gets generated?

I'm aware of a program that can simulate a right-click at specific coordinates on my display at any given interval. However, I'm wondering if it's possible to write a script that can perform a right-...
Ryan's user avatar
  • 1
1 vote
0 answers
185 views

How can I run the file currently open in the kate editor as a python script?

I am writing Python scripts and using a shebang line to specify the location of the Python interpreter in my system.: #!/usr/bin/env python So, in principle, my system should be able to run the ...
Fabio's user avatar
  • 407
0 votes
1 answer
24 views

Copy multiple files by filenames in subdirectories in linux

I can do the following to copy a file from subdirectories. find . -name "file1.txt" -type f -exec cp {} ./distfolder \; How do I change this code to copy multiple files (file1.txt, file5.txt,...
Sher's user avatar
  • 113
-2 votes
1 answer
90 views

Automate "atlasvpn connect"

I want to connect to a server through AtlasVPN automatically. But I have some difficulties to create a code that works at the startup of my Ubuntu system. Look at how that company's script works and ...
Megapeiron's user avatar
0 votes
1 answer
149 views

How to escape characters inside variables in awk?

I'm trying to make a script that uses awk to get the recent file names from .config/okularrc and pipe them into dmenu, and back to awk to get the path for the name selected. However, I'm getting an ...
white-hat-er's user avatar
0 votes
1 answer
51 views

ZFS script pull latest snapshot and restore

I keep my zfs snapshot backups in zfs/snapshotbackps and my virtual machghines run off direct zfs location I am trying to create a script that will pull the latest snapshot and restore it. I've tried ...
Teddy77's user avatar
  • 2,903
1 vote
2 answers
148 views

Combine rows based on shared elements (bash/awk)

I have a following file: a3 v2c v5 a7 a9 v2c v1c a3 a7c Desired output (without duplicates in each row): a3 a7c a9 v1c v2c a7 v5 What I want is to combine the rows sharing at least one element. In ...
Tokivideo's user avatar
6 votes
2 answers
287 views

isblocks.conf create onclick event (open firefox with URL)

I have this block in /etc/i3blocks.conf [rss] command=rsstail -n1 -1 -N -u https://news.ycombinator.com/rss | iconv -f UTF-8 -t ASCII//TRANSLIT | head -c 50 color=#00FF00 interval=300 I'd like to ...
xralf's user avatar
  • 16.3k
1 vote
1 answer
59 views

i3blocks.conf Error could not parse JSON lexical error

I have this error in my /etc/i3blocks.conf Error: Could not parse JSON (lexical error: invalid bytes in UTF8 string.) My code in /etc/i3blocks.conf looks like this. [rss] command=rsstail -n1 -1 -N -u ...
xralf's user avatar
  • 16.3k
0 votes
0 answers
82 views

Get coordinates with xdotool upon user click and use them in an automation script

I am trying to prompt the user "Click the confirm button" and use the coordinates as a variable in a script. If the user clicks at 1285 786, I would like to click this coordinate once and ...
PerryJones's user avatar
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 ...
Opux's user avatar
  • 215
0 votes
3 answers
68 views

Matching variable value and setting default

I have a variable that can take any of the values "SUBSCRIPT", "ITERATE", "COUNTER". How can I test the variable in any of those, and default to "SUBSCRIPT" in ...
Vera's user avatar
  • 1,183
0 votes
1 answer
32 views

How do I write a script that runs "du -sh" for every file in a directory?

My organization has a network share dedicated to user files. Each user has their own directory. I am trying to figure out who is using the most space on the share. My current code looks like this #!/...
Ambre's user avatar
  • 5
-3 votes
1 answer
121 views

Im trying to run a shell script but I keep getting If: expression syntax. How to I get rid of it

Good afternoon, I'm trying to run my code for assignment 4 but I keep getting an expression syntax error, can you tell me why? #!/bin/sh if [ "$#" -ne 1 ] then echo "Usage: ...
Gbreezoo's user avatar
0 votes
1 answer
67 views

How to navigate to a previous line in a bash script

I have a bash script with a lot of if/elif statements. Is there a way to take the output of a command, and make it execute the associated if/elif statement, rather than the default version of the ...
Lee's user avatar
  • 85
0 votes
1 answer
44 views

Allow a certain set of domain names corrisponding ip with resolution and whitelisting on the fly

I'm trying to setup a firewall config for a specific machine. The firewall is configured to block all traffic except for a certain set of allowed IPs. Today I was asked to put on a teamviewer service ...
user3450548's user avatar
  • 2,714
1 vote
2 answers
829 views

How to pass string from bash to python function

I have a python function which takes a parameter as input and I want to automate and call it through bash. But bash is giving error when i pass variable(string) when calling it a="test" ...
ssuraj's user avatar
  • 13
1 vote
0 answers
26 views

Recommended solutions, libraries or frameworks to build a repeatable copy/mirror tool

I'm looking to satisfy the following use cases Occasionally automatically copy all data from a removable storage to fixed folder (and in reverse) Occasionally automatically sync a folder with a ...
hipsterdoofus's user avatar
0 votes
0 answers
84 views

Running a local script on remote server over ssh with sudo privileges

I have a script script.sh on local machine which I want to execute on remote server with sudo permissions. I am logging in to remote server through SSH and executing the script using the below command ...
Anubhav Rai's user avatar
3 votes
2 answers
690 views

Race condition not seen while two scripts write to a same file

I have two scripts running parallelly and they are echoing to the same file. One script is echoing +++++++++++++++ to the file while the other script is echoing =========== to the file. Below is the ...
Anubhav Rai's user avatar

1
2 3 4 5
89