Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [shell-script]

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

0
votes
0answers
8 views

Dynamic Log Remove

I want to delete logs in Linux machines and the path example below. /test1/test2/test3/x/a/b /test1/test2/test3/y/a/b /test1/test2/test3/z/a/b Thing is directory changes after the "test3" folder I ...
-2
votes
1answer
26 views

Script program for checking IP connectivity [on hold]

I need a program to check the IP connectivity. Like I will be having more than 100 different IP addresses. For each IP address, I need to check whether it has connectivity or not. My challenge is I ...
1
vote
0answers
18 views

Starting wpa_supplicant via script in systemd not working properly

I've written a script to manually start the wpa_supplicant function on a Fedora/Centos7 machine with a wireless NIC. Due to static routing issues, I cannot use NetworkManager (nor do I want do with ...
0
votes
1answer
21 views

Bash String manipulation when string contains parentheses

I have a directory full of files with the name template xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are ...
0
votes
1answer
42 views

Understanding grep -oP … In a script

I'm writting a litlle bash script for debian. I want to find the 3th octet of my IPv4 and push it into "ip1" variable, and push the final octet in "ip2" variable. After some researches I found a ...
0
votes
1answer
37 views

bash: syntax error near unexpected token `;'

I got this error bash: syntax error near unexpected token; while running this line: while; do; clear; tree .git; sleep 1; done I got this line from this video
1
vote
2answers
47 views

fastest way to subsitute on 10GB file for multiple expressions

I have a file of 10GB data, I want to execute 2048 substitution expressions of sed -i 's/pattern/replace_pattern/g' on that file. Is there a way to do it faster and effectively. Currently, I am ...
1
vote
1answer
19 views

How to Merge Multiple Columns in to Two Columns based on Column 1 Value?

I have a text file in the below sample format File.txt Record1 20 23; Record2 256; Record3 45 679 98 1; The no of columns in each line can vary. I want to change the file with only two columns ...
0
votes
1answer
24 views

Use bash EXIT trap to confirm or cancel ctrl+d [duplicate]

Is there a simple way to require confirmation before logging out of a shell, and to prevent the shell from exiting if confirmation is denied? This would be useful to avoid accidentally terminating an ...
1
vote
1answer
37 views

Unable to find regular file with default shell as bash but works when it's ksh

We have script file FileChecker.sh where it checks whether file exists or not FileChecker.sh content: #!/bin/ksh FILE=$1 FILE2=$2 if [[ "$FILE" == "" || "$FILE2" == "" ]] ; then echo "[ERROR] ...
0
votes
2answers
23 views

How to delete columns with zero value in each line?

I have a file containing numeric data. Each line has a varying number of columns. In each line, I want to delete the columns containing 0. Below is a sample Input 25 60 0 29 0 10 23 0 26 43 49 1 56 ...
0
votes
3answers
41 views

how does this work ? for loop strips variable result

while learning bash/ksh from a book. i came across an exercise that had a result i would love to understand. When executing this script with bash -x to try to understand how it behaves (debugging) ...
4
votes
2answers
328 views

porting install scripts : can rpm replace apt?

I have the following install script for ubuntu : #!/bin/bash sudo apt update sudo apt full-upgrade -y sudo apt install jq sudo apt autoclean -y sudo apt autoremove will the following work under ...
0
votes
2answers
48 views

Command in Linux to perform opposite of egrep?

I want to find which of the patterns or words are not present in file. Example : test.txt marco polo charlie anthony john egrep 'marco|polo' test.txt will output marco and polo But I want a ...
0
votes
1answer
27 views

Distinguishing files on the basis of first column's content

I have multiple tab-separated files with .cluster extension. I want to classify these files on the basis of their first column content using the following criteria: (2 and 3 are actual digits/content ...
0
votes
0answers
26 views

appending a text to file using cat >> is not working but echo with tee --append is working [duplicate]

I want to append the line "include /etc/nginx/tcpconf.d/*;" to the file /etc/nginx/nginx.conf. When I did run the below command, it failed - $ sudo cat "include /etc/nginx/tcpconf.d/*;" >> /...
1
vote
2answers
35 views

How can I read a txt file line by line and sort them by the correct variables and write them to another file?

Here is an example of my txt file John NY 2019 APR Mark SC 2019 JAN Ava CA 2018 AUG Here is the example of the target txt file Name,Location,Year,Month John, NY,2019,APR Mark, SC,2019,JAN Ava, CA,...
-1
votes
0answers
28 views

add prefix to the recursively expanded variable in shell

I have : COMP_FILE+=docker-compose.con-etl.yml COMP_FILE+=${USE_DIRECTORY}/docker-compose.abc.yml COMP_FILE+=${USE_DIRECTORY}/docker-compose.cde.yml COMP_FILE+=${USE_DIRECTORY}/docker-compose.efg.yml ...
0
votes
0answers
22 views

How to extract only XML message from log file having text and XML message both

Below are the sample output: er : [com.rbsg.digital.platform.model.persistence.entity.EntityAddressDTO.individuals#263660] 2019-04-13 05:00:19.924 DEBUG LENDING_DIGITAL_CERT_STAFF_LBZ5_PROD_MM [http-...
0
votes
1answer
42 views

Notify when file read [duplicate]

How can I register to event that let me know when specific file is read in linux? Can implement in c or in bash /shell script
0
votes
0answers
8 views

How to mention the staring size in sfdisk when using extended partition?

I'm using the below sfdisk script for eMMC partition on the target Linux platform and is working fine. #!/bin/sh # wait for the SD/MMC device node ready while [ ! -e $1 ] do sleep 1 echo “wait for $...
0
votes
0answers
30 views

Wait command in Bash script not acting as expected [on hold]

I am making a script to play 4 different video feeds from 4 different camera DVRs via RTSP, and need them to be pretty much hands-free i.e. a dedicated mini pc running Debian that will, network ...
0
votes
0answers
67 views

How can I sort files without ls or find

I need sorted list of files and directories in for-loop, must be files sorted before directories.I need this because i'm trying to copy and sequentially renaming files recursively and i tried with ls ...
1
vote
0answers
26 views

how to remove leading space in command line argument [duplicate]

I am losing my mind here.. have tried every combination of functions that strip whitespace but I can't get rid of this particular whitespace I want to write a convenience alias so that typing runit ...
0
votes
1answer
20 views

Copy and rename files to a sequential numbering with subdirectories

I want to copy files of the given type with inside subdirectories. I think copy of the zzz.txt file works after copying the files in the abc_folder. How can i resolve this problem. AAA ---aaa.txt ...
1
vote
0answers
13 views

Replace part of a vdf file

Again I am attempting to alter configuration file via script. I looked into jq but jq seems to support the .json format alone. .vdf is almost exactly like .json except that there are no commas. ...
2
votes
2answers
49 views

Script a Github file download using curl where filename AND path are variable

I needed to script the install of the Digital Ocean CLI " doctl " tool from Github using curl, but there was a problem: The filename varied as it incorporated the version number- so hard-coding it ...
0
votes
0answers
17 views

As part of a script read directory but as a GUI

I'd like to enhance my script : #!bin/bash echo "where would you like to install? (type directory)" read directory this is nice but not really robust, it doesn't really account for human error the ...
1
vote
1answer
62 views

Creating directory tree based on file name

I have a large number of files with the following structure: [Lion] 2015 Africa Book.pdf [Lion] 2015 Africa Magazine.pdf [Lion] 2016 Africa Book.pdf [Lion] 2016 Africa Magazine.pdf [Lion] 2015 Asia ...
4
votes
1answer
85 views

How to make `trap` know if the EXIT is after successful program finish or because of premature as an error or something

PROBLEM: I have a shell program that I have been writing but I can't find out how to make sure that trap is trapping for cleanup at the end or because of a error in some command, it cleans up either ...
0
votes
1answer
28 views

Renaming multiple paired files, deleting varying barcode character string in middle?

I have a bunch of paired files with unneeded barcode tags within the middle of the file, for example: LIB008983_TRA00020080_TAAGGCGA-TATCCTCT_L001_R1.fastq.gz LIB008983_TRA00020080_TAAGGCGA-...
0
votes
1answer
21 views

Shell Script - Ping and create folder from list of servers

I'm trying to create a script to ping a list of servers, and it will write the result to a text file, then it will create a folder to the list of servers. FILENAME="hosts" while IFS='' read -r LINE |...
0
votes
0answers
32 views

Bash - Remove line from /etc/fstab - advice [duplicate]

First post - go easy on me:) Was rewriting bash script to delete lines in /etc/fstab. I can get it to work with the "echo". Question: Why cant it do with with awk? echo "Code:" if [ "$quit" ==...
-1
votes
3answers
79 views

Extract files which have more than 5 lines, and keep same filename [on hold]

I have multipe files containing errors in annual reports. Each file name have .mvt extension. It is not necessary that every file has error. I have found that when errors appear OR not there is always ...
-1
votes
2answers
44 views

How to prevent a bash script to close [on hold]

How can I prevent a bash script from closing, so block itself from closing. Is there a command that executes a command if there is no action?
-1
votes
0answers
27 views

replace xml attribute value using shell script

I want to replace the value "04/14/2017 20:04:44" to this "04/14/2017 19:59:44" if the value is in the range of "04/14/2017 20:00:00 to 04/14/2017 21:00:00" My xml file sample below: <...
1
vote
2answers
48 views

Bash array with folder paths and wildcards

Given the above folder paths, I am trying to write a script that will delete files older than a certain amount of days. I am trying to use some more advanced techniques than just hard coding the ...
0
votes
0answers
32 views

Why does 'rsync' overwrite files in my destination with the same contents?

I'm using rsync in a shell script to perform deployments of Bitbucket (Git) managed repositories. Part of the requirements for deployment is that files from several designated directories in source ...
-8
votes
0answers
32 views

About shell scripting [closed]

Write a Linux Bash shell script to compute the bonus for a salesperson as per the given pseudocode. Convert the following pseudocode into a Bash script: Read SalesPerson and QuarterlySales from the ...
0
votes
1answer
43 views

How do I pass long-style command line options to a bash script using getopt?

I have this script that I have cobbled together from bits of lore I've gleaned from googling: #!/usr/bin/env bash usage() { declare -r script_name=$(basename "$0") echo """ Usage: "${...
0
votes
1answer
20 views

How to resolve SAS macro variable in shell script

I am running a shell script via X command within a SAS macro. I want to use a macro variable defined in SAS macro, in my shell script. I know if I pass that macro variable as parameter to shell script,...
0
votes
0answers
35 views

How to enter and leave a man page in a script

I want to run a script that enters a man page and leaves it. Something like (in pseudo-code) $ man man q How can I do such a thing? Preferably the exit code will be 0. More generally how do I do ...
-1
votes
1answer
63 views

bash in Windows behaves differently than bash in Linux [closed]

I am using the following version of bash on Windows 10: GNU bash, version 4.4.23(1)-release (x86_64-pc-msys) I received a script from somebody who is running it on Linux. When running on Windows, ...
0
votes
0answers
38 views

Script for server if directory sizes reaches to 20 GB [on hold]

I have written script to check the directory size and send mail to user if it crosses limit.. #!/bin/bash set -e LIMIT='8' DIR='/stage_jenkins_data/instances' MAILTO='k_vinod@idle.com' SUBJECT="$...
0
votes
0answers
24 views

Any way to interpret string representing an integer or operation?

Lets say I have this string one plus two Is there any way we can interpret this as 1 + 2 faster than going into some conditions checking word per word and testing it if it equal something in a given ...
1
vote
2answers
37 views

How to redirect program error to a file while using pipes

I'm running a command on a Linux machine to backup my DB: (echo "`date`: START DUMPING"; db_dump.sh; echo "`date`: DONE DUMPING") >>db_dump.log And in the db_dump.sh: pg_dump -v --dbname=mydb ...
0
votes
1answer
68 views

When can a “cd” command fail in a shell script and what can I do to remedy it?

I have a shell script that failed to finish last week; it was a failed "cd" command and it exits if it fails. The script is a bash shell script for configuring new Debian installs. Here is the full ...
0
votes
2answers
42 views

Looping through contents of a file and finding it in different directory

I need to compare the contents of a file located in dir A with actual files in different directory. ex- directory A has a file test.txt , Item mentioned in test.txt and not present in directory B ...
27
votes
11answers
6k views

Why doesn't shell automatically fix “useless use of cat”? [closed]

Many people use oneliners and scripts containing code along the lines cat "$MYFILE" | command1 | command2 > "$OUTPUT" The first cat is often called "useless use of cat" because technically it ...
-2
votes
1answer
48 views

Can I combine the tail and gzip commands inside a function? [closed]

I'm currently learning UNIX commands as part of my internship. Is there a way to combine these two commands-> (tailing log files then zips it using gzip)? My script is posted below: #!/bin/sh # ...