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
42 views

What's the POSIX-compliant way to get the epoch timestamp in a shell?

I just noticed, that POSIX date doesn't seem to have the %s or %N format items. So I can't use those. What's an alternative, yet POSIX-compliant way to get the epoch timestamp in my shell script?
user avatar
  • 1,854
0 votes
0 answers
24 views

Delete folders from a directory once it's sbatch`ed in a for loop?

I am running a command using sbatch for a tool on the server, that takes a lot of space. The command uses some directories (some files) from a main directory(tq_first) in a for loop. I was wondering ...
user avatar
  • 1
1 vote
1 answer
11 views

Filter rows of a huge csv file based on values in 2 columns

I have a .csv files as shown below: RepDate;FOO1;ProcessId;ClusterName;ProcessType 19700101;-1;Job_1000969943637142044;PROD;auswertung.mpeTestPlayer.xml 20181231;root;Job_107953405843118835;PROD;...
user avatar
0 votes
0 answers
22 views

systemd doesn't read environment variables required for script

I want to use borg backup and systemd timers to do my backups. I am using the script from borg backup website very slightly adjusted. You can see the original HERE and my script below: #!/bin/sh # ...
user avatar
  • 101
0 votes
0 answers
15 views

why websocat or wscat in background with nohup, disown, bg, &, &! don't work

The question is about running a bash script in background with the ability to logout and the process to continue. The issue is that websocat and wscat don't like when I close the terminal or logout.......
user avatar
  • 115
0 votes
2 answers
31 views

Define bash function and chain `script` with it in a shell script

I am having issues defining a bash function inside a bash script and getting to use it in the same script when I try to chaining it after the script command. A minimal working example is this. I have ...
user avatar
  • 103
2 votes
2 answers
39 views

Setting time zone in a kindle bash file

I've recently jailbreaked my kindle to make it a clock that shows a certain image for each minute of the day. I used the instructions mentioned in this article https://www.instructables.com/Literary-...
user avatar
5 votes
4 answers
510 views

Shellcheck approved way to pass 2 arguments in one variable, to a command in a bash script

In a bash script, I call another programme, but I want to configure that programme with a command line option. The following works: AREA_ARG="" if __SOME_SETTING__ ; then AREA_ARG=" --...
user avatar
  • 1,047
-2 votes
1 answer
28 views

Displaying users logged in today between two dates

I have two times, for example: 12:48 and 16:29. How can I list the users logged in from 12:48 to 16:29?
user avatar
1 vote
2 answers
26 views

Rename files with numbers already in file name

I have files with following names starting with water-frames0.gro upto water-frames201.gro water-frames0.gro water-frames119.gro water-frames138.gro water-frames157.gro water-frames116.gro water-...
user avatar
  • 113
0 votes
1 answer
39 views

Make script answer "Y" to prompts from apt-get

I use a bash script to initially set up and update virtual machines. Trying to make this bash script configure the VMs without having to do so manually. #! /bin/bash echo "Updating and ...
user avatar
  • 103
2 votes
2 answers
34 views

Remove files except latest one by numeric order

I am trying to remove files within a bash script. I can list the latest file with : ls | grep core | tail -n 1 and rename it like "keep-core-2994-xyz.bin", then remove the rest with: rm -f ...
user avatar
  • 119
-1 votes
0 answers
19 views

I am trying to unpack multiple tar folders in a directory and want to extract 'fastq' type files in the folder using a bash script. Below is my code; [closed]

Trying to unpack multiple folders to a directory, the folders name start with a common prefix, 'ABX-'followed by unique ids. I would like to unpack them with their names and copy them to a unique ...
user avatar
  • 1
0 votes
0 answers
18 views

How can I redirect functions from a sourced file to individual scripts?

First I tried grepping the file using the matching only option and adjust from there; # REGEX function () { # ((\w|ç|Ç|ñ|Ñ)+\s+\(\)\s+\{\n) blahblah # (.*\n)+ } ...
user avatar
  • 93
0 votes
2 answers
36 views

What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?

Say that https://example.nosuchtld https://example.net https://example.org https://example.willfail is the content of urls.txt. I want to run <command> <url> for every URL/line of urls....
user avatar
0 votes
1 answer
53 views

Trying to write a script to find ORF [closed]

I'm new to bash, and I found this script to identify ORF, the problem I have is that it gives me three results (ATGATGGATCCTTGCGTGCAGTAA, ATGGGATAA and ATGATGGATCCTTGCGTGCAGTAA) and not two as it ...
user avatar
0 votes
0 answers
20 views

shared library not found even if "export LD_LIBRARY_PATH" is set

Here comes a strange question. I have a QT App and it requires some libraries. Normally, the following bash script works: #!/bin/bash export LD_LIBRARY_PATH="./libs" export QT_DEBUG_PLUGINS=...
user avatar
0 votes
1 answer
38 views

