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
0answers
6 views

How to use bash script to get grep status?

I tried to write a bash script, purpose to control raspberry Pi GPIO when a kind of condition. the script will detect GPIO status and decide whether change it's status so it could change relay status,...
0
votes
1answer
17 views

Correct umask value to automate the creation of file with the SSH private key content

I'm trying to find a way to shorten these lines (CI_PRIVATE_SSH_KEY is already set): mkdir -p "${HOME}/.ssh/" chmod 700 "${HOME}/.ssh/" echo "${CI_PRIVATE_SSH_KEY}" > "${HOME}/.ssh/id_rsa" chmod ...
1
vote
1answer
29 views

awk not recognized in shell script

I'm trying to do floating point arithmetic in a shell script. I learned that awk can do it on the command line, but the way it works there does not seem to carry over to a shell script. When I type ...
0
votes
0answers
14 views

How to call bash script that may request user input from another script

I have two scripts one calls another and under some conditions that called script may request user input. At the moment I'm just executing this script but it is even doesn't wait for an input. How do ...
1
vote
0answers
20 views

Select only the header with it's pertaining list

i am working on creating a workflow for CICD using jenkins and I have a file that I am grep'ing that is formatted like this: api qa0= qa1= qa3= qa4=master qa5=master feasibility-service qa0= qa1=...
0
votes
1answer
23 views

How to write MySQL query in text file and run in linux

I would like to call a .sql file from a .sh file in linux. The .sql file will contain queries to MySQL database. I am able to call the .sql file by running .sh file in linux, but the sql query is not ...
-2
votes
2answers
48 views

Call an app from a bash script Ubuntu

I have an app in a specific installed on my Ubuntu machine which is installed in /usr/local/MYPROGRAM/bin/myapp and when I try using myfn in my bash script mybashscript.sh it gives an error saying ...
-1
votes
2answers
28 views

To get the value of specific attribute value as True or False, having uneven columns

I am having one file with the below two lines in the file. I need to check if the value of xpoweredBy is true or false. Many thanks in advance. <Connector clientAuth="false" sslProtocol="TLS"...
0
votes
1answer
14 views

Accessing openvpn from script without storing password on file

sudo openvpn --config ubuntu.ovpn --auth-user-pass file I know this command. Is there any other way to give password without using file. For suppose in wget I can use --http-user --http-password ...
0
votes
0answers
7 views

PHP Shell_exec and output result and alignment in php web page

I successfully managed to run my first php script in a web page!! I'm using a Raspberry Pi and with this script, a result is shown in a php page. It shows METAR data from the local airport. Basically ...
-1
votes
2answers
41 views

Shell script- To fetch the content from the specific tag at all occurrence using shell scripting

I have an XML file on my server. In that file, I have many tags in which there is a tag for example, "container" tag. I need to fetch the content of all the container tags content separately. Many ...
0
votes
1answer
31 views

rc.local - script message suppression

I am working on one project on Raspberry Pi, it include NUT server configuration and making the OS Image Read only. I have completed the required steps and configured the NUT server. I have ...
2
votes
3answers
61 views

Increment a variable timely in bash script

I want to increment a variable by one every 3 seconds. Is there any way to do that using bash? I had a program running in infinite loop in which I am doing some stuff with a variable; I want to ...
0
votes
1answer
21 views

Merge multiple csv files with different patterns

I have a directory where there are many csv files with the below 3 pattern: STRUCTURED_PROD, STRUCTURED_NON_PROD and UNSTRUCTURED. I want to merge all of these into 3 separate files, with just one ...
1
vote
0answers
14 views

