Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

Filter by
Sorted by
Tagged with
2 votes
2 answers
61 views

find the partition and block device for a filesystem *without* string manipulation

Given a filesystem such as /dev/sda5 or /dev/mmcblk0p5 is it possible to get both the partition number (5) and block device (i.e. /dev/mmcblk0) without string manipulation, or by minimizing the ...
  • 507
0 votes
0 answers
12 views

Zenity checklist from file

I created a checklist and I want to insert data from a file in a specific order. The data comes from a terminal command in my bash script: data=$(lsblk -o name,size,model --nodeps >> /data.txt ...
  • 11
-6 votes
1 answer
35 views

the output between zsh and bash

i write this command in zsh pwd ; ls ; cd /etc ; pwd ; cd ; pwd ; ls ; echo $BASH_SUBSHELL} /root Desktop Downloads Music Public Templates Documents for_play Pictures pycharm Videos /...
0 votes
1 answer
37 views

How to change the modification date (The Metadata) of multiple files?

I have a gallery folder with multiple images and videos, some of them has their modification date correct, and some of them has the month wrong. I want to make a script that will change all the files ...
0 votes
2 answers
60 views

Arithmetic in a bash script

In a bash script, I would like to determine the maximum or minimum value depending on my input: for example if my input is max 20 40, then the output should be 40. If the input is min 20 40 then the ...
2 votes
3 answers
56 views

Sed replace the middle string

I have this this String 22<>22 And i have this list test dev too The output should be like 22test22 22dev22 etc.. This is the commands i use for do that cat list | sed 's/$/22/g' | sed 's/^/...
-1 votes
1 answer
30 views

add a new line after a specific string in a file? [duplicate]

Right now I'm using echo sed '/\Random/a \ newly added line' info.txt to append some text to a file but I also need to add text below a certain string let's say random, I know it is possible with ...
6 votes
2 answers
423 views

What are the ideas behind the absence of quote removal and escaping in variable expansion?

Commands can be stored in variables and executed (though not a good practice) in shell like: command='ls -l A* "B\" type"' $command It lists files beginning with A, "B\" and ...
1 vote
1 answer
28 views

How to make a script to rename images and videos with the date of modification?

I have a gallery folder with images and videos in it named in unwanted format. I want to make a script that scans through each file in that directory and when it finds an image or a video to rename it ...
-3 votes
2 answers
26 views

am not sure how to write on other file

hi i have this script called script.sh have 2 variable #! /bin/bash read -p " name " name read -p " last " last ( here am not sure what to do but if possible to open file name....
-1 votes
1 answer
34 views

How to merge csv file into one csv but different sheet using unix/shell

We have a requirement to merge many CSV files into a single workbook with different worksheets using UNIX scripting. For example: If we have 4 different excel sheets (sheet1.csv, sheet2.csv, sheet3....
  • 7
0 votes
1 answer
11 views

Running minicom from a bash script for X amount of time (and getting the output)

I'm trying to write a script that involves repeatedly calling minicom, letting it run for 60 seconds, getting the output, then killing the job nad moving on to the next directory it runs minicom. So ...
  • 1
1 vote
1 answer
31 views

Multiple commands in variable? [duplicate]

Is it possible to execute multiple commands stored in a variable? Singe command works fine variable="echo HELLO" $variable HELLO I would like to have something like this variable="...
's user avatar
3 votes
3 answers
71 views

PROMPT_COMMAND output in shell script using piping LINUX

I want to make a shell script that shows the available data on my root directory and shows it continuously after each new command in the prompt by using PROMPT_COMMAND in the shell script. However, I ...
0 votes
1 answer
20 views

Zenity select disk/volume

is it possible to select a disk/volume with zenity instead of a single file? I know there is the zenity --file-selection command, but can you also select for example /dev/sda1 ? Thanks for your time!
  • 11
1 vote
1 answer
19 views

Makefile: how to assign object to variable and iterate on object of array

Makefile: QUERY := "securityresources | where type == 'microsoft.security/assessments' | summarize by assessmentKey=name | join kind=inner ( securityresources | where type == 'microsoft.security/...
1 vote
2 answers
18 views

Save a variable to environment till it is not erased

I am new to bash scripting, so if I ask anything stupid sorry for it xD I'm making a script which run come cli commands everyday. The output which I get from the cli command is a ID which I have to ...
  • 139
1 vote
0 answers
23 views

Permission Error

I have installed bash shell in windows 10 to run linux commands. I am trying to execute a script which gives error "You do not have permission to edit". I have executed command "chmod ...
1 vote
1 answer
19 views

How do we write only fail jobs in a log when we use GNU parallel

parallel --joblog /tmp/log exit ::: 1 2 3 0 cat /tmp/log Ηow can Ι use a filter to write only failed job in my load when using GNU parallel or is there a way to get only failed jobs from the above ...
0 votes
1 answer
31 views

Prevent starting a program if it is already running and has opened a particular file

I need to restrict a a_command myfile couple to only one instance. In my particular case I run qemu-system-x86_64 [options] -drive file=myfile.img,format=raw The script should check whether both ...
0 votes
0 answers
13 views

Which is correct format for memory allocation in LSF bsub

which is correct format for memory allocation in LSF bsub? a) bsub -K -R mem=100000 b) bsub -K -R "rusage[mem=256GB]" and what's the difference between them?
0 votes
0 answers
23 views

