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
0
votes
2answers
42 views

Rename files by reversing number order

I have a lot of files that are named like: data1_1.txt data1_2.txt data1_3.txt data2_1.txt data2_2.txt ... However these were downloaded and named in the reverse ordering. How could I rename all of ...
0
votes
2answers
15 views

How can I use sed to replace multiple characters?

I have this script: replace 3 echo 12345 | sed "s/^\(.\){"$1"}/\1hi/" I also tried this: echo 12345 | sed "s/^\(.{"$1"}\)/\1hi/" In this situation I want the script to add 'hi' after the first 3 ...
3
votes
2answers
4k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
0
votes
1answer
43 views

Notification 'Message Sent' for write command

I need to use the write command to send someone a message. Using a shell script if the message is sent successfully I want to have a 'Message sent!' notification pop up and if possible, end the shell ...
0
votes
2answers
27 views

How can I 1) find a matrix according to its title in a file and 2) sort each line into a distinct file by the first two numbers?

I have tens of thousands of directories. Each directory is named by number, like 1, 2, 3,... Each directory contains a large .dat file called data.dat and each file has a section that looks like ...
0
votes
0answers
21 views

sh -c and exec works in prompt but not in Shebang script

I try to execute Xsession logout via shell script: xfce4-session-logout --logout The above option (or -l) allows logout without confirmation. It works fine in bash prompt, but instead of sh, I have ...
16
votes
3answers
16k views

awk: forcing a return status?

This is a followup to my earlier question. I am validating the number of fields in /etc/passwd using this handy snippit. In the following example, the users 'fieldcount1' and 'fieldcount2' have the ...
50
votes
8answers
85k views

Bash script to get ASCII values for alphabet

How do I get the ASCII value of the alphabet? For example, 97 for a?
1
vote
1answer
24 views

pass multiple search terms to text browser via bash_aliases in prompt

