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
14 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 ...
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 ...
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
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
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 ...
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 ...
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
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 ...
-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 ...
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 ...
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 '/;...
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 ...
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 ...
-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 ...
-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 ...
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 ...
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 ...
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 ...
-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 ...
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': ...
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 ...
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 ...
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/...
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?
1
vote
0answers
34 views

How to make a simple menu in bash from an associative array

I am refactoring a script that displays a text menu similar to this: Select a mounted BTRFS device on your local machine to backup to. 1) 123456789abc-def012345-6789abcdef012 (/) 2) 123456789abc-...
0
votes
0answers
41 views

WC command is broken within script? Works as expected in terminal [closed]

I've been trying to get this script to run but I am having no luck with the wc command. It works as expected from the terminal but breaks when using a script as it can't seem to find the file. Any ...
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 ...
1
vote
0answers
21 views

Adding Text to A Shell Script for Simple Program [closed]

I'm trying to create a really simple shell program, and I am having some difficulty trying to get it to work. I feel like my program matches the syntax that I see out on the internet, but my program ...
-4
votes
3answers
41 views

Shell: How to get number from file?

1 2 5 7 I have numbers like this in a text file. How can I print the third number using a shell script?
-4
votes
0answers
24 views

Print a number pattern [closed]

Want to print this pattern in Linux 1 1 2 1 2 3
1
vote
2answers
28 views

Display only IP addresses from nslookup without writing output to file

i am a student newly studying cybersecurity. We are using kali linux for the phases of pen-testing. I'm new to bash script too. Command: nslookup -type=mx cathay.com.sg EXAMPLE OUTPUT Server: ...
0
votes
1answer
51 views

I need to ssh into another machine using expect and a password and start a program there, then start a program on my local machine. How can I do this?

As said in the title, I am writing a script that should run on Computer A. Computer A should ssh on Computer B, run Program B, then exit the ssh session (Program B still running on Computer B) and ...
0
votes
1answer
18 views

How to create a bashrc/zshrc symlink?

I reinstall my OS a lot, and I've learned to start backing up configs in iCloud Drive folder The command I generally run (after searching google for the nth time): ln -s "/Users/myName/Library/...
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 ...
-1
votes
0answers
46 views

What could be the reason for “Argument list too long: /bin/bash” error, while executing encrypted bash file?

I have written a bash script which is of size around 500 kB and encrypted it following this guide https://www.thegeekstuff.com/2012/05/encrypt-bash-shell-script/ The problem is when, I execute ...
0
votes
1answer
18 views

Are subshells run in parallel by default?

This question follows from this one and one of its answers' recommendation to read Linuxtopia - Chapter 20. Subshells. I'm a bit confused by this statement at the Linuxtopia site: subshells let ...
1
vote
1answer
82 views

how do I fix invalid arithmetic operator using bash?

I am parsing a log file. My goal is gather avg, min, max of time from it. I am able to parse the milliseconds from each line. When I try to do math on it, I get the error: 17607 + 0 : syntax error: ...
0
votes
0answers
15 views

What option affects variable assignments on the same line as a command? [duplicate]

Yesterday, the following command worked as expected in my bash shell. $ foo=x echo $foo x Today, it prints a blank line instead. $ foo=x echo $foo I am very confused about what changed. What shell ...
1
vote
1answer
15 views

how to replace a string in files only under some folders whose name contains certain string

I have such directory structure: resources/config/config_12_33/en/config1.txt resources/config/config_12_33/fr/config1.txt resources/config/config_12_34/en/config1.txt resources/config/...
0
votes
0answers
7 views

Using PulseAudio to pipe audio from multiple applications into separate files in parallel

I would like to redirect the audio output of multiple applications to multiple files in parallel on Ubuntu. For example, if I have two instances of Chrome running in the background at the same time, I ...
0
votes
0answers
29 views

Run a script in a new terminal window, but the same terminal emulator as the current window

I want to run a script in a new terminal window. I found several solutions such as this. However, they all provide terminal specific solutions. So konsole ./myscript.sh works if I'm using konsole, but ...
0
votes
1answer
37 views

how to grep from multiple file and out to a file

I have 3 files in the same location with below information: File1: msisdn, channel, transid, time1 File2: transid, time2, messageid File3: messageid, status, time3, time4 How can I grep from 3 ...
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; ...
15
votes
5answers
1k views

Between while and do in shell script

I have the following script that works fine: !/bin/bash a=12 while [ $a -gt 10 ] do echo "$a" a=$(($a-1)) done echo "done" If I add line "echo something" above "do", I expect to see a ...