Securely run shell command using php from another server

I've got Server A where the main website is hosted. I've got a panel there that I'd like to safely run a shell command on Server B every time a new user joins in. I will basically create a new user on ...
  • 1
-1 votes
0 answers
42 views

How to add comment line for the output using for loop

Im running a code for multiple server and i want to get details from them, then create a separate file based in the serverlist and add a comment header based on the txtfile. I tried adding echo -e &...
  • 11
1 vote
0 answers
27 views

Issue with redirecting output to double digit file descriptor

/tmp$ python Python 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>&...
0 votes
1 answer
39 views

Prevent splitting command line argument at spaces when running in bash script [duplicate]

I'm trying to run a command in a bash variable, like this: cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234" $cmd It looks like it is splitting the command line ...
0 votes
0 answers
11 views

How following code work in unix shell script [duplicate]

Consider filename_????_*_sample.zip. I am not able to find the meaning of ???? in IICS while generating this dynamic filename.
3 votes
4 answers
96 views

Collapse multi-line records into single CSV lines containing the "value" parts only

I have data with multi-line records which looks like this: Name>Ami Admin>2 Oper>1 Name>Sum Admin>3 Total>2 Name>Tar Admin>1 Oper>2 Now I want to collapse ...
-1 votes
3 answers
37 views

Searching filename for certain string and saving it to a variable in a shell script

Let's say I have files with a very specific naming scheme. For instance, maybe I have a file named x=1,y=15,z=63.txt, and I've saved this filename to the variable file. I want to search the variable ...
  • 11
0 votes
0 answers
40 views

Is there an optimized solution for tcpdump pulling a specific IP?

I made a script that runs tcpdump in the background: nohup tcpdump -i $INTERFACENAME dst $IPC >> text.txt And I made another script that pulls any IP address other than $IP from text.txt, but ...
2 votes
3 answers
537 views

Remove duplicated word from a file

I have a text file of format something like path1/path2/path3a 34474538656 path1/path2/path3a 8115147679 path1/path2/path3b 2266371027 path1/path2/path3b 3860823 path1/path2/path3b 554247 And this ...
-1 votes
1 answer
38 views

How safe is it to use EXPORT in bash scripts when using GNU Parallel?