I want to achieve a bash alias so that I can type just: $> lynxsearch most popular unix text browsers $> w3msearch most popular unix text browsers (or the search terms within quotes or ...
2
votes
1answer
2k views

Kill a running shell script, and kill all process running within it

I have a shell script running in the background, which runs 5 different jobs. When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will ...
0
votes
1answer
2k views

When root, source another user's ~/.bashrc and get all environment variables

I'm trying to develop a small system app that is run as root. In this app, I would like to list all environment variables of the default user (not the $USER, but the user who calls runs the app as ...
22
votes
2answers
5k views

How do I compile something for Linux if I don't have enough space for installing GCC?

I purchased a Human Machine Interface (Exor Esmart04). Running on Linux 3.10.12, however this Linux is stripped down and does not have a C compiler. Another problem is the disk space: I've tried to ...
1
vote
1answer
58 views

How to determine if an EXIT trap is defined for a BASH subshell?

Below is a example BASH script. #!/bin/bash exithdl() { echo "in exithdl subshell=$BASH_SUBSHELL" >&2 } trap exithdl EXIT fun() { echo "in fun subshell=$BASH_SUBSHELL" >&2 ...
12
votes
6answers
19k views

how to check directory is empty

I have a requirement, if I execute a script ./123 with an arguments of empty path, say /usr/share/linux-headers-3.16.0-34-generic/.tmp_versions(this directory is empty). It should display "directory ...
-4
votes
2answers
59 views

Shell Script - Alphabet in code

I want to create an alphabet where each letter and character has a specific value. Example: A="99_banana" a="@_melon" B="22_GRAPE" b="orange" C="Strawberry" c="life" @="12399" !="tv_12" and so on ...
0
votes
2answers
59 views

getopts for parsing both long and short options

I already have a script that accepts only SHORT OPTIONS, and I want to extend the same script so as to pass the respective LONG OPTIONS. The existing code is given below. while getopts :t:c: name; do ...
0
votes
0answers
17 views

Checking and programming crontab in the same script [duplicate]

I have to deploy a script on different machines in a large network that will be checked every 5 minutes. The script is very simple: #!/bin/bash if [[ ($(command)) ]]; then output fi asd ...
0
votes
1answer
15 views

How to run lxc exec for commands with pipe?

for example, I have this command: lxc launch ubuntu:18.04 memsql1 lxc exec memsql1 -- wget -O - 'https://release.memsql.com/release-aug2018.gpg' 2>/dev/null | sudo apt-key add - && apt-...
0
votes
0answers
29 views

Run script in “run dialog” instead of gnome-terminal

To run a script in terminal emulator we use gnome-terminal -e "/home/blueray/Documents/Translate/screen_ts.sh" Or, x-terminal-emulator -e "/home/blueray/Documents/Translate/screen_ts.sh" How to ...
0
votes
1answer
21 views

Open chromium from bash script using crontab

I'm trying to open Chromium from a bash script. This script can be executed in any moment / at the moment scheduled in crontab. I'm using Debian 9. This script kills Chromium if the script is ...
0
votes
2answers
34 views

Directory stack (pushd and popd) behaviour in bash scripts

If I poorly write a script that uses pushd /etc but I don't finish it with popd: Will /etc still be in the pushd+popd directory stack/in RAM after the bash script has finished executing and Bash has ...
-3
votes
0answers
40 views

Bash Shell script to check mount points on server is only displaying name and not all arguments [closed]

I am using a script to Check mount points on the server : https://github.com/echocat/nagios-plugin-check_mountpoints/blob/master/check_mountpoints.sh But the output is only displaying Filesystem ...
2
votes
1answer
62 views

How do I find what process is running in a particular GNU screen window?

Problem I need to find what process is running on a particular window in screen (in a reasonable amount of time). Scenario I need to use the Session Name and Window Title to find the process ...
-1
votes
2answers
40 views

copy multiple lines and past in the end of another text file

I have a bash script, which shows some flag (some text) on terminal at the end of the execution. I want to copy these flags (text) in the end of another file. I want to copy these flag (after the ...
0
votes
0answers
31 views

How to use sed to replace variable value with a variable of the same name?

I'm trying to write a script that updates a server config file to the latest format. The purpose of the script is to copy over existing (defined) variables to the latest config (in a temp file), then ...
2
votes
2answers
76 views

How to merge text files - Bash script

I want to write a script that takes text files as arguments and merge them. All the files consist of grouped lines divided by empty lines. The script can take more than 2 arguments The files can ...
7
votes
4answers
9k views

read first line from .gz compressed file without decompressing entire file

I have a huge log file compressed in .gz format and I want to just read the first line of it without uncompressing it to just check the date of the oldest log in the file. The logs are of the form: ...
0
votes
0answers
24 views

I want to automate the process of updating the exported variables [duplicate]

I have multiple variables defined in a Makefile with some values/strings initialized. I want to have a target with which, I can update any of the variable in run time. For that I wrote a script ...
0
votes
0answers
23 views

Add new server mx records file zone use awk

I need to add additional records to the MX records from the server. I use script but it only adds the server to the last MX record. Please help me. for i in `cat file.zone | grep MX | cut -f1| sed '/;...
6
votes
4answers
10k views

Check IP is in Range of Whitelist Array

#!/bin/bash MAXCDN_ARRAY="108.161.176.0/20 94.46.144.0/20 146.88.128.0/20 198.232.124.0/22 23.111.8.0/22 217.22.28.0/22 64.125.76.64/27 64.125.76.96/27 64.125.78.96/27 64.125.78.192/27 64.125.78.224/...
41
votes
7answers
15k views

Conditional pipeline

Say I've got the following pipeline: cmd1 < input.txt |\ cmd2 |\ cmd4 |\ cmd5 |\ cmd6 |\ (...) |\ cmdN > result.txt Under certain conditions I would like to add a cmd3 between cmd2 and cmd4. ...
-22
votes
3answers
810 views

Search in the PATH for commands starting with a particular letter

Which command could I use list all commands that start with the letter g? Let's assume I can't use bash completion, and that a script must be written.
1
vote
5answers
259 views

Sum of even and odd numbers of odd and even lines

I would like to write a shell script program that gives the sum of even and odd numbers in a given file's odd and even lines. I would like to use: sed -n 2~2p and sed -n 1~2p but I am not even ...
0
votes
0answers
17 views

Need to get hung state when the command or script executes [closed]

I don't know how much time it should take to complete the execution of a command or script. I would like to show a hung up state when I don't get the proper output. The below script is held up for ...
4
votes
1answer
631 views

Cleanup Script for macOS

I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to ...
1
vote
1answer
55 views

How can a command within a pipeline abort the pipeline?

Given the pipeline a | b | c how might I alter b so that it aborts the pipeline if b generates an error or matches a particular pattern in the input stream?
22
votes
3answers
47k views

Case-insensitive substring search in a shell script [closed]

How can I write a shell script that will do a case-insensitive substring match of command output?
0
votes
1answer
30 views

problem finding variable values starting with tab

I'm trying to write a simple Linux make command with bash scripting. here is what I have written so far: #!/usr/bin/env bash function make_cmd() { read target colon sources for src in $sources; ...
1
vote
1answer
930 views

Fastest way to find and replace in large file while replacing field present in another file

I have two files. File1 is a csv with 60 fields: 111,Check1|^/h1/h2/h3,22062014184500,20,0..... 111,Check2|^/h43/h40/h9,22062014184500,4,..... 111,Check3|^/h1/h3/h4,22062014184500,0,0,..... File2 is ...
-2
votes
0answers
18 views

Take a backup in zip file and delete original [Linux] [Cygwin]

I have a directory named as "Vikram" There are some files and directories in "Vikram". Directories under Vikram has some subdirs and files. I need to take backup of 30 days old dirs in one zip file ...
7
votes
6answers
53k views

how can we use multiple variables in single for loop in shell script?

I am implementing as below code using for loop but wrong output coming after running the script. for i in `awk -F"|" '{print $1}' $INPUTFILE`, j in `awk -F"|" '{print $2}' $INPUTFILE` do echo $i:$j ...
0
votes
0answers
36 views

why /var/spool/abrt/ folders not deleted

we try to delete all abrt folders as the following ( on redhat Linux machines ) find /var/spool/abrt/* -type d -exec abrt-cli rm '{}' \; rm '/var/spool/abrt/ccpp-2018-09-03-14:52:11-5653' rm '/...
0
votes
1answer
31 views

what are the risks for disable the abrtd service?

we have 672 linux redhat machines since we have small /var size and sometimes /var/spool take space , then we want to disable the abrtd service what are the risks for disable the abrtd service ? as ...
6
votes
2answers
22k views

Is shell script a programming language? [closed]

This is my first question in UNIX: I started with shell scripts 2 days ago. But I have a question: is a shell script a special programming language for a specific shell?
0
votes
1answer
15 views

headless chromium-browser command syntax issue

I'm having some issue with the headless chromium-browser not creating the html files correctly. The only thing / file that gets created is a single {}.html file My domains.txt contains: https://ibm....
-1
votes
1answer
35 views

IF loop with multiple OR condition throwing syntax error

I want to add multiple or condition where I am comparing string values, with single string value my following code is working prname ="$projname" if prname == 'CheckForUpdate': ...
8
votes
2answers
642 views

How do I use GNU parallel to calculate sha256 hash?

Based on this: Simultaneously calculate multiple digests (md5, sha256)? I have a folder that has a large number of files that I want to compute the SHA256 hash for. I used to code segment: #!/bin/...
0
votes
0answers
21 views

How to set DTR of COM high using Bash script without using C code?

I've purchased a HMI running on Linux. This HMI has a serial port and I'm trying to set the DTR signal of this port. However this Linux is stripped down and I cant install a C compiler etc. I'm trying ...
1
vote
2answers
65 views

How to update values in a csv file with values from another csv file, using bash

I have two files, each with data arranged in two columns. Columns are separated by a semicolon. The first file (11_19.txt) includes more lines and the second file(12_19.txt) is to update the first ...
0
votes
1answer
26 views

How to change value of a key from terminal among non-unique keys in a .conf file?

I have a .conf file in key/value format. But there may be some non-unique keys. Distinction between them is like below: ### ### [meta] ### ### Controls the parameters for the Raft consensus group ...