Unknown keyword `smtp-auth' when using --set=smtp-auth=login

I use a bash script to make some process, then send me a mail report. This works fine when I use a local postfix configuration, but this not works with smtp auth and I got the error «smtp-auth unknown»...
1
vote
1answer
43 views

Remove top line from csv and then merge

I have multiple similar csv files at one location. I have to merge those files into one file. But the problem is my csv files have one additional line at the top of the headers. I want to remove that ...
-1
votes
1answer
35 views

Command ssh connection for 1000 linux servers

Please help me out from below situation. There are 1000 linux servers with me. i need to find out which all servers are accepting passwordless connection from my master server. Below is the command i ...
1
vote
1answer
26 views

Nested command substitution does not stop a script on a failure even if -e and shopt -s inherit_errexit are set

Suppose you have a following script sandbox.sh. (This looks similar to Command substitution inside a function does not stop the script on a failure even if -e is set, but I believe a bit different ...
1
vote
1answer
38 views

Zip and archive to other directory

I have some 250 CSV source files in the incoming directory. My task is to merge those CSV files and generate a file like Merge_. the Informatica Job will then pick the merge file as the source and ...
-7
votes
0answers
43 views

Explain briefly why the getops command is useful in a shell script [on hold]

Explain briefly why the getops command is useful in a shell script and the purpose of it.
1
vote
1answer
54 views

To delete a word in a line in file without deleting a whole line

I want to delete a string "www.yahoo.com" only if the line starts with assign where host.name in [ and ends with ] and also if the string is followed by comma(,)  I need to delete that comma as well ...
1
vote
1answer
20 views

How to procedurally generate command in bash script using string interpolation with spaces?

I'm trying to create a simple script that uses a list of months like this: (Jan Feb) To generate and execute this command: python ExpenseManager.py -p Inputs/Jan\ 2019\ Debit.CSV Inputs/Jan\ ...
2
votes
2answers
82 views

Removing trailing blanks from a file

I'm trying to remove trailing blanks at the end of every record in a text file using a shell script. Let's say I have the following columns in the file: 123 456 789' ' 234 567 890' ' Desired ...
0
votes
2answers
30 views

How to extract specific values after a specific string and store it to different variables?

I am very new to Linux. I need to parse one summary file which generates at the end of our automation. Below is that summary file: Total_Test_Cases_Count:25 Total_Pass:24 Total_Fail:1 ...
0
votes
1answer
32 views

What does this achieve?

What's the point of this: abort() { { if [ "$#" -eq 0 ]; then cat - else echo "rbenv: $*" fi } >&2 exit 1 } source
0
votes
2answers
30 views

Prevent bashscript argument being transferred to a child sourced script

I source a bashscript (Child) inside another bashscript (Parent), somewhere in the middle of Parent. The argument passed to Parent when executing it gets passed to the Child. How can I prevent this ...
0
votes
2answers
34 views

How to Move file using Script

I have been asked to design a script which when executed, moves the file types given in the arguments to the respective folder(creates the folder with file type if not there). Like suppose I give ...
0
votes
2answers
37 views

get pid of multiple instances of a process in a script and use them

Let's say I'm running multiple instances of process w1 (from source code while1.c) in the background (while1.c contains an infinite while loop): gcc while1.c -o w1 ./w1& ./w1& ./w1& ./w1&...
0
votes
1answer
47 views

how to combine 2 arrays into one associative array

i need to combine ARRAY1 and ARRAY2 into an associative array like ARRAY. i'm using this code: mapfile -t ARRAY1 < <(/bin/awk '{ print $ 1 }' /output/gen_branch) mapfile -t ARRAY2 < <(...
2
votes
1answer
43 views

Globbing with negation in ZSH

I’m trying to get something like ls **/*!(test).rb to expand to all ruby files which do not end with “test”. However, everything I tried so far didn’t help. I tried turning on ZSH’s expanded globbing ...
0
votes
0answers
37 views

Beautify the o/p of grep command

I am writing a bash script. It runs a couple of grep commands, and record the output of the grep command, in a text file. I am getting the output, but it is not formatted, so it is very difficult to ...
4
votes
1answer
66 views

Assign every word from a line to a variable

I am very new to shell programming. I have a file named quaternary_splitted.csv on macOS. Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest ...
1
vote
1answer
14 views

How to provide values to the read command in script when run in nohup mode. Ex. in body

If I have two read commands in the script and I have to run in nohup mode, then how can I give values using echo command. Eg. script: #!/bin/sh echo "/n read the value1" read info1 echo "/n read ...
1
vote
1answer
26 views

Cutting output of program running in loop

What I'd Like to do I'd like to cut the output of the program xkb-switch -W, which infinitely waits for layout group change, and prints group names to stdout. I'm only really interested in the first ...
0
votes
1answer
40 views

Copy files with bash script

I want to pass four parameters to bash script. script should copy files in user home directory. /opt/script.sh f1 f2 f3 f4 FYI: 1-each file might be exist or not, might be one of them exist or four ...
1
vote
0answers
66 views

Command substitution inside a function does not stop the script on a failure even if -e is set

I have a following script sandbox.sh, #!/bin/bash set -eu -o pipefail -E function func1() { echo "FUNC1" exit 1 } function func2() { local ret ret=$(func1) echo $ret echo "(func2)This ...
2
votes
4answers
45 views

How to dump all the URLs opened in firefox

Imagine a situation you are self-studying, and you suddenly remember that you need to submit an assignment tomorrow, so you need to do those stuff now. Now, you close your tabs and open new websites ...
3
votes
1answer
62 views

Run asynchronous tasks and retrieve their exit code and output in bash

I have to run a bunch of bash commands asynchronously and as soon as one finishes, I need to perform actions according to its exit code and output. Note that I can't predict how for long any of these ...
0
votes
1answer
31 views

Script bash, need to send mail if condition

I need to send an email only if a condition is reached, but I'm having error running this script: file='/somewhere/here/file.txt' value=$(cat "$file") if [$value < 99]; then echo "$value" | ...
-3
votes
1answer
38 views

11. Given a file, replace all occurrence of word “DEF” with “ABC” from 5th line till end in only those lines that contains word “MNO”

I was able to substitute all occurrences of "DEF" string with "ABC" string starting from line 5 in my file called "DEFABC.txt". However, when I try to add another condition with an if statement (only ...
-1
votes
1answer
15 views

Removal of tftp service

I have 2 extractions to interpret, the first one XINETD.CONF and second one /etc/xinetd.d. I am supposed to ensure that tftp is deactivated as it poses a security risk since it offers no ...
-4
votes
1answer
27 views

Seperating Parts of a file name in a Bash Script

If I have a file in the format of ./AAAA_AAAA_00_00_AAA-22222.txt, how would I be able to split it into AAAA_AAAA_00_00_AAA and 22222?
1
vote
0answers
38 views

Why would reading a passphrase from STDIN be disallowed but not from a PTY or argument?

I have a program that receives a secret passphrase. The options I have are to type it in manually on the terminal or to provide it as a command line argument. This makes it hard to automate in a ...
0
votes
1answer
44 views

Launch a script from GUI and see the commands

I'm trying to circumvent the absence of desktop shortcuts in Gnome by running the script from GUI through an explicitly launched instance of konsole: #!/usr/bin/sh set -x konsole --hold -e echo ...
1
vote
1answer
47 views

/bin/ksh: bad interpreter: No such file or directory [duplicate]

I have script with #!/bin/ksh in the first line. When I try to execute this script (run ./myscript.sh) the error occurred: -bash: ./myscript.sh: /bin/ksh: bad interpreter: No such file or directory ...
0
votes
2answers
74 views

How to create a empty string list and append it by using shell script?

A=Book,Pen,Pencil...n B=Cat,Rat,Bat.....m Code is:: Type=() TEST=`echo $path` echo $TEST Output :: n/m Excepted output :: Book/Cat/Book/Rat/Book/Bat/..../Book/m/Pen/Cat/Pen/Rat/Pen/Bat/...../...
1
vote
1answer
53 views

Edit sh script before a cron job starts running

I do not have much experience in Linux and would like some insight into whether there is a possibility to change a variable within a script before it is automatically started through a Cron Job. For ...
-4
votes
1answer
66 views

Shell terminates when running script. Why? [on hold]

I'm running the following script at home that I found online and every time I do, the shell terminates when I supply an answer to the read prompt. When I run the script in the bg, I get the following ...
0
votes
0answers
23 views

Interpreting file permission

I am doing an audit of the Linux system and it involves reviewing permits on sensitive configuration files. I am supposed to verify that no unauthorized users have write permission on them especially ...
2
votes
0answers
31 views

Python open screen and execute inside screen

I have a py script S1 that I would need to execute inside a screen. On an end-user point of view, I would like them to just execute another python script S2, which will open a screen and execute the ...