How safe is it to use export in bash scripts when using GNU Parallel? I have a parent script. parent.sh (echo child.sh & echo child_two.sh) || parallel bash wait if [[ "$STATUS1" == &...
1 vote
2 answers
62 views

Is this bash variable a valid IP v4 or 6 address?

I have a bash (v5.2 from latest Debian testing/bookworm apt) variable called TARGET. How can I check if the contents is a valid IPv4 or IPv6 address, rather than something like ERROR?
  • 1,096
-1 votes
0 answers
30 views

How to get the individual script overall status as 0 or 1 with GNU Parallel?

I have a parent script. parent.sh (echo child.sh & echo child_two.sh) || parallel bash wait if [[ "$STATUS1" == "0" && "$STATUS2" == "0" ]]; then ...
0 votes
1 answer
25 views

I want remove repeated records and remove those lines in awk

I want check repeated records in column 2 and remove those lines in awk create a delete a create b create c delete c create d delete f create f create g create h Expected Output create b create d ...
  • 15
0 votes
1 answer
19 views

ssh root@$host.list < ./remotescript.sh [duplicate]

I'm using this command a lot to run a script on remote servers: ssh root@servername.eu < ./remotescript.sh It works quite well. Now that there are more servers I'm wondering how I could use a list ...
  • 71
2 votes
1 answer
41 views

Is there a way to auto install anything I need in a new linux distribution with one file?

I know the question is very poorly redacted, I couldn't find the words to do it, let me explain. What I want is to make a file (I imagine this can be done with a text file but I have very little ...
1 vote
1 answer
25 views

How to manage desktops and polybar on BSPWM with MULTIPLE MONITORS

I use bspwm as my window manager. I've been using it on my desktop for long and now I've also using it on my laptop, but here it's a bit more difficult to operate. I use a tool called mons to auto-...
  • 43
0 votes
1 answer
21 views

how to skip "is this a single-disk" archive message

after running this code terminal asks me "is this a single-disk archive : y/n". where I need to type y and press enter but I want to do this from the code I am running. In other words I don'...
0 votes
0 answers
64 views

Creating a bash script to install packages

I'm quite a newbie when it comes to bash. I'm trying to create a script that checks whether a package is installed or not. If not it will install that package. Not sure what I'm doing tbh. #! /bin/...
2 votes
2 answers
41 views

Script - Compare filename date with current date

I'm trying to compare a file with date in its name to the current datetime of the system: Filenames are with the following format: FileName.yyyymmdd.hhmm.file (e.g. File156tr.20220914.0958.txt) I have ...
  • 51
2 votes
2 answers
36 views

How to add CIDRs from files to set in best way?

So I have several files which contain CIDR entries (such as 1.1.1.0/24). The task is to add entries from these files to one NFTables set using a bash script. In doing so, I am limited to OpenWRT ...
0 votes
1 answer
29 views

Issue - infinite loop using while on ksh script

I'm writting a scsript to automate some check at work & i have trouble on only 1 standing issue which is the script never ending. It do the all task over & over. There are 2 while loop & ...
1 vote
0 answers
14 views

progress bar for general non-looping script, or using multiple processes to write to stdout

How do I make a spinning wheel or progress bar that measures the progress of a very general script and I don't need or want to run it over anything looping or iterable? It doesn't need to be anywhere ...
-2 votes
2 answers
76 views

if condition in awk script

I have one details.txt file which has below data size=190000 date=1603278566981 repo-name=testupload repo-path=/home/test/testupload size=140000 date=1603278566981 repo-name=testupload2 repo-path=/...
  • 51
1 vote
1 answer
76 views

How is it possible that this doesn't work even if you use quotes?

I know that to deal with spaces in file names you should wrap the entire file name between quotes but this is not working for this script, indeed what is happening is the exact opposite, it only works ...
's user avatar
0 votes
1 answer
70 views

Replace $placeholder text in various configuration files with $placeholder parameter

I am at my wits end trying to get sed to do this for me and I feel like an idiot. So I hope someone has a much smarter way to accomplish what seems to be incredibly simple. file.conf: USER: !USER! ...
0 votes
2 answers
18 views

Traffic flow Monitoring on a particular UDP Port

Is there any way from where we can monitor incoming traffic speed on a particular UDP port using bash? There are tool like nload, vnstat which shows traffic flow on a particular interface. Can someone ...
  • 139
0 votes
1 answer
34 views

Using `env` command with `eval`

Suppose I have this in script.sh: env -i SOMEVAR=SOMEVALUE eval -- "$@" I run it with: ./script.sh echo "\$SOMEVAR" Now it shows: env: ‘eval’: No such file or directory I ...
  • 25
0 votes
0 answers
19 views

Unable to run flatpak independent of the script that started it

I've always successfuly used an ampersand to start an application in the background from within a script. Such background applications seem to be detached from the script that started it, meaning that ...
  • 51
-3 votes
1 answer
24 views

I'm using windows subsystem for linux, for my unix practice, why wsl showing me command not found when all are correct

echo "Enter two filenames" read file1 file2 var1 = `ls -l $file1 | cut -c 1-10` var2 = `ls -l $file2 | cut -c 1-10` if [ $var1 == $var2 ] then echo "The common permission is $var1"...
  • 1

1
2 3 4 5
311