extract tar then enter its directory (shell scripting)

How do I make script exctract tar then enter the extracted tar directory? I was trying xtract #!/bin/bash tar -xvf $1 && cd $1 Usage example suppose there's foo.tar.xz so how to use it: ./...
user avatar
1 vote
2 answers
46 views

How to pass a parameter in a command without run the parameter content?

Good days. I have a little problem. I have this function in bash script function denyCheck(){ file=$(readlink -f $(which $(printf "%s\n" "$1"))) if [[ -x $file ]];then ...
user avatar
  • 13
0 votes
3 answers
58 views

How to display a prompt and prevent execution against basic but dangerous commands like mv or rm

Objective Whenever I use mv (or commands of similar nature) I want my shell to prompt me something like "Hey, you used mv. Sorry but do it again using mv -i". I'd like to know the reasonable ...
user avatar
  • 357
0 votes
0 answers
29 views

Linux bash not working properlly [duplicate]

I am trying to run the following script on a OpenSuse machine: OUR_REPO=$(git branch | grep "*" | awk '{print $2}') THE_REPO_THAT_OURS_IS_BASED_ON="origin/$OUR_REPO" GIT_COMMIT=$(...
user avatar
  • 121
0 votes
0 answers
22 views

bash variable assignment difference between RedHat 8 and Ubuntu 20 [duplicate]

This works fine in a bash script on Ubuntu 20 INIT="${5:=false}" but on RedHat 8 I get an error $5: cannot assign in this way I'm a bit stumped on why, since I would expect they should ...
user avatar
0 votes
1 answer
31 views

Periodically transfer files from two remote servers to single host using shell script

I have two remote data acquisition machines that are continuously writing data to their own local data.txt files. The remote machines begin acquiring data and appending their data.txt with new data ...
user avatar
  • 103
0 votes
2 answers
33 views

looking to compare two different directories using the hash values of files within the directories

looking to compare two directories by checking the hashvalues between all the files in each directory and determine if the two directories are == to each other using the sha256 hashvalue
user avatar
0 votes
0 answers
44 views

SCP results look strange when using >> to append to file

I am trying to record a reoccurring test to a txt file using tail but there is an issue with the output. The commands I am running are: script -q /dev/stdout -c 'scp /home/user/test.img user@pc28:/tmp'...
user avatar
  • 1
0 votes
1 answer
31 views

looking to compare two directories using boolean statement

just looking to compare two directories and make sure that all files reside in both, I'm aware of the diff cmd but is there a way to use Boolean logic? if directory a contents == directory b contents ...
user avatar
0 votes
1 answer
41 views

How can I read each line of a text file (contains unique id) in bash using for loop, save it into a variable and use it subsequently for

Hi I am new to bash scripting, trying to read a text file that contains my ids and want to use it in a loop by saving it to a $variable and using that for fetching some data. #!/bin/bash file = "...
user avatar
  • 1
1 vote
1 answer
30 views

Extract field and number of occurrences per line

I have this file: John Green', 'Age: 32', 'State: New York', 'Total cars: 2', 'Manufacter: General Motor', 'Model: Pontiac', 'Year: 2000', 'Manufacter: Ford Motor', 'Model: Endeavour', 'Year: 2010 ...
user avatar
1 vote
1 answer
29 views

How to make libreoffice headless conversion act differently on file loading error

I use a script via my file manager context menu to convert various document formats (e.g. *.DOC) to ODT format like this: for filename in "${@}"; do if [[ -f "${filename%.*}.odt&...
user avatar
  • 399
-3 votes
0 answers
62 views

Create a user without using the "adduser" (or similar) command [closed]

How can I write a script to manually create a new user account with the name and password taken from the first and second command-line argument and a home directory under /home. The third and later ...
user avatar
0 votes
2 answers
33 views

How to execute the next command in pipe only if previous have at least one result?

So, I have the following command $(docker container ls -a -q) | docker container stop to stop all my docker containers, which works great! Except when I've just wiped clean all of them: "docker ...
user avatar
0 votes
6 answers
83 views

How to ignore all text containing special character more than once?

Sample Input: apple_ig rabbit_cat_ig dog_ig bird_duck_ig orange_ig goat_ig Expected output: apple_ig dog_ig orange_ig goat_ig I need to ignore all data that contains underscore _ more than once in ...
user avatar
  • 1,001
1 vote
1 answer
23 views

Confusing behavior of stdout/stderr and /dev/null

I am trying to understand a command like [command] > /dev/null 2>&1 If I understand this correctly, the output of the command is redirected to /dev/null and then the stderr (file descriptor ...
user avatar
  • 115
0 votes
1 answer
26 views

sscanf equivalent in shell script

I have a file which has some stats and counters stored for some ACL rules. I want to design a shell script to read that file and parse those counters. I have done the similar thing in c programming ...
user avatar
  • 131
2 votes
1 answer
254 views

Prevent shell script from hanging on a line

I have a written a shell script that helps me calculate the disk utilization in remote servers using df -h. I'm including the code snippet below s_arch_1_per=`sshpass -p 'password' ssh root@...
user avatar
1 vote
3 answers
45 views

diff: Find files that differ and are in the second directory

Say that I have these files for example: old/common-change/index.html new/common-change/index.html new/only-new/index.html old/only-old/index.html The output of diff -qr is close to what I want: $ ...
user avatar
0 votes
1 answer
39 views

how to bash script menu in one row only

I am creating a menu in a script (#!/bin/bash), and it works as I needed: PS3='[ menu ] choose partition tool:' options=("fdisk" "cfdisk" "continue") select opt in "$...
user avatar
  • 3
2 votes
0 answers
42 views

Posix shell/bash 3.2: Non-blocking read from file descriptor

Is it possible to do a non-blocking read in bash 3.2 that is also portable to POSIX environments? In modern versions of bash it's possible using read -r -d'' -t $TIMEOUT -N $NBYTES myvar but I need to ...
user avatar
  • 151
0 votes
0 answers
48 views

gnome-terminal in shell script [closed]

#!/bin/csh Command 1 gnome-terminal -- ./script1.sh gnome-terminal -- ./script2.sh Command 3 If I run the script it ignores all gnome-terminal and runs command 1 and command 3. Question : How can ...
user avatar
1 vote
3 answers
57 views

concatenate all the text files in all the sub folders into one giant text file

Ok so the situation is that I have an unknown number of sub-directories that all follow the same naming profile folder0, folder1, folder2, folder3 etc Now each folder will have 3 text files and these ...
user avatar
1 vote
0 answers
71 views

How can I execute a command in a shell script in a loop and in background mode?

In Restart mplayer stream process on loss of internet connection -> use while true an answer is given to restart an external command of a shell script - mplayer - after a connection loss. One ...
user avatar
1 vote
2 answers
39 views

find a string in every line of a file then replace another string on the same line using bash

here is my script : #! /bin/bash # C-band Edit dqt='"' str5="polarization=${dqt}2${dqt}" for x in {3600..4200} do; sed -i "/$str5.*$x/s/$x/$((x-600))/" satellites.xml ...
user avatar
0 votes
0 answers
28 views

Oneliner to archive, test the archive and remove source folder or stop if error

I've made my small shell function to un-compress the latest archive in a specific folder, then use it (code removed for sake of clarity), and then make an archive, test it and if everything is ok, ...
user avatar
0 votes
4 answers
72 views

Finding max row with highest value for a particular country in a csv file

I have a .csv file with entries like Location,Indicator,Period,First Tooltip Afghanistan,Malaria incidence (per 1 000 population at risk),2018,29 Afghanistan,Malaria incidence (per 1 000 population at ...
user avatar
-4 votes
1 answer
71 views

What do the "*" and "[[]]" symbols in the shell script mean?

‍‍This is my code: Number=12 ListOperation=('+' '/' '*' '-') if [[ " ${ListOperation[*]} " == *"/"* ]]; then let Result="$Number $operation $Number" echo $...
user avatar
0 votes
3 answers
68 views

awk based solution for summing the rows of multiple files

I have several files which look like file1.dat: 1 1 1 3 4 5 9 10 11 file2.dat: 3 0 8 9 0 3 9 2 4 typically with many more rows (with each row containing one less column than the previous row). I ...
user avatar
  • 107
0 votes
2 answers
32 views

Piping find to xargs works in terminal, but not in shell script [duplicate]

I'm trying to write a Bash shell script that copies all the files in the current directory, minus a few exceptions, into another directory. The script builds a command, stores it in a variable, and ...
user avatar
  • 101
1 vote
1 answer
22 views

What does Session ID mean within the pkill context?

About the pkill command, I know is possible kill processes - for specific scenarios - based through tty[1-6] and pts/[0-N]. I tested and works as expected. Until here all is ok. But now, according ...
user avatar
0 votes
1 answer
55 views

Instead of a single hostname specified on the command line, it reads in a list of multiple target IP addresses from a file

I want to make it so that instead of a single hostname specified on the command line, it reads in a list of multiple target IP addresses from a file. #!/bin/bash - # bannergrab.sh function isportopen (...
user avatar
0 votes
1 answer
36 views

Switch case with for loop for matching string

I am trying below thing but not able to succeed I have file with below content events_0-new events_1-new events_2-new events_3-new events_4-new events_5-new events_6-new system-events_0-new system-...
user avatar
  • 29

1
2 3 4